コード例 #1
0
    def handle(self, *args, **options):

        newsfeed = get_collection("newsfeed")

        newsfeed.ensure_index([
            ("recipients", DESCENDING),
            ("date_created", DESCENDING),
        ])

        newsfeed.remove()

        for user in User.objects.all():
            newsfeed.insert({
                "object_id": user.id,
                "news_type": NEWS_TYPE_REGISTRATION,
                "date_created": user.date_joined,
                "recipients": [],
                "sender": {
                    "username": user.username,
                    "email": user.email # it's required for gravatar
                },
            })


        for document in map(Document, get_collection("documents").find()):
            news_type = NEWS_TYPE_DOCUMENT if document.fork_of else NEWS_TYPE_FORK
            newsfeed.insert({
                "object_id": document.pk,
                "news_type": news_type,
                "date_created": document.date_created,
                "recipients": [],
                "sender": {
                    "username": document.user.username,
                    "email": document.user.email # it's required for gravatar
                },
            })

        for comment in map(Comment, get_collection("comments").find()):
            newsfeed.insert({
                "object_id": comment.pk,
                "news_type": NEWS_TYPE_COMMENT,
                "date_created": comment.date_created,
                "recipients": [],
                "sender": {
                    "username": comment.user.username,
                    "email": comment.user.email # it's required for gravatar
                },
            })

        print get_collection("newsfeed").count()
コード例 #2
0
    def handle(self, *args, **options):

        newsfeed = get_collection("newsfeed")

        newsfeed.ensure_index([
            ("recipients", DESCENDING),
            ("date_created", DESCENDING),
        ])

        newsfeed.remove()

        for user in User.objects.all():
            newsfeed.insert({
                "object_id": user.id,
                "news_type": NEWS_TYPE_REGISTRATION,
                "date_created": user.date_joined,
                "recipients": [],
                "sender": {
                    "username": user.username,
                    "email": user.email  # it's required for gravatar
                },
            })

        for document in map(Document, get_collection("documents").find()):
            news_type = NEWS_TYPE_DOCUMENT if document.fork_of else NEWS_TYPE_FORK
            newsfeed.insert({
                "object_id": document.pk,
                "news_type": news_type,
                "date_created": document.date_created,
                "recipients": [],
                "sender": {
                    "username": document.user.username,
                    "email": document.user.email  # it's required for gravatar
                },
            })

        for comment in map(Comment, get_collection("comments").find()):
            newsfeed.insert({
                "object_id": comment.pk,
                "news_type": NEWS_TYPE_COMMENT,
                "date_created": comment.date_created,
                "recipients": [],
                "sender": {
                    "username": comment.user.username,
                    "email": comment.user.email  # it's required for gravatar
                },
            })

        print get_collection("newsfeed").count()
コード例 #3
0
ファイル: views.py プロジェクト: pombredanne/dbpatterns
    def get_context_data(self, **kwargs):
        documents = get_collection("documents")

        documents.ensure_index([
            ("featured", 1),
            ("star_count", 1)
        ])

        featured_documents = imap(Document, documents.find({
           "featured": True
        }).sort([("date_created", -1)]).limit(9))

        most_rated_documents = imap(Document,
            documents.find().sort([("star_count", -1)]).limit(9))

        recently_added_documents = imap(Document, documents.find({
            "$where": "this.entities && this.entities.length > 1"
        }).sort([("date_created", -1)]).limit(9))

        return {
            "featured_documents": featured_documents,
            "most_rated_documents": most_rated_documents,
            "recently_added_documents": recently_added_documents,
            "search_form": SearchForm()
        }
コード例 #4
0
    def handle(self, *args, **options):

        get_collection("documents").ensure_index([
                ("_keywords", 1),
                ("title", 1),
            ])

        for document in get_collection("documents").find():

            print document.get("_id")

            get_collection("documents").update({
                "_id": document.get("_id")
            }, {
                "$set": {
                    "_keywords": extract_keywords(document.get("title"))
                }
            })
コード例 #5
0
ファイル: views.py プロジェクト: pombredanne/dbpatterns
 def form_valid(self, form, **kwargs):
     self.object_id = get_collection("documents").insert({
         "title": form.cleaned_data.get("title"),
         "user_id": self.request.user.pk,
         "date_created": datetime.now(),
         "entities": form.cleaned_data.get("entities"),
         "_keywords": extract_keywords(form.cleaned_data.get("title"))
     })
     return super(NewDocumentView, self).form_valid(form)
