Browse Source

Dropped forum template choice in favor of more versatile solution.

Ralfp 12 years ago
parent
commit
9aa3f92269
4 changed files with 34 additions and 18 deletions
  1. 4 1
      misago/acl/panels.py
  2. 22 12
      misago/forums/forms.py
  3. 4 1
      misago/forums/models.py
  4. 4 4
      misago/forums/views.py

+ 4 - 1
misago/acl/panels.py

@@ -23,5 +23,8 @@ class MisagoACLDebugPanel(DebugPanel):
             self.has_content = False
             self.has_content = False
         else:
         else:
             context = self.context.copy()
             context = self.context.copy()
-            context['acl'] = self.request.acl
+            try:
+                context['acl'] = self.request.acl
+            except AttributeError:
+                context['acl'] = {}
             return render_to_string('debug_toolbar/panels/acl.html', context)
             return render_to_string('debug_toolbar/panels/acl.html', context)

+ 22 - 12
misago/forums/forms.py

@@ -15,11 +15,7 @@ class CategoryForm(Form):
     description = forms.CharField(widget=forms.Textarea, required=False)
     description = forms.CharField(widget=forms.Textarea, required=False)
     closed = forms.BooleanField(widget=YesNoSwitch, required=False)
     closed = forms.BooleanField(widget=YesNoSwitch, required=False)
     style = forms.CharField(max_length=255, required=False)
     style = forms.CharField(max_length=255, required=False)
