diff --git a/tipp/views.py b/tipp/views.py index 3c2319a..8455a19 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.