diff --git a/templates/md.html b/templates/md.html index 370b4e7..c0ac288 100644 --- a/templates/md.html +++ b/templates/md.html @@ -40,32 +40,7 @@ diff --git a/tipp/models.py b/tipp/models.py index 934ef0c..38262cd 100644 --- a/tipp/models.py +++ b/tipp/models.py @@ -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'] diff --git a/tipp/openliga.py b/tipp/openliga.py index 61ffa77..23a1a88 100755 --- a/tipp/openliga.py +++ b/tipp/openliga.py @@ -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)) + + diff --git a/tipp/views.py b/tipp/views.py index 797a8b3..6f2cde6 100644 --- a/tipp/views.py +++ b/tipp/views.py @@ -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")