-    template = forms.ChoiceField(choices=(
-                                          ('row', _('One forum per row')),
-                                          ('half', _('Two forums per row')),
-                                          ('quarter', _('Four forums per row')),
-                                          ))
+    attrs = forms.CharField(max_length=255, required=False)
     show_details = forms.BooleanField(widget=YesNoSwitch, required=False)
     show_details = forms.BooleanField(widget=YesNoSwitch, required=False)
 
 
     layout = (
     layout = (
@@ -36,7 +32,7 @@ class CategoryForm(Form):
               (
               (
                _("Display Options"),
                _("Display Options"),
                (
                (
-                ('template', {'label': _("Category Layout"), 'help_text': _('Controls how this category is displayed on forums lists.')}),
+                ('attrs', {'label': _("Category Attributes"), 'help_text': _('Custom templates can check categories for predefined attributes that will change way they are rendered.')}),
                 ('show_details', {'label': _("Show Subforums Details"), 'help_text': _('Allows you to prevent this category subforums from displaying statistics, last post data, etc. ect. on forums lists.')}),
                 ('show_details', {'label': _("Show Subforums Details"), 'help_text': _('Allows you to prevent this category subforums from displaying statistics, last post data, etc. ect. on forums lists.')}),
                 ('style', {'label': _("Category Style"), 'help_text': _('You can add custom CSS classess to this category, to change way it looks on board index.')}),
                 ('style', {'label': _("Category Style"), 'help_text': _('You can add custom CSS classess to this category, to change way it looks on board index.')}),
                 ),
                 ),
@@ -47,6 +43,15 @@ class CategoryForm(Form):
         self.fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(include_self=True), level_indicator=u'- - ')
         self.fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(include_self=True), level_indicator=u'- - ')
         self.fields['perms'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(), level_indicator=u'- - ', required=False, empty_label=_("Don't copy permissions"))
         self.fields['perms'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(), level_indicator=u'- - ', required=False, empty_label=_("Don't copy permissions"))
 
 
+    def clean_attrs(self):
+        clean = []
+        data = self.cleaned_data['attrs'].strip().split()
+        for i in data:
+            i = i.strip()
+            if not i in clean:
+                clean.append(i)
+        return ' '.join(clean)
+
 
 
 class ForumForm(Form):
 class ForumForm(Form):
     parent = False
     parent = False
@@ -60,11 +65,7 @@ class ForumForm(Form):
     style = forms.CharField(max_length=255, required=False)
     style = forms.CharField(max_length=255, required=False)
     prune_start = forms.IntegerField(min_value=0, initial=0)
     prune_start = forms.IntegerField(min_value=0, initial=0)
     prune_last = forms.IntegerField(min_value=0, initial=0)
     prune_last = forms.IntegerField(min_value=0, initial=0)
-    template = forms.ChoiceField(choices=(
-                                          ('row', _('One forum per row')),
-                                          ('half', _('Two forums per row')),
-                                          ('quarter', _('Four forums per row')),
-                                          ))
+    attrs = forms.CharField(max_length=255, required=False)
     show_details = forms.BooleanField(widget=YesNoSwitch, required=False)
     show_details = forms.BooleanField(widget=YesNoSwitch, required=False)
 
 
     layout = (
     layout = (
@@ -88,7 +89,7 @@ class ForumForm(Form):
               (
               (
                _("Display Options"),
                _("Display Options"),
                (
                (
-                ('template', {'label': _("Subforums Layout"), 'help_text': _('Controls how this forum displays subforums list.')}),
+                ('attrs', {'label': _("Subforums List Attributes"), 'help_text': _('Custom templates can check forums for predefined attributes that will change way subforums lists are rendered.')}),
                 ('show_details', {'label': _("Show Subforums Details"), 'help_text': _("Allows you to prevent this forum's subforums from displaying statistics, last post data, etc. ect. on subforums list.")}),
                 ('show_details', {'label': _("Show Subforums Details"), 'help_text': _("Allows you to prevent this forum's subforums from displaying statistics, last post data, etc. ect. on subforums list.")}),
                 ('style', {'label': _("Forum Style"), 'help_text': _('You can add custom CSS classess to this forum to change way it looks on forums lists.')}),
                 ('style', {'label': _("Forum Style"), 'help_text': _('You can add custom CSS classess to this forum to change way it looks on forums lists.')}),
                 ),
                 ),
@@ -99,6 +100,15 @@ class ForumForm(Form):
         self.fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(), level_indicator=u'- - ')
         self.fields['parent'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(), level_indicator=u'- - ')
         self.fields['perms'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(), level_indicator=u'- - ', required=False, empty_label=_("Don't copy permissions"))
         self.fields['perms'] = TreeNodeChoiceField(queryset=Forum.tree.get(token='root').get_descendants(), level_indicator=u'- - ', required=False, empty_label=_("Don't copy permissions"))
 
 
+    def clean_attrs(self):
+        clean = []
+        data = self.cleaned_data['attrs'].strip().split()
+        for i in data:
+            i = i.strip()
+            if not i in clean:
+                clean.append(i)
+        return ' '.join(clean)
+
 
 
 class RedirectForm(Form):
 class RedirectForm(Form):
     parent = False
     parent = False

+ 4 - 1
misago/forums/models.py

@@ -135,7 +135,7 @@ class Forum(MPTTModel):
     prune_start = models.PositiveIntegerField(default=0)
     prune_start = models.PositiveIntegerField(default=0)
     prune_last = models.PositiveIntegerField(default=0)
     prune_last = models.PositiveIntegerField(default=0)
     redirect = models.CharField(max_length=255, null=True, blank=True)
     redirect = models.CharField(max_length=255, null=True, blank=True)
-    template = models.CharField(default='row', max_length=255, null=True, blank=True)
+    attrs = models.CharField(max_length=255, null=True, blank=True)
     show_details = models.BooleanField(default=True)
     show_details = models.BooleanField(default=True)
     style = models.CharField(max_length=255, null=True, blank=True)
     style = models.CharField(max_length=255, null=True, blank=True)
     closed = models.BooleanField(default=False)
     closed = models.BooleanField(default=False)
@@ -168,6 +168,9 @@ class Forum(MPTTModel):
     def move_content(self, target):
     def move_content(self, target):
         move_forum_content.send(sender=self, move_to=target)
         move_forum_content.send(sender=self, move_to=target)
 
 
+    def attr(self, att):
+        return att in self.attrs.split()
+
     def sync(self):
     def sync(self):
         self.threads = self.thread_set.filter(moderated=False).filter(deleted=False).count()
         self.threads = self.thread_set.filter(moderated=False).filter(deleted=False).count()
         self.posts = self.post_set.filter(moderated=False).filter(deleted=False).count()
         self.posts = self.post_set.filter(moderated=False).filter(deleted=False).count()

+ 4 - 4
misago/forums/views.py

@@ -85,7 +85,7 @@ class NewCategory(FormWidget):
                           name=form.cleaned_data['name'],
                           name=form.cleaned_data['name'],
                           slug=slugify(form.cleaned_data['name']),
                           slug=slugify(form.cleaned_data['name']),
                           type='category',
                           type='category',
-                          template=form.cleaned_data['template'],
+                          attrs=form.cleaned_data['attrs'],
                           show_details=form.cleaned_data['show_details'],
                           show_details=form.cleaned_data['show_details'],
                           style=form.cleaned_data['style'],
                           style=form.cleaned_data['style'],
                           closed=form.cleaned_data['closed'],
                           closed=form.cleaned_data['closed'],
@@ -119,7 +119,7 @@ class NewForum(FormWidget):
                           name=form.cleaned_data['name'],
                           name=form.cleaned_data['name'],
                           slug=slugify(form.cleaned_data['name']),
                           slug=slugify(form.cleaned_data['name']),
                           type='forum',
                           type='forum',
-                          template=form.cleaned_data['template'],
+                          attrs=form.cleaned_data['attrs'],
                           show_details=form.cleaned_data['show_details'],
                           show_details=form.cleaned_data['show_details'],
                           style=form.cleaned_data['style'],
                           style=form.cleaned_data['style'],
                           closed=form.cleaned_data['closed'],
                           closed=form.cleaned_data['closed'],
@@ -250,7 +250,7 @@ class Edit(FormWidget):
         if model.type == 'redirect':
         if model.type == 'redirect':
             initial['redirect'] = model.redirect
             initial['redirect'] = model.redirect
         else:
         else:
-            initial['template'] = model.template
+            initial['attrs'] = model.attrs
             initial['show_details'] = model.show_details
             initial['show_details'] = model.show_details
             initial['style'] = model.style
             initial['style'] = model.style
             initial['closed'] = model.closed
             initial['closed'] = model.closed
@@ -268,7 +268,7 @@ class Edit(FormWidget):
         if target.type == 'redirect':
         if target.type == 'redirect':
             target.redirect = form.cleaned_data['redirect']
             target.redirect = form.cleaned_data['redirect']
         else:
         else:
-            target.template = form.cleaned_data['template']
+            target.attrs = form.cleaned_data['attrs']
             target.show_details = form.cleaned_data['show_details']
             target.show_details = form.cleaned_data['show_details']
             target.style = form.cleaned_data['style']
             target.style = form.cleaned_data['style']
             target.closed = form.cleaned_data['closed']
             target.closed = form.cleaned_data['closed']