Example #1
0
    def post(self, request, *args, **kwargs):
        document = self.get_document()

        stars = document.get_stars()

        if request.user.pk in stars:
            stars.remove(request.user.pk)
        else:
            stars.append(request.user.pk)

        resource = DocumentResource()
        resource.obj_update(bundle=resource.build_bundle(data={
            "stars": stars,
            "star_count": len(stars)
        }), pk=document.pk)

        return super(StarDocumentView, self).post(request, *args, **kwargs)
Example #2
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)
Example #3
0
    def post(self, request, *args, **kwargs):
        document = self.get_document()

        stars = document.get_stars()

        if request.user.pk in stars:
            stars.remove(request.user.pk)
        else:
            stars.append(request.user.pk)

        resource = DocumentResource()
        resource.obj_update(
            bundle=resource.build_bundle(data={
                "stars": stars,
                "star_count": len(stars)
            }),
            pk=document.pk)

        return super(StarDocumentView, self).post(request, *args, **kwargs)
Example #4
0
    def form_valid(self, form, **kwargs):
        resource = DocumentResource()
        document = self.get_document()

        self.object_id = Document.objects.collection.insert({
            "title": form.cleaned_data.get("title"),
            "user_id": self.request.user.pk,
            "entities": document.entities,
            "fork_of": document.pk,
            "date_created": datetime.now(),
            "is_public": document.is_public,
            "_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)

        fork_done.send(sender=self,
            instance=Document.objects.get(_id=ObjectId(self.object_id)))

        return super(NewDocumentView, self).form_valid(form)
Example #5
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)