Beispiel #1
0
    def form_valid(self, form, **kwargs):
        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"))
        })

        Document.objects.collection.update({'_id': ObjectId(document.pk)},
                                           {"$inc": {
                                               'fork_count': 1
                                           }})

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

        return super(NewDocumentView, self).form_valid(form)
Beispiel #2
0
    def form_valid(self, form, **kwargs):
        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"))
        })

        Document.objects.collection.update(
            {'_id': ObjectId(document.pk)},
            {"$inc": {'fork_count': 1}})

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

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