Browse Source

Use better variable names

sh4nks 10 years ago
parent
commit
c28d2b2768
3 changed files with 18 additions and 25 deletions
  1. 8 8
      flaskbb/api/forums.py
  2. 6 14
      flaskbb/api/users.py
  3. 4 3
      flaskbb/app.py

+ 8 - 8
flaskbb/api/forums.py

@@ -87,8 +87,8 @@ class CategoryAPI(Resource):
     def __init__(self):
         super(CategoryAPI, self).__init__()
 
-    def get(self, id):
-        category = Category.query.filter_by(id=id).first()
+    def get(self, category_id):
+        category = Category.query.filter_by(id=category_id).first()
 
         if not category:
             abort(404)
@@ -123,8 +123,8 @@ class ForumAPI(Resource):
     def __init__(self):
         super(ForumAPI, self).__init__()
 
-    def get(self, id):
-        forum = Forum.query.filter_by(id=id).first()
+    def get(self, forum_id):
+        forum = Forum.query.filter_by(id=forum_id).first()
 
         if not forum:
             abort(404)
@@ -166,8 +166,8 @@ class TopicAPI(Resource):
     def __init__(self):
         super(TopicAPI, self).__init__()
 
-    def get(self, id):
-        topic = Topic.query.filter_by(id=id).first()
+    def get(self, topic_id):
+        topic = Topic.query.filter_by(id=topic_id).first()
 
         if not topic:
             abort(404)
@@ -210,8 +210,8 @@ class PostAPI(Resource):
     def __init__(self):
         super(PostAPI, self).__init__()
 
-    def get(self, id):
-        post = Post.query.filter_by(id=id).first()
+    def get(self, post_id):
+        post = Post.query.filter_by(id=post_id).first()
 
         if not post:
             abort(404)

+ 6 - 14
flaskbb/api/users.py

@@ -16,14 +16,6 @@ from flask_restful import Resource, reqparse, fields, marshal, abort
 from flaskbb.api import auth
 from flaskbb.user.models import User
 
-# CREATE NEW USER
-# curl -u test:test1 -i -H "Content-Type: application/json" -X POST -d '{"username":"test6", "password": "test", "email": "test6@example.org"}' http://localhost:8080/api/users
-
-# UPDATE USER
-# curl -u test1:test -i -H "Content-Type: application/json" -X PUT -d '{"email": "test7@example.org"}' http://localhost:8080/api/users/5
-
-# GET USER
-# curl -i http://localhost:8080/api/users
 
 user_fields = {
     'id': fields.Integer,
@@ -91,8 +83,8 @@ class UserAPI(Resource):
 
         super(UserAPI, self).__init__()
 
-    def get(self, id):
-        user = User.query.filter_by(id=id).first()
+    def get(self, user_id):
+        user = User.query.filter_by(id=user_id).first()
 
         if not user:
             abort(404)
@@ -100,8 +92,8 @@ class UserAPI(Resource):
         return {'user': marshal(user, user_fields)}
 
     @auth.login_required
-    def put(self, id):
-        user = User.query.filter_by(id=id).first()
+    def put(self, user_id):
+        user = User.query.filter_by(id=user_id).first()
 
         if not user:
             abort(404)
@@ -117,8 +109,8 @@ class UserAPI(Resource):
         return {'user': marshal(user, user_fields)}
 
     @auth.login_required
-    def delete(self, id):
-        user = User.query.filter_by(id=id).first()
+    def delete(self, user_id):
+        user = User.query.filter_by(id=user_id).first()
 
         if not user:
             abort(404)

+ 4 - 3
flaskbb/app.py

@@ -149,14 +149,15 @@ def configure_extensions(app):
     login_manager.anonymous_user = Guest
 
     @login_manager.user_loader
-    def load_user(id):
+    def load_user(user_id):
         """
         Loads the user. Required by the `login` extension
         """
         unread_count = db.session.query(db.func.count(PrivateMessage.id)).\
             filter(PrivateMessage.unread,
-                   PrivateMessage.user_id == id).subquery()
-        u = db.session.query(User, unread_count).filter(User.id == id).first()
+                   PrivateMessage.user_id == user_id).subquery()
+        u = db.session.query(User, unread_count).filter(User.id == user_id).\
+            first()
 
         if u:
             user, user.pm_unread = u