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()
    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()
Beispiel #3
0
    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()
        }
    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"))
                }
            })
Beispiel #5
0
 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)
Beispiel #6
0
 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)
Beispiel #7
0
    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)
Beispiel #8
0
 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()
     }
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}
Beispiel #10
0
    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)
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
    }
Beispiel #12
0
    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)
Beispiel #13
0
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
    )
Beispiel #14
0
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)
Beispiel #15
0
    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)
Beispiel #16
0
 def get_collection(self):
     return get_collection("comments")
Beispiel #17
0
 def comment_count(self):
     return get_collection("comments").find({
         "document_id": self.pk
     }).count()
Beispiel #18
0
 def forks(self):
     return map(self.__class__, get_collection("documents").find({
         "fork_of": self.pk
     }))
Beispiel #19
0
 def get_collection(self):
     return get_collection("documents")
Beispiel #20
0
 def load(self):
     self.collection = get_collection("documents")
     self.collection.ensure_index([
         ("date_created", DESCENDING),
     ])
Beispiel #21
0
 def get_collection(self):
     return get_collection("comments")
Beispiel #22
0
 def get_collection(self):
     return get_collection("documents")
Beispiel #23
0
 def get_queryset(self):
     collection = get_collection("documents").find(
         {"user_id": self.request.user.pk})
     return map(Document, collection)
Beispiel #24
0
 def document(self):
     return Document(
         get_collection("documents").find_one(
             {"_id": ObjectId(self.document_id)}))
Beispiel #25
0
 def forks(self):
     """Returns forks of document"""
     forks = get_collection("documents").find({"fork_of": self.pk})
     return map(Document, forks)
Beispiel #26
0
 def load(self):
     self.collection = get_collection("notifications")
     self.collection.ensure_index([
         ("date_created", DESCENDING),
     ])
Beispiel #27
0
 def comment_count(self):
     return get_collection("comments").find({
         "document_id": self.pk
     }).count()
Beispiel #28
0
 def document(self):
     """Returns the document of comment"""
     query = {"_id": ObjectId(self.document_id)}
     return Document(get_collection("documents").find_one(query))
Beispiel #29
0
 def document(self):
     return Document(get_collection("documents").find_one({
         "_id": ObjectId(self.document_id)
     }))
Beispiel #30
0
 def get(self, **kwargs):
     return Comment(get_collection("comments").find_one(kwargs))
Beispiel #31
0
 def load(self):
     self.collection = get_collection("newsfeed")
Beispiel #32
0
 def forks(self):
     return map(self.__class__,
                get_collection("documents").find({"fork_of": self.pk}))
Beispiel #33
0
 def comment_count(self):
     """Returns the comment count of document"""
     comments = get_collection("comments")
     return comments.find({"document_id": self.pk}).count()
Beispiel #34
0
 def get_queryset(self):
     resource = DocumentResource()
     collection = get_collection("documents").find({"user_id": self.request.user.pk})
     return map(Document, collection)
Beispiel #35
0
 def load(self):
     """Reloads mongodb connection"""
     self.collection = get_collection("documents")
     self.collection.ensure_index([
         ("date_created", DESCENDING),
     ])
Beispiel #36
0
 def load(self):
     self.collection = get_collection("notifications")
     self.collection.ensure_index([
         ("date_created", DESCENDING),
     ])
Beispiel #37
0
 def load(self):
     self.collection = get_collection("newsfeed")