Renewed get_current_md() based on OL method

This commit is contained in:
2016-06-11 17:09:13 +02:00
parent c02f137c0b
commit 911b19068c
4 changed files with 40 additions and 44 deletions

View File

@@ -40,32 +40,7 @@
<nav> <nav>
<ul class="pager"> <ul class="pager">
<li data-toggle="tooltip" title="{% trans 'previous' %}" class="previous"><a href="/matchday/{{ ls }}/{{ season }}/{{ cur_md|add:"-1"|stringformat:"02i" }}"><span aria-hidden="true">&larr;</span></a></li> <li data-toggle="tooltip" title="{% trans 'previous' %}" class="previous"><a href="/matchday/{{ ls }}/{{ season }}/{{ cur_md|add:"-1"|stringformat:"02i" }}"><span aria-hidden="true">&larr;</span></a></li>
{% if ls == "em2016" %} {{ md_name }}
{% if cur_md == "01" %}
Gruppe A
{% elif cur_md == "02" %}
Gruppe B
{% elif cur_md == "03" %}
Gruppe C
{% elif cur_md == "04" %}
Gruppe D
{% elif cur_md == "05" %}
Gruppe E
{% elif cur_md == "06" %}
Gruppe F
{% elif cur_md == "07" %}
Achtelfinale
{% elif cur_md == "08" %}
Viertelfinale
{% elif cur_md == "09" %}
Halbfinale
{% elif cur_md == "10" %}
Finale
{% endif %}
{% else %}
{{ cur_md }}. Spieltag
{% endif %}
<li data-toggle="tooltip" title="{% trans 'next' %}" class="next"><a href="/matchday/{{ ls }}/{{ season }}/{{ cur_md|add:"1"|stringformat:"02i" }}"><span aria-hidden="true">&rarr;</span></a></li> <li data-toggle="tooltip" title="{% trans 'next' %}" class="next"><a href="/matchday/{{ ls }}/{{ season }}/{{ cur_md|add:"1"|stringformat:"02i" }}"><span aria-hidden="true">&rarr;</span></a></li>
</ul> </ul>
</nav> </nav>

View File

@@ -57,6 +57,7 @@ class Match(models.Model):
matchDateTime = models.DateTimeField() matchDateTime = models.DateTimeField()
group = models.IntegerField() group = models.IntegerField()
matchday = models.IntegerField() matchday = models.IntegerField()
matchday_name = models.CharField(max_length=128)
idTeam1 = models.ForeignKey(Team, related_name='+') idTeam1 = models.ForeignKey(Team, related_name='+')
idTeam2 = models.ForeignKey(Team, related_name='+') idTeam2 = models.ForeignKey(Team, related_name='+')
pointsTeam1 = models.SmallIntegerField() pointsTeam1 = models.SmallIntegerField()
@@ -122,6 +123,7 @@ class Post(models.Model):
published = models.BooleanField(default=True) published = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
author = models.ForeignKey(User) author = models.ForeignKey(User)
mandant = models.ForeignKey(Mandant)
class Meta: class Meta:
ordering = ['-created'] ordering = ['-created']

View File

@@ -67,4 +67,8 @@ class OpenLiga(object):
def getTeams(self, season, league='bl1'): def getTeams(self, season, league='bl1'):
return(self.client.service.GetTeamsByLeagueSaison(leagueShortcut=league,leagueSaison=season)) return(self.client.service.GetTeamsByLeagueSaison(leagueShortcut=league,leagueSaison=season))
def getCurrentGroup(self, league):
return(self.client.service.GetCurrentGroup(leagueShortcut=league))

View File

