Anonymous avatar Anonymous committed a281bab

adding missing files

Comments (0)

Files changed (8)

 production_settings.py
 
 dist
+build
 docs/output
 
 _uploads

gunicorn-deploy.py

+# Production WSGI configuration
+
+import production_settings
+
+from newsmeme import create_app
+
+app = create_app(production_settings)
+
+5151

newsmeme/forms/account.py

     
     remember = BooleanField(_("Remember me"))
     
-    login = TextField(_("Username or email address"), validators=[
-                      required(message=\
-                               _("You must provide an email or username"))])
+    login = TextField(
+        _("Username or email address"), 
+        validators=[
+            required(
+                message=_("You must provide an email or username")
+            )
+        ]
+    )
 
     password = PasswordField(_("Password"))
 

newsmeme/models/base.py

+from mongoengine import QuerySet, DoesNotExist, MultipleObjectsReturned
+from flaskext.sqlalchemy import Pagination
+
+class BaseQuerySet(QuerySet):
+    """
+    Custom QuerySet with some handy extra methods. Use this or 
+    subclass of this with models:
+
+    class MyClass(Document):
+        ...
+        meta = {'queryset_class' : BaseQuerySet})
+    """
+
+    def get_or_404(self, **kwargs):
+        try:
+            return self.get(**kwargs)
+        except (DoesNotExist, MultipleObjectsReturned):
+            abort(404)
+
+    def first_or_404(self, **kwargs):
+        result = self.first()
+        if result is None:
+            abort(404)
+
+    def paginate(self, page, per_page=20, error_out=True):
+        """Returns `per_page` items from page `page`.  By default it will
+        abort with 404 if no items were found and the page was larger than
+        1.  This behavor can be disabled by setting `error_out` to `False`.
+
+        Returns an :class:`Pagination` object.
+        """
+        if error_out and page < 1:
+            abort(404)
+        items = self.limit(per_page).skip((page - 1) * per_page).all()
+        if not items and page != 1 and error_out:
+            abort(404)
+        return Pagination(self, page, per_page, self.count(), items)

newsmeme/models/permissions.py

+class Permissions(object):
+
+    def __init__(self, obj):
+        self.obj = obj
+
+    def __getattr__(self, name):
+        return getattr(self.obj, name)
+
+from mongoengine import *
+from mongoengine.queryset import QuerySet, DoesNotExist, queryset_manager
+from pymongo.objectid import ObjectId
+
+from flask import abort
+
+connect("newsmeme-dev")
+
+class Paginator(object):
+
+    def paginate(self, queryset):
+        return []
+
+
+"""
+page_obj = paginate(Post.objects.public(),
+                    page,
+                    Post.PER_PAGE)
+
+post = get_or_404(Post.objects.public(), id=1)
+
+"""
+
+class SomeQuerySet(QuerySet):
+
+    def get_or_404(self, **kwargs):
+        try:
+            return self.get(**kwargs)
+        except DoesNotExist:
+            abort(404)
+
+    def paginate(self, page, page_size):
+        return []
+
+    def restricted(self):
+        return self.filter(access=Post.PUBLIC)
+
+    def popular(self):
+        return self.filter(access=Post.PUBLIC)
+
+class Post(Document):
+
+    PUBLIC = 100
+    PRIVATE = 200
+
+    title = StringField()
+    description = StringField()
+    access = IntField(default=PUBLIC)
+
+    meta  = {'queryset_class' : SomeQuerySet}
+
+    @queryset_manager
+    def public(cls, queryset):
+        return queryset.filter(access=cls.PUBLIC)
+
+post = Post.objects.restricted().get_or_404(id=ObjectId("4d0642b42f54ae12b0000000"))
+print post.title
+
+#post = Post.objects.get_or_404(id=ObjectId("4d0642b42f54ae12b0000001"))
+post = Post.objects.popular().restricted().with_id("4d0642b42f54ae12b0000000")
+print post.title
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.