summaryrefslogtreecommitdiff
path: root/devel
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2013-11-08 13:14:27 -0600
committerDan McGee <dan@archlinux.org>2013-11-08 13:15:02 -0600
commite2fc5cfccdd2f844e75df75f44fff84f4181da7d (patch)
tree0a90df2557f2a49829fcadde24b51fda176e87e2 /devel
parent7ac017e1e7884320bd00f67134dd1ae7e06ceaaf (diff)
Ensure user has a profile created when they go to edit it
Use get_or_create, even though it leaves a bad taste in my mouth. The first user created won't have a profile becuase Django doesn't create one for users created at the command line, causing an exception when the user goes to edit it. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'devel')
-rw-r--r--devel/views.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/devel/views.py b/devel/views.py
index 378d6d57..b6e85822 100644
--- a/devel/views.py
+++ b/devel/views.py
@@ -20,7 +20,7 @@ from django.utils.http import http_date
from django.utils.timezone import now
from .forms import ProfileForm, UserProfileForm, NewUserForm
-from .models import DeveloperKey
+from .models import DeveloperKey, UserProfile
from main.models import Package, PackageFile
from main.models import Arch, Repo
from news.models import News
@@ -158,10 +158,11 @@ def clock(request):
@login_required
@never_cache
def change_profile(request):
+ profile, _ = UserProfile.objects.get_or_create(user=request.user)
if request.POST:
form = ProfileForm(request.POST)
profile_form = UserProfileForm(request.POST, request.FILES,
- instance=request.user.userprofile)
+ instance=profile)
if form.is_valid() and profile_form.is_valid():
request.user.email = form.cleaned_data['email']
if form.cleaned_data['passwd1']:
@@ -172,7 +173,7 @@ def change_profile(request):
return HttpResponseRedirect('/devel/')
else:
form = ProfileForm(initial={'email': request.user.email})
- profile_form = UserProfileForm(instance=request.user.userprofile)
+ profile_form = UserProfileForm(instance=profile)
return render(request, 'devel/profile.html',
{'form': form, 'profile_form': profile_form})