diff --git a/tipp/views.py b/tipp/views.py index 3c2319a..e64bd89 100644 --- a/tipp/views.py +++ b/tipp/views.py @@ -38,7 +38,12 @@ from tipp.forms import * from openliga import * from datetime import datetime from PIL import Image as PImage -import urllib2, pytz, os +import urllib2, pytz, os, sys + +# setting utf-8 as default encoding to avoid errors in file +# uploads and form data +reload(sys) +sys.setdefaultencoding('utf8') timezoneLocal = pytz.timezone('Europe/Berlin') @@ -68,25 +73,17 @@ def profile(request, pk): # If it's a HTTP POST, we're interested in processing form data. if request.method == 'POST': - # Attempt to grab information from the raw form information. - # Note that we make use of both UserForm and UserProfileForm. user_form = UserForm(data=request.POST, instance=user) profile_form = UserProfileForm(data=request.POST, instance=profile) - # If the two forms are valid... if user_form.is_valid() and profile_form.is_valid(): - # Save the user's form data to the database. user = user_form.save() - # Now sort out the UserProfile instance. - # Since we need to set the user attribute ourselves, we set commit=False. - # This delays saving the model until we're ready to avoid integrity problems. profile = profile_form.save(commit=False) profile.user = user # Did the user provide a profile picture? - # If so, we need to get it from the input form and put it in the UserProfile model. if 'avatar' in request.FILES: profile.avatar = request.FILES['avatar'] # Now we save the UserProfile model instance. @@ -108,8 +105,6 @@ def profile(request, pk): for item in request.POST: debug.append(str(item) + " -> " + str(request.POST[item])) - - # Invalid form or forms - mistakes or something else? # Print problems to the terminal. # They'll also be shown to the user. @@ -117,6 +112,7 @@ def profile(request, pk): print user_form.errors, profile_form.errors return redirect( '/accounts/profile/' + str(user.id) ) + # Not a HTTP POST, so we render our form using two ModelForm instances. # These forms will be blank, ready for user input. else: @@ -335,7 +331,13 @@ def matchday(request, ls, season, matchday, template_name='md.html'): try: matetipp = Tipp.objects.get(tipperID=mate['mate'],matchID=match.matchID) if match_started is True: - mate['tipps'].append(str(matetipp.pointsTeam1) + ":" + str(matetipp.pointsTeam2) + "(" + str(matetipp.score) + ")") + 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: @@ -401,8 +403,11 @@ def charts(request, ls, season, pos='default', template_name='charts.html'): # get user object, then fetch matches for user user = User.objects.get(id=userid) score = Tipp.objects.filter(matchID__in=matches, tipperID=user).aggregate(Sum('score')) - - user_dict[user.first_name] = score['score__sum'] + + if score['score__sum'] is None: + user_dict[user.first_name] = 0 + else: + user_dict[user.first_name] = score['score__sum'] mandant_dict[mandant.name] = sorted(user_dict.items(), key=lambda x: x[1], reverse=True)