Browse Source

Fix creating new categories

sh4nks 11 years ago
parent
commit
918d258bc6
1 changed files with 7 additions and 3 deletions
  1. 7 3
      flaskbb/admin/forms.py

+ 7 - 3
flaskbb/admin/forms.py

@@ -228,6 +228,7 @@ class ForumForm(Form):
 
 
     parent = QuerySelectField("Parent",
     parent = QuerySelectField("Parent",
                               query_factory=selectable_forums,
                               query_factory=selectable_forums,
+                              allow_blank=True,
                               get_label="title",
                               get_label="title",
                               description="This field is not saved if this \
                               description="This field is not saved if this \
                                            forum is a category (see \"Is a \
                                            forum is a category (see \"Is a \
@@ -235,14 +236,16 @@ class ForumForm(Form):
 
 
     is_category = BooleanField("Is a category?",
     is_category = BooleanField("Is a category?",
                                description="Categories are root-level parents \
                                description="Categories are root-level parents \
-                               for forums. They can not contain topics.")
+                                            for forums. They can not contain \
+                                            topics.")
 
 
     locked = BooleanField("Locked?", description="Disable new posts and topics \
     locked = BooleanField("Locked?", description="Disable new posts and topics \
                                                   in this forum.")
                                                   in this forum.")
 
 
     def validate_parent(self, field):
     def validate_parent(self, field):
-        if field.data.id == self._id:
-            raise ValidationError("A forum cannot be it's own parent!")
+        if hasattr(field.data, "id"):
+            if field.data.id == self._id:
+                raise ValidationError("A forum cannot be it's own parent!")
 
 
     def save(self):
     def save(self):
         forum = Forum(title=self.title.data,
         forum = Forum(title=self.title.data,
@@ -251,6 +254,7 @@ class ForumForm(Form):
 
 
         if self.is_category.data:
         if self.is_category.data:
             forum.is_category = True
             forum.is_category = True
+            forum.parent_id = None
         else:
         else:
             forum.parent_id = self.parent.data.id
             forum.parent_id = self.parent.data.id