Browse Source

Some PEP8 fixes

sh4nks 10 years ago
parent
commit
bae6fa2073
4 changed files with 27 additions and 28 deletions
  1. 3 3
      flaskbb/forum/models.py
  2. 9 7
      flaskbb/management/views.py
  3. 12 15
      flaskbb/user/models.py
  4. 3 3
      manage.py

+ 3 - 3
flaskbb/forum/models.py

@@ -980,13 +980,13 @@ class Category(db.Model):
             ).add_entity(
                 ForumsRead
             ).order_by(
-                Category.position, Category.id,  forum_alias.position
+                Category.position, Category.id, forum_alias.position
             ).all()
         else:
             guest_group = Group.get_guest_group()
             # filter forums by guest groups
             guest_forums = Forum.query.filter(
-                Forum.groups.any(Group.id==guest_group.id)
+                Forum.groups.any(Group.id == guest_group.id)
             ).subquery()
             forum_alias = aliased(Forum, guest_forums)
             forums = cls.query.join(
@@ -1045,7 +1045,7 @@ class Category(db.Model):
             guest_group = Group.get_guest_group()
             # filter forums by guest groups
             guest_forums = Forum.query.filter(
-                Forum.groups.any(Group.id==guest_group.id)
+                Forum.groups.any(Group.id == guest_group.id)
             ).subquery()
             forum_alias = aliased(Forum, guest_forums)
             forums = cls.query.filter(

+ 9 - 7
flaskbb/management/views.py

@@ -479,14 +479,16 @@ def enable_plugin(plugin):
         try:
             if os.path.exists(disabled_file):
                 os.remove(disabled_file)
-                flash(_("Plugin is enabled. Please reload your app."), "success")
+                flash(_("Plugin is enabled. Please reload your app."),
+                      "success")
             else:
-                flash(_("Plugin is already enabled. Please reload  your app."), "warning")
+                flash(_("Plugin is already enabled. Please reload  your app."),
+                      "warning")
 
         except OSError:
-            flash(_("If you are using a host which doesn't support writting on the "
-                "disk, this won't work - than you need to delete the "
-                "'DISABLED' file by yourself."), "danger")
+            flash(_("If you are using a host which doesn't support writting "
+                    "on the disk, this won't work - than you need to delete "
+                    "the 'DISABLED' file by yourself."), "danger")
 
     else:
         flash(_("Couldn't enable Plugin."), "danger")
@@ -516,8 +518,8 @@ def disable_plugin(plugin):
 
     except OSError:
         flash(_("If you are using a host which doesn't "
-            "support writting on the disk, this won't work - than you need to "
-            "create a 'DISABLED' file by yourself."), "info")
+                "support writting on the disk, this won't work - than you "
+                "need to create a 'DISABLED' file by yourself."), "info")
 
     return redirect(url_for("management.plugins"))
 

+ 12 - 15
flaskbb/user/models.py

@@ -82,7 +82,7 @@ class Group(db.Model):
 
     @classmethod
     def get_guest_group(cls):
-        return Group.query.filter(cls.guest==True).first()
+        return Group.query.filter(cls.guest == True).first()
 
 
 class User(db.Model, UserMixin):
@@ -150,6 +150,11 @@ class User(db.Model, UserMixin):
         return self.get_permissions()
 
     @property
+    def groups(self):
+        """Returns user groups"""
+        return self.get_groups()
+
+    @property
     def days_registered(self):
         """Returns the amount of days the user is registered."""
         days_registered = (datetime.utcnow() - self.date_joined).days
@@ -172,11 +177,6 @@ class User(db.Model, UserMixin):
         """Returns the topics per day count"""
         return round((float(self.topic_count) / float(self.days_registered)), 1)
 
-    @property
-    def groups(self):
-        """Returns user groups"""
-        return [self.primary_group] + list(self.secondary_groups)
-
     # Methods
     def __repr__(self):
         """Set to a unique key specific to the object in the database.
@@ -280,7 +280,6 @@ class User(db.Model, UserMixin):
 
         :param topic: The topic which should be added to the topic tracker.
         """
-
         if not self.is_tracking_topic(topic):
             self.tracked_topics.append(topic)
             return self
@@ -291,7 +290,6 @@ class User(db.Model, UserMixin):
         :param topic: The topic which should be removed from the
                       topic tracker.
         """
-
         if self.is_tracking_topic(topic):
             self.tracked_topics.remove(topic)
             return self
@@ -310,7 +308,6 @@ class User(db.Model, UserMixin):
 
         :param group: The group which should be added to the user.
         """
-
         if not self.in_group(group):
             self.secondary_groups.append(group)
             return self
@@ -335,12 +332,16 @@ class User(db.Model, UserMixin):
             groups_users.c.group_id == group.id).count() > 0
 
     @cache.memoize(timeout=max_integer)
+    def get_groups(self):
+        """Returns all the groups the user is in."""
+        return [self.primary_group] + list(self.secondary_groups)
+
+    @cache.memoize(timeout=max_integer)
     def get_permissions(self, exclude=None):
         """Returns a dictionary with all the permissions the user has.
 
         :param exclude: a list with excluded permissions. default is None.
         """
-
         exclude = exclude or []
         exclude.extend(['id', 'name', 'description'])
 
@@ -367,12 +368,11 @@ class User(db.Model, UserMixin):
 
     def invalidate_cache(self):
         """Invalidates this objects cached metadata."""
-
         cache.delete_memoized(self.get_permissions, self)
+        cache.delete_memoized(self.get_groups, self)
 
     def ban(self):
         """Bans the user. Returns True upon success."""
-
         if not self.get_permissions()['banned']:
             banned_group = Group.query.filter(
                 Group.banned == True
@@ -386,7 +386,6 @@ class User(db.Model, UserMixin):
 
     def unban(self):
         """Unbans the user. Returns True upon success."""
-
         if self.get_permissions()['banned']:
             member_group = Group.query.filter(
                 Group.admin == False,
@@ -409,7 +408,6 @@ class User(db.Model, UserMixin):
         :param groups: A list with groups that should be added to the
                        secondary groups from user.
         """
-
         if groups:
             # TODO: Only remove/add groups that are selected
             secondary_groups = self.secondary_groups.all()
@@ -431,7 +429,6 @@ class User(db.Model, UserMixin):
 
     def delete(self):
         """Deletes the User."""
-
         # This isn't done automatically...
         Conversation.query.filter_by(user_id=self.id).delete()
         ForumsRead.query.filter_by(user_id=self.id).delete()

+ 3 - 3
manage.py

@@ -83,11 +83,11 @@ def populate(dropdb=False, createdb=False):
     '-c' (to not create the db) and '-d' (to not drop the db)
     """
 
-    if not dropdb:
+    if dropdb:
         print("Dropping database...")
         db.drop_all()
 
-    if not createdb:
+    if createdb:
         print("Creating database...")
         upgrade()
 
@@ -303,7 +303,7 @@ def download_emoji():
             f = open(full_path, 'wb')
             f.write(requests.get(image["download_url"]).content)
             f.close()
-            if count == cached_count+50:
+            if count == cached_count + 50:
                 cached_count = count
                 print("{} out of {} Emojis downloaded...".format(
                       cached_count, len(response.json())))