Browse Source

Default groups for forums

sh4nks 10 years ago
parent
commit
26e3e84336
3 changed files with 11 additions and 7 deletions
  1. 9 2
      flaskbb/forum/models.py
  2. 2 2
      flaskbb/management/forms.py
  3. 0 3
      flaskbb/management/views.py

+ 9 - 2
flaskbb/forum/models.py

@@ -780,12 +780,19 @@ class Forum(db.Model):
         # Nothing updated, because there are still more than 0 unread topicsread
         # Nothing updated, because there are still more than 0 unread topicsread
         return False
         return False
 
 
-    def save(self):
-        """Saves a forum"""
+    def save(self, groups=None):
+        """Saves a forum
+
+        :param groups: A list with group objects."""
         if self.id:
         if self.id:
             db.session.merge(self)
             db.session.merge(self)
         else:
         else:
+            if groups is None:
+                # importing here because of circular dependencies
+                from flaskbb.user.models import Group
+                self.groups = Group.query.order_by(Group.name.asc()).all()
             db.session.add(self)
             db.session.add(self)
+
         db.session.commit()
         db.session.commit()
         return self
         return self
 
 

+ 2 - 2
flaskbb/management/forms.py

@@ -375,7 +375,7 @@ class ForumForm(Form):
             pass
             pass
         elif field.raw_data:
         elif field.raw_data:
             ids = field.raw_data.pop().split(",")
             ids = field.raw_data.pop().split(",")
-            groups  = Group.query.filter(Group.id.in_(ids)).all()
+            groups = Group.query.filter(Group.id.in_(ids)).all()
             field.data = groups
             field.data = groups
         else:
         else:
             field.data = []
             field.data = []
@@ -386,7 +386,7 @@ class ForumForm(Form):
         # remove the button
         # remove the button
         data.pop('submit', None)
         data.pop('submit', None)
         forum = Forum(**data)
         forum = Forum(**data)
-        #flush SQLA info from created instabce so that it can be merged
+        # flush SQLA info from created instabce so that it can be merged
         make_transient(forum)
         make_transient(forum)
         make_transient_to_detached(forum)
         make_transient_to_detached(forum)
 
 

+ 0 - 3
flaskbb/management/views.py

@@ -404,9 +404,6 @@ def add_forum(category_id=None):
         flash(_("Forum successfully added."), "success")
         flash(_("Forum successfully added."), "success")
         return redirect(url_for("management.forums"))
         return redirect(url_for("management.forums"))
     else:
     else:
-        # by default all groups have access to a forum
-        form.groups.data = Group.query.order_by(Group.name.asc()).all()
-
         if category_id:
         if category_id:
             category = Category.query.filter_by(id=category_id).first()
             category = Category.query.filter_by(id=category_id).first()
             form.category.data = category
             form.category.data = category