コード例 #6
0
ファイル: views.py プロジェクト: haoshuji/dbpatterns
 def form_valid(self, form, **kwargs):
     self.object_id = get_collection("documents").insert({
         "title":
         form.cleaned_data.get("title"),
         "user_id":
         self.request.user.pk,
         "date_created":
         datetime.now(),
         "entities":
         form.cleaned_data.get("entities"),
         "_keywords":
         extract_keywords(form.cleaned_data.get("title"))
     })
     return super(NewDocumentView, self).form_valid(form)
コード例 #7
0
ファイル: views.py プロジェクト: haoshuji/dbpatterns
    def get_queryset(self):

        form = self.get_form()

        if not form.is_valid():
            return []

        keyword = form.cleaned_data.get("keyword")

        collection = get_collection("documents").find(
            {"_keywords": {
                "$all": keyword.split()
            }})

        return map(Document, collection)
コード例 #8
0
ファイル: views.py プロジェクト: haoshuji/dbpatterns
 def get_context_data(self, **kwargs):
     documents = get_collection("documents")
     most_rated_documents = map(
         Document,
         documents.find().sort([("star_count", -1)]).limit(9))
     recently_added_documents = map(
         Document,
         documents.find({
             "$where":
             "this.entities && this.entities.length > 1"
         }).sort([("date_created", -1)]).limit(9))
     return {
         "most_rated_documents": most_rated_documents,
         "recently_added_documents": recently_added_documents,
         "search_form": SearchForm()
     }
コード例 #9
0
def notifications(request):
    """
    Returns unread notification count
    """

    if request.user.is_anonymous():
        notification_count = 0
    else:
        notification_count = get_collection("notifications").find({
            "recipient":
            request.user.id,
            "is_read":
            False
        }).count()

    return {"notification_count": notification_count}
コード例 #10
0
ファイル: views.py プロジェクト: pombredanne/dbpatterns
    def get_queryset(self):

        form = self.get_form()

        if not form.is_valid():
            return []

        keyword = form.cleaned_data.get("keyword")

        collection = get_collection("documents").find({
            "_keywords": {
                "$all": keyword.split()
            }
        })

        return map(Document, collection)
コード例 #11
0
def notifications(request):
    """
    Returns unread notification count
    """

    if request.user.is_anonymous():
        notification_count = 0
    else:
        notification_count = get_collection("notifications").find({
            "recipient": request.user.id,
            "is_read": False
        }).count()

    return {
        "notification_count": notification_count
    }
コード例 #12
0
ファイル: views.py プロジェクト: fatihzkaratana/dbpatterns
    def form_valid(self, form, **kwargs):
        resource = DocumentResource()
        document = self.get_document()
        self.object_id = get_collection("documents").insert({
            "title": form.cleaned_data.get("title"),
            "user_id": self.request.user.pk,
            "entities": document.entities,
            "fork_of": document.pk,
            "date_created": datetime.now()
        })

        # TODO: use atomic operations for incrementing!
        resource.obj_update(bundle=resource.build_bundle(data={
            "fork_count": (document.fork_count or 0) + 1
        }), pk=document.pk)

        return super(NewDocumentView, self).form_valid(form)
コード例 #13
0
ファイル: resources.py プロジェクト: feber007/dbpatterns
def comment_on(sender, comment_id, **kwargs):

    comment = Comment(get_collection("comments").find_one({
        "_id": ObjectId(comment_id)
    }))

    document = comment.document

    send_mail(
        subject = "You have new comment(s) on your pattern",
        message = COMMENT_TEMPLATE % {
            "document_title": document.title,
            "document_link": settings.SITE_URL + document.get_absolute_url()
        },
        from_email = settings.COMMENTS_FROM_EMAIL,
        recipient_list = ['"%s" <%s>' % (
            document.user.get_full_name() or document.user.username, document.user.email)],
        fail_silently = True
    )
コード例 #14
0
ファイル: resources.py プロジェクト: haoshuji/dbpatterns
def comment_on(sender, comment_id, **kwargs):

    comment = Comment(
        get_collection("comments").find_one({"_id": ObjectId(comment_id)}))

    document = comment.document

    send_mail(
        subject="You have new comment(s) on your pattern",
        message=COMMENT_TEMPLATE % {
            "document_title": document.title,
            "document_link": settings.SITE_URL + document.get_absolute_url()
        },
        from_email=settings.COMMENTS_FROM_EMAIL,
        recipient_list=[
            '"%s" <%s>' % (document.user.get_full_name()
                           or document.user.username, document.user.email)
        ],
        fail_silently=True)
