Added support for User.flag_showhidden edition.
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Fri, 13 May 2011 13:51:11 +0000 (13:51 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Fri, 13 May 2011 13:51:11 +0000 (13:51 +0000)
bin/djais/views.py

index 98ba0ca1685cce744ed6f08cbc67e2ea9005e555..32ede76d373d8e9a05985d51025e814fd37c48f3 100644 (file)
@@ -965,9 +965,12 @@ class UserEditForm(forms.Form):
     email = forms.EmailField()
     phone = forms.RegexField(regex='\\+.+', max_length=20, required=False,
         error_message ='Phones must start with a \'+\'')
-    def __init__(self, *args, **kargs):
+    def __init__(self, show_flag_showhidden, *args, **kargs):
         forms.Form.__init__(self, *args, **kargs)
         self.old_login = kargs['initial']['login']
+        if show_flag_showhidden:
+            self.fields['show_hidden_ships'] = forms.BooleanField(required=False)
+
     def clean_login(self):
         new_login = self.cleaned_data['login']
         if new_login != self.old_login:
@@ -997,18 +1000,21 @@ def user_edit(request, login):
     initial['name'] = user.name
     initial['email'] = user.email
     initial['phone'] = user.phone
+    initial['show_hidden_ships'] = user.flag_allowhidden
     if request.method == 'POST':
-        form = UserEditForm(request.POST, initial=initial)
+        form = UserEditForm(request.user.flag_allowhidden, request.POST, initial=initial)
         if form.is_valid():
             user.login = form.cleaned_data['login']
             user.name = form.cleaned_data['name']
             user.email = form.cleaned_data['email']
             user.phone = form.cleaned_data['phone']
+            if request.user.flag_allowhidden:
+                user.flag_allowhidden = form.cleaned_data['show_hidden_ships']
             user.save()
             user.check_sandbox_access(request.user)
             return HttpResponseRedirect('/user/')
     else: # GET
-        form = UserEditForm(initial=initial)
+        form = UserEditForm(request.user.flag_allowhidden, initial=initial)
 
     return render_to_response('user_edit.html', {'form':form, 'auser': user}, RequestContext(request))