diff --git a/templates/md.html b/templates/md.html index c0ac288..ad8621b 100644 --- a/templates/md.html +++ b/templates/md.html @@ -110,13 +110,16 @@ {% endfor %} - {% for mate in tipp_mates %} + {% for mandant in mandant_dict %} + + {% for mate in mandant_dict.mandant %} {{ mate.mate.first_name }} {{ mate.sum_score }} {% for tipp in mate.tipps %} {{ tipp }} {% endfor %} + {% endfor %} {% endfor %} diff --git a/tipp/views.py b/tipp/views.py index f7c6de2..2f1a4f6 100644 --- a/tipp/views.py +++ b/tipp/views.py @@ -316,22 +316,18 @@ def matchday(request, ls, season, matchday, template_name='md.html'): values_list('mandant', flat=True) """ get mates """ - tipp_mates = [] + mandant_dict = {} for m in mandants: + mandant = Mandant.objects.get(id=m) + mandant_dict[mandant.name] = [] rs = RelUserMandant.objects.filter(mandant=m) - for r in rs: - """filter duplicates """ - d = False - for item in tipp_mates: - if r.user == item['mate']: - d = True - if d is False: - tipp_mates.append({ - 'mate': r.user, - 'tipps': [], - 'sum_score': 0 - }) + for r in rs: + mandant_dict[mandant.name].append({ + 'mate': r.user, + 'tipps': [], + 'sum_score': 0 + }) matches = [] for match in md_matches: @@ -412,25 +408,27 @@ def matchday(request, ls, season, matchday, template_name='md.html'): f.fields['tippTeam1'].widget.attrs['disabled'] = True f.fields['tippTeam2'].widget.attrs['disabled'] = True - for mate in tipp_mates: - try: - matetipp = Tipp.objects.get(tipperID=mate['mate'], - matchID=match.matchID) - if match_started is True: - if matetipp.score is None: - score = u'\u231B' - else: - score = matetipp.score + """ get tipps from mates """ + for mandant in mandant_dict: + for mate in mandant_dict[mandant]: + try: + matetipp = Tipp.objects.get(tipperID=mate['mate'], + matchID=match.matchID) + if match_started is True: + if matetipp.score is None: + score = u'\u231B' + else: + score = matetipp.score - mate['tipps'].append(str(matetipp.pointsTeam1) - + ":" + str(matetipp.pointsTeam2) - + "(" + str(score) + ")") - if match.finished is True: - mate['sum_score'] += matetipp.score - else: - mate['tipps'].append(u'\u2714') - except Exception as e: - mate['tipps'].append(u'\u2717') + mate['tipps'].append(str(matetipp.pointsTeam1) + + ":" + str(matetipp.pointsTeam2) + + "(" + str(score) + ")") + if match.finished is True: + mate['sum_score'] += matetipp.score + else: + mate['tipps'].append(u'\u2714') + except Exception as e: + mate['tipps'].append(u'\u2717') matches.append(item) @@ -460,8 +458,9 @@ def matchday(request, ls, season, matchday, template_name='md.html'): 'ls': ls, 'season': season, 'username': user, - 'tipp_mates': sorted(tipp_mates, key=lambda k: k['sum_score'], - reverse=True), + 'mandant_dict': mandant_dict, + #'tipp_mates': sorted(tipp_mates, key=lambda k: k['sum_score'], + #reverse=True), 'posts': posts, 'has_refresh': has_refresh })