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>
<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>
{% if ls == "em2016" %}
{% 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 %}
{{ md_name }}
<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>
</nav>

View File

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

View File

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