Browse Source

Showstopper in forms that have no value for ModelChoiceField fixed.

Ralfp 12 years ago
parent
commit
2f009b6754
1 changed files with 3 additions and 1 deletions
  1. 3 1
      misago/forms/__init__.py

+ 3 - 1
misago/forms/__init__.py

@@ -14,6 +14,7 @@ class Form(forms.Form):
     error_source = None
     error_source = None
     def __init__(self, data=None, request=None, *args, **kwargs):
     def __init__(self, data=None, request=None, *args, **kwargs):
         self.request = request
         self.request = request
+        
         # Kill captcha fields
         # Kill captcha fields
         try:
         try:
             if self.request.settings['bots_registration'] != 'recaptcha' or self.request.session.get('captcha_passed'):
             if self.request.settings['bots_registration'] != 'recaptcha' or self.request.session.get('captcha_passed'):
@@ -29,6 +30,7 @@ class Form(forms.Form):
                 self.base_fields['captcha_qa'].help_text = self.request.session['qa_test_help']
                 self.base_fields['captcha_qa'].help_text = self.request.session['qa_test_help']
         except KeyError:
         except KeyError:
             pass
             pass
+        
         # Extract request from first argument
         # Extract request from first argument
         if data != None:
         if data != None:
             # Clean bad data
             # Clean bad data
@@ -43,7 +45,7 @@ class Form(forms.Form):
         """
         """
         for key, field in self.base_fields.iteritems():
         for key, field in self.base_fields.iteritems():
             try:
             try:
-                if field.__class__.__name__ == 'ModelChoiceField':
+                if field.__class__.__name__ == 'ModelChoiceField' and data[key]:
                     data[key] = int(data[key])
                     data[key] = int(data[key])
                 elif field.__class__.__name__ == 'ModelMultipleChoiceField':
                 elif field.__class__.__name__ == 'ModelMultipleChoiceField':
                     data.setlist(key, [int(x) for x in data.getlist(key, [])])
                     data.setlist(key, [int(x) for x in data.getlist(key, [])])