コード例 #15
0
ファイル: views.py プロジェクト: haoshuji/dbpatterns
    def form_valid(self, form, **kwargs):
        resource = DocumentResource()
        document = self.get_document()
        self.object_id = get_collection("documents").insert({
            "title":
            form.cleaned_data.get("title"),
            "user_id":
            self.request.user.pk,
            "entities":
            document.entities,
            "fork_of":
            document.pk,
            "date_created":
            datetime.now(),
            "_keywords":
            extract_keywords(form.cleaned_data.get("title"))
        })

        # TODO: use atomic operations for incrementing!
        resource.obj_update(bundle=resource.build_bundle(
            data={"fork_count": (document.fork_count or 0) + 1}),
                            pk=document.pk)

        return super(NewDocumentView, self).form_valid(form)
コード例 #16
0
ファイル: resources.py プロジェクト: haoshuji/dbpatterns
 def get_collection(self):
     return get_collection("comments")
コード例 #17
0
ファイル: models.py プロジェクト: feber007/dbpatterns
 def comment_count(self):
     return get_collection("comments").find({
         "document_id": self.pk
     }).count()
コード例 #18
0
ファイル: models.py プロジェクト: feber007/dbpatterns
 def forks(self):
     return map(self.__class__, get_collection("documents").find({
         "fork_of": self.pk
     }))
コード例 #19
0
ファイル: resources.py プロジェクト: thedangler/dbpatterns
 def get_collection(self):
     return get_collection("documents")
コード例 #20
0
ファイル: models.py プロジェクト: msurguy/dbpatterns
 def load(self):
     self.collection = get_collection("documents")
     self.collection.ensure_index([
         ("date_created", DESCENDING),
     ])
コード例 #21
0
ファイル: resources.py プロジェクト: fatiherikli/dbpatterns
 def get_collection(self):
     return get_collection("comments")
コード例 #22
0
ファイル: resources.py プロジェクト: haoshuji/dbpatterns
 def get_collection(self):
     return get_collection("documents")
コード例 #23
0
ファイル: views.py プロジェクト: haoshuji/dbpatterns
 def get_queryset(self):
     collection = get_collection("documents").find(
         {"user_id": self.request.user.pk})
     return map(Document, collection)
コード例 #24
0
ファイル: models.py プロジェクト: haoshuji/dbpatterns
 def document(self):
     return Document(
         get_collection("documents").find_one(
             {"_id": ObjectId(self.document_id)}))
コード例 #25
0
 def forks(self):
     """Returns forks of document"""
     forks = get_collection("documents").find({"fork_of": self.pk})
     return map(Document, forks)
コード例 #26
0
ファイル: models.py プロジェクト: ArRolin/dbpatterns
 def load(self):
     self.collection = get_collection("notifications")
     self.collection.ensure_index([
         ("date_created", DESCENDING),
     ])
コード例 #27
0
 def comment_count(self):
     return get_collection("comments").find({
         "document_id": self.pk
     }).count()
コード例 #28
0
 def document(self):
     """Returns the document of comment"""
     query = {"_id": ObjectId(self.document_id)}
     return Document(get_collection("documents").find_one(query))
コード例 #29
0
ファイル: models.py プロジェクト: msurguy/dbpatterns
 def document(self):
     return Document(get_collection("documents").find_one({
         "_id": ObjectId(self.document_id)
     }))
コード例 #30
0
 def get(self, **kwargs):
     return Comment(get_collection("comments").find_one(kwargs))
コード例 #31
0
ファイル: models.py プロジェクト: ArRolin/dbpatterns
 def load(self):
     self.collection = get_collection("newsfeed")
コード例 #32
0
 def forks(self):
     return map(self.__class__,
                get_collection("documents").find({"fork_of": self.pk}))
コード例 #33
0
 def comment_count(self):
     """Returns the comment count of document"""
     comments = get_collection("comments")
     return comments.find({"document_id": self.pk}).count()
コード例 #34
0
ファイル: views.py プロジェクト: fatihzkaratana/dbpatterns
 def get_queryset(self):
     resource = DocumentResource()
     collection = get_collection("documents").find({"user_id": self.request.user.pk})
     return map(Document, collection)
コード例 #35
0
 def load(self):
     """Reloads mongodb connection"""
     self.collection = get_collection("documents")
     self.collection.ensure_index([
         ("date_created", DESCENDING),
     ])
コード例 #36
0
 def load(self):
     self.collection = get_collection("notifications")
     self.collection.ensure_index([
         ("date_created", DESCENDING),
     ])
コード例 #37
0
 def load(self):
     self.collection = get_collection("newsfeed")