Browse Source

Replaced type with test to match model change

Ralfp 12 years ago
parent
commit
e0837b4a4b
2 changed files with 23 additions and 23 deletions
  1. 14 14
      misago/apps/admin/bans/forms.py
  2. 9 9
      misago/apps/admin/bans/views.py

+ 14 - 14
misago/apps/admin/bans/forms.py

@@ -6,12 +6,12 @@ class BanForm(Form):
     """
     New/Edit Ban form
     """
-    type = forms.ChoiceField(choices=(
-                                      (0, _('Ban Username and e-mail')),
-                                      (1, _('Ban Username')),
-                                      (2, _('Ban E-mail address')),
-                                      (3, _('Ban IP Address'))
-                                      ))
+    test = forms.TypedChoiceField(choices=(
+                                           (0, _('Ban Username and e-mail')),
+                                           (1, _('Ban Username')),
+                                           (2, _('Ban E-mail address')),
+                                           (3, _('Ban IP Address'))
+                                           ), coerce=int)
     reason_user = forms.CharField(widget=forms.Textarea, required=False)
     reason_admin = forms.CharField(widget=forms.Textarea, required=False)
     ban = forms.CharField(max_length=255)
@@ -20,7 +20,7 @@ class BanForm(Form):
                (
                  _("Ban Details"),
                  (
-                  ('nested', (('type', {'label': _("Ban Rule"), 'help_text': _("Select ban type from list and define rule by entering it in text field. If you want to ban specific user, enter here either his Username or E-mail address. If you want to define blanket ban, you can use wildcard (\"*\"). For example to forbid all members from using name suggesting that member is an admin, you can set ban that forbids \"Admin*\" as username."), 'width': 25}),
+                  ('nested', (('test', {'label': _("Ban Rule"), 'help_text': _("Select ban type from list and define rule by entering it in text field. If you want to ban specific user, enter here either his Username or E-mail address. If you want to define blanket ban, you can use wildcard (\"*\"). For example to forbid all members from using name suggesting that member is an admin, you can set ban that forbids \"Admin*\" as username."), 'width': 25}),
                   ('ban', {'width': 75}))),
                   ('expires', {'label': _("Ban Expiration"), 'help_text': _("If you want to, you can set this ban's expiration date by entering it here using YYYY-MM-DD format. Otherwhise you can leave this field empty making this ban permanent.")}),
                  ),
@@ -38,19 +38,19 @@ class BanForm(Form):
 class SearchBansForm(Form):
     ban = forms.CharField(required=False)
     reason = forms.CharField(required=False)
-    type = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=(
-                                      ("0", _('Username and e-mail')),
-                                      ("1", _('Username')),
-                                      ("2", _('E-mail address')),
-                                      ("3", _('IP Address'))
-                                      ), required=False)
+    test = forms.TypedMultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=(
+                                          (0, _('Username and e-mail')),
+                                          (1, _('Username')),
+                                          (2, _('E-mail address')),
+                                          (3, _('IP Address'))
+                                          ), coerce=int, required=False)
     layout = (
               (
                _("Search Bans"),
                (
                 ('ban', {'label': _("Ban"), 'attrs': {'placeholder': _("Ban contains...")}}),
                 ('reason', {'label': _("Messages"), 'attrs': {'placeholder': _("User or Team message contains...")}}),
-                ('type', {'label': _("Type")}),
+                ('test', {'label': _("Type")}),
                ),
               ),
              )

+ 9 - 9
misago/apps/admin/bans/views.py

@@ -46,8 +46,8 @@ class List(ListWidget):
             model = model.filter(ban__contains=filters['ban'])
         if 'reason' in filters:
             model = model.filter(Q(reason_user__contains=filters['reason']) | Q(reason_admin__contains=filters['reason']))
-        if 'type' in filters:
-            model = model.filter(type__in=filters['type'])
+        if 'test' in filters:
+            model = model.filter(test__in=filters['test'])
         return model
 
     def get_item_actions(self, item):
@@ -80,7 +80,7 @@ class New(FormWidget):
 
     def submit_form(self, form, target):
         new_ban = Ban(
-                      type=form.cleaned_data['type'],
+                      test=form.cleaned_data['test'],
                       ban=form.cleaned_data['ban'],
                       reason_user=form.cleaned_data['reason_user'],
                       reason_admin=form.cleaned_data['reason_admin'],
@@ -112,7 +112,7 @@ class Edit(FormWidget):
 
     def get_initial_data(self, model):
         return {
-                'type': model.type,
+                'test': model.test,
                 'ban': model.ban,
                 'reason_user': model.reason_user,
                 'reason_admin': model.reason_admin,
@@ -120,7 +120,7 @@ class Edit(FormWidget):
                 }
 
     def submit_form(self, form, target):
-        target.type = form.cleaned_data['type']
+        target.test = form.cleaned_data['test']
         target.ban = form.cleaned_data['ban']
         target.reason_user = form.cleaned_data['reason_user']
         target.reason_admin = form.cleaned_data['reason_admin']
@@ -142,11 +142,11 @@ class Delete(ButtonWidget):
     def action(self, target):
         target.delete()
         self.request.monitor['bans_version'] = int(self.request.monitor['bans_version']) + 1
-        if target.type == 0:
+        if target.test == 0:
             return Message(_('E-mail and username Ban "%(ban)s" has been lifted.') % {'ban': target.ban}, 'success'), False
-        if target.type == 1:
+        if target.test == 1:
             return Message(_('Username Ban "%(ban)s" has been lifted.') % {'ban': target.ban}, 'success'), False
-        if target.type == 2:
+        if target.test == 2:
             return Message(_('E-mail Ban "%(ban)s" has been lifted.') % {'ban': target.ban}, 'success'), False
-        if target.type == 3:
+        if target.test == 3:
             return Message(_('IP Ban "%(ban)s" has been lifted.') % {'ban': target.ban}, 'success'), False