Exemple #1
0
 def test_create_document_already_exists(self):
     """ Adding a document that is already in a collection we want to add it to """
     self.assertEqual(1, self.coll.documents.count())
     docuuid = self.doc.external_identifier
     util.docserver_create_document(self.coll.collectionid, docuuid,
                                    "some title")
     self.assertEqual(1, self.coll.documents.count())
Exemple #2
0
    def test_create_document_other_collection(self):
        """ A document that already exists in a different collection """
        u = str(uuid.uuid4())
        root = "/other/root/directory"
        othercoll = models.Collection.objects.create(collectionid=u, name='second collection',
                slug='second-collection', description='', root_directory=root)

        docuuid = self.doc.external_identifier
        util.docserver_create_document(u, docuuid, "some title")
        self.assertEqual(1, self.coll.documents.count())
        self.assertEqual(1, othercoll.documents.count())
        self.assertEqual(2, self.doc.collections.count())
Exemple #3
0
    def test_create_document_other_collection(self):
        """ A document that already exists in a different collection """
        u = str(uuid.uuid4())
        root = "/other/root/directory"
        othercoll = models.Collection.objects.create(collectionid=u,
                                                     name='second collection',
                                                     slug='second-collection',
                                                     description='',
                                                     root_directory=root)

        docuuid = self.doc.external_identifier
        util.docserver_create_document(u, docuuid, "some title")
        self.assertEqual(1, self.coll.documents.count())
        self.assertEqual(1, othercoll.documents.count())
        self.assertEqual(2, self.doc.collections.count())
Exemple #4
0
def edit_item(request, item_id, cat_id):
    message = ""
    item = Item.objects.get(ref=item_id, category__id=cat_id)
    FieldSet = inlineformset_factory(Item, Field, form=FieldForm, fields=('key','value','modified'), can_delete=False, extra=0)
    if request.method == 'POST':
        item_form = ItemForm(request.POST, instance=item)
        form = FieldSet(request.POST, instance = item)
        if item_form.is_valid() and form.is_valid():
            item_form.save()
            form.save()
            # Re-make the form with the item from the database so
            # that `modified` is set if it was changed
            item = Item.objects.get(ref=item_id, category__id=cat_id)
            form = FieldSet(instance=item)
            item_form = ItemForm(instance=item)
            message = "Item successfully saved."
            if item.verified and item.category.source_file_type and item.category.collection:
                if item.fields.filter(key="name").exists():
                    name = item.fields.get(key="name").value
                else:
                    name = item.ref
                document = docserver_create_document(item.category.collection.collectionid,
                                                     item.ref,
                                                     name)
                docserver_upload_and_save_file(document.id,
                                               item.category.source_file_type.id,
                                               ContentFile(item.to_json()))
                message += " SourceFile uploaded."
    else:
        item_form = ItemForm(instance=item)
        form = FieldSet(instance = item)
    return render(request, 'kvedit/edit.html', {'item_form':item_form, 'form': form, 'item': item, "message": message})
Exemple #5
0
    def test_create_document(self):
        """ A document that doesn't exist """
        self.assertEqual(1, models.Document.objects.count())

        u = str(uuid.uuid4())
        doc = util.docserver_create_document(self.coll.collectionid, u, "some title")
        self.assertEqual(2, models.Document.objects.count())
        self.assertEqual(u, doc.external_identifier)
        self.assertEqual("some title", doc.title)
Exemple #6
0
    def test_create_document(self):
        """ A document that doesn't exist """
        self.assertEqual(1, models.Document.objects.count())

        u = str(uuid.uuid4())
        doc = util.docserver_create_document(self.coll.collectionid, u,
                                             "some title")
        self.assertEqual(2, models.Document.objects.count())
        self.assertEqual(u, doc.external_identifier)
        self.assertEqual("some title", doc.title)
Exemple #7
0
    def create(self, request, external_identifier):
        title = request.data.get("title", None)
        slug = request.data.get("collection", None)

        if not slug:
            raise Exception("Slug not present in request")

        collection = get_object_or_404(models.Collection.objects, slug=slug)
        doc = util.docserver_create_document(collection.collectionid, external_identifier, title)
        serialized = serializers.DocumentSerializer(doc)
        return response.Response(serialized.data, status=status.HTTP_201_CREATED)
Exemple #8
0
    def create(self, request, external_identifier):
        title = request.data.get("title", None)
        slug = request.data.get("collection", None)

        if not slug:
            raise Exception("Slug not present in request")

        collection = get_object_or_404(models.Collection.objects, slug=slug)
        doc = util.docserver_create_document(collection.collectionid, external_identifier, title)
        serialized = serializers.DocumentSerializer(doc)
        return response.Response(serialized.data, status=status.HTTP_201_CREATED)
Exemple #9
0
    def create(self, request, external_identifier):
        title = request.data.get("title", None)
        slug = request.data.get("collection", None)

        if not slug:
            raise ValidationError("Slug not present in request")

        try:
            collection = models.Collection.objects.get(slug=slug)
        except models.Collection.DoesNotExist:
            raise Http404("Invalid collection slug")
        doc = util.docserver_create_document(collection.collectionid,
                                             external_identifier, title)
        serialized = serializers.DocumentSerializer(doc)
        return response.Response(serialized.data,
                                 status=status.HTTP_201_CREATED)
Exemple #10
0
def edit_item(request, item_id, cat_id):
    message = ""
    item = Item.objects.get(ref=item_id, category__id=cat_id)
    FieldSet = inlineformset_factory(Item,
                                     Field,
                                     form=FieldForm,
                                     fields=('key', 'value', 'modified'),
                                     can_delete=False,
                                     extra=0)
    if request.method == 'POST':
        item_form = ItemForm(request.POST, instance=item)
        form = FieldSet(request.POST, instance=item)
        if item_form.is_valid() and form.is_valid():
            item_form.save()
            form.save()
            # Re-make the form with the item from the database so
            # that `modified` is set if it was changed
            item = Item.objects.get(ref=item_id, category__id=cat_id)
            form = FieldSet(instance=item)
            item_form = ItemForm(instance=item)
            message = "Item successfully saved."
            if item.verified and item.category.source_file_type and item.category.collection:
                if item.fields.filter(key="name").exists():
                    name = item.fields.get(key="name").value
                else:
                    name = item.ref
                document = docserver_create_document(
                    item.category.collection.collectionid, item.ref, name)
                docserver_upload_and_save_file(
                    document.id, item.category.source_file_type.id,
                    ContentFile(item.to_json()))
                message += " SourceFile uploaded."
    else:
        item_form = ItemForm(instance=item)
        form = FieldSet(instance=item)
    return render(request, 'kvedit/edit.html', {
        'item_form': item_form,
        'form': form,
        'item': item,
        "message": message
    })
Exemple #11
0
 def test_create_document_already_exists(self):
     """ Adding a document that is already in a collection we want to add it to """
     self.assertEqual(1, self.coll.documents.count())
     docuuid = self.doc.external_identifier
     util.docserver_create_document(self.coll.collectionid, docuuid, "some title")
     self.assertEqual(1, self.coll.documents.count())