@@ -51,11 +51,12 @@ timezoneLocal = pytz.timezone('Europe/Berlin')
def home(request): def home(request):
ls = get_current_ls() ls = get_current_ls()
season = get_current_season() season = get_current_season()
md = get_current_md(ls)
return redirect("matchday", return redirect("matchday",
ls = ls, ls = ls,
season = season, season = season,
matchday=str(get_current_md(ls, season)).zfill(2) matchday=str(md['groupOrderID']).zfill(2)
) )
@login_required @login_required
@@ -137,6 +138,7 @@ def getSeason(request, ls, season):
ol = OpenLiga() ol = OpenLiga()
teams = ol.getTeams(str(season), ls) teams = ol.getTeams(str(season), ls)
season = ol.getSeason(str(season), ls) season = ol.getSeason(str(season), ls)
md = get_current_md(ls)
for team in teams[0]: for team in teams[0]:
t = Team( t = Team(
@@ -152,6 +154,7 @@ def getSeason(request, ls, season):
matchDateTime=datetime.strptime(unicode(match['matchDateTime']), '%Y-%m-%d %H:%M:%S'), matchDateTime=datetime.strptime(unicode(match['matchDateTime']), '%Y-%m-%d %H:%M:%S'),
group=int(match['groupID']), group=int(match['groupID']),
matchday=int(match['groupOrderID']), matchday=int(match['groupOrderID']),
matchday_name=unicode(match['groupName']),
idTeam1=Team.objects.get(teamID=int(match['idTeam1'])), idTeam1=Team.objects.get(teamID=int(match['idTeam1'])),
idTeam2=Team.objects.get(teamID=int(match['idTeam2'])), idTeam2=Team.objects.get(teamID=int(match['idTeam2'])),
pointsTeam1=match['pointsTeam1'], pointsTeam1=match['pointsTeam1'],
@@ -162,7 +165,7 @@ def getSeason(request, ls, season):
) )
m.save() m.save()
return redirect("matchday", ls=ls, season=season, matchday=get_current_md(ls, season)) return redirect("matchday", ls=ls, season=season, matchday=md['groupOrderID'])
@login_required @login_required
@@ -184,17 +187,22 @@ def update(request, ls, season, cur_md):
if result['resultName'] == "Endergebnis": if result['resultName'] == "Endergebnis":
pointsTeam1=int(result['pointsTeam1']) pointsTeam1=int(result['pointsTeam1'])
pointsTeam2=int(result['pointsTeam2']) pointsTeam2=int(result['pointsTeam2'])
elif result['resultName'] == "Halbzeitergebnis": elif result['resultName'] == "Halbzeit":
pointsTeam1=int(result['pointsTeam1']) pointsTeam1=int(result['pointsTeam1'])
pointsTeam2=int(result['pointsTeam2']) pointsTeam2=int(result['pointsTeam2'])
else:
pointsTeam1=-1
pointsTeam2=-1
except: except:
pointsTeam1=-1 pointsTeam1=-1
pointsTeam2=-1 pointsTeam2=-1
m = Match(matchID=unicode(match['matchID']), m = Match(matchID=unicode(match['matchID']),
matchDateTime=datetime.strptime(unicode(match['matchDateTime']), '%Y-%m-%d %H:%M:%S'), matchDateTime=datetime.strptime(unicode(match['matchDateTime']), '%Y-%m-%d %H:%M:%S'),
group=int(match['groupID']), group=int(match['groupID']),
matchday=int(match['groupOrderID']), matchday=int(match['groupOrderID']),
matchday_name = match['groupName'],
idTeam1=Team.objects.get(teamID=int(match['idTeam1'])), idTeam1=Team.objects.get(teamID=int(match['idTeam1'])),
idTeam2=Team.objects.get(teamID=int(match['idTeam2'])), idTeam2=Team.objects.get(teamID=int(match['idTeam2'])),
pointsTeam1=pointsTeam1, pointsTeam1=pointsTeam1,
@@ -269,8 +277,9 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
debug += "Debugging: " debug += "Debugging: "
has_refresh = True has_refresh = True
""" get matchday closest to current date """ """ get matches of the matchday """
md_matches = Match.objects.filter(leagueShortcut=ls, season=season, matchday=int(matchday)).order_by('matchDateTime') md_matches = Match.objects.filter(leagueShortcut=ls, season=season,
matchday=int(matchday)).order_by('matchDateTime')
""" get the current user """ """ get the current user """
user = User.objects.get(username=request.user.username) user = User.objects.get(username=request.user.username)
@@ -357,6 +366,7 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
item['abbrTeam2']= str(match.idTeam2.abbr) item['abbrTeam2']= str(match.idTeam2.abbr)
item['started'] = match_started item['started'] = match_started
item['finished'] = match.finished item['finished'] = match.finished
item['md_name'] = match.matchday_name
if (match.pointsTeam1 == -1 or match.pointsTeam2 == -1): if (match.pointsTeam1 == -1 or match.pointsTeam2 == -1):
item['matchResult'] = "-:-" item['matchResult'] = "-:-"
@@ -392,17 +402,20 @@ def matchday(request, ls, season, matchday, template_name='md.html'):
# get the newest blogposts # get the newest blogposts
posts = [] posts = []
for post in Post.objects.filter(published=True)[:2]: for post in Post.objects.filter(published=True)[:1]:
try: try:
avatar = UserProfile.objects.get(user_id=post.author_id).avatar.name avatar = UserProfile.objects.get(user_id=post.author_id).avatar.name
except: except:
avatar = None avatar = None
posts.append( (post, avatar) ) posts.append( (post, avatar) )
cur_group = matches[0]['md_name']
return render(request, 'md.html', { return render(request, 'md.html', {
'debug': debug, #'debug': debug,
#'mds_season': mds_in_season, #'mds_season': mds_in_season,
'cur_md': matchday, 'cur_md': matchday,
'md_name': cur_group,
'matches': matches, 'matches': matches,
'ls': ls, 'ls': ls,
'season': season, 'season': season,
@@ -526,20 +539,22 @@ def logout(request):
logout(request) logout(request)
return HttpResponseRedirect('/') return HttpResponseRedirect('/')
def get_current_md(ls,season): def get_current_md(ls):
""" get current matchday """ """
get current matchday()
returns dict with keys
['groupName']
['groupOrderID']
['groupID']
""" """
try: try:
current_md = Match.objects.filter(leagueShortcut=ls, season=season, \ ol = OpenLiga()
finished=False).order_by('matchday').values_list('matchday', \ cur_md = ol.getCurrentGroup(ls)
flat=True).distinct()[0]
except IndexError:
current_md = Match.objects.filter(leagueShortcut=ls, season=season).aggregate(Max('matchday'))
except: except:
current_md = 34 cur_md = {'groupName': u"1. Spieltag", 'groupOrderID': 1}
"""
current_md = 34 return(cur_md)
return(current_md)
def get_current_ls(): def get_current_ls():
return("em2016") return("em2016")