예제 #1
0
def dummy_wagtail_doc(request):
    if not Collection.objects.exists():  # pragma: no cover
        Collection.add_root()

    doc = Document(title='hello')
    doc.file.save('foo.txt', ContentFile('foo', 'foo.txt'))
    doc.save()
    doc = Document.objects.get(pk=doc.pk)  # Reload to ensure the upload took

    def nuke():
        try:  # Try cleaning up so `/var/media` isn't full of foo
            doc.file.delete()
            doc.delete()
        except:  # pragma: no cover
            pass

    request.addfinalizer(nuke)
    return doc
예제 #2
0
def dummy_wagtail_doc(request):
    if not Collection.objects.exists():  # pragma: no cover
        Collection.add_root()

    doc = Document(title='hello')
    doc.file.save('foo.txt', ContentFile('foo', 'foo.txt'))
    doc.save()
    doc = Document.objects.get(pk=doc.pk)  # Reload to ensure the upload took

    def nuke():
        try:  # Try cleaning up so `/var/media` isn't full of foo
            doc.file.delete()
            doc.delete()
        except:  # pragma: no cover
            pass

    request.addfinalizer(nuke)
    return doc
예제 #3
0
    def save(self, *args, **kwargs):
        ret = super().save(*args, **kwargs)

        update_fields = []
        if self.root_collection is None:
            obj = Collection(name=self.name)
            Collection.add_root(instance=obj)
            self.root_collection = obj
            update_fields.append('root_collection')

        if self.admin_group is None:
            obj = Group.objects.create(name='%s admins' % self.name)
            self.admin_group = obj
            update_fields.append('admin_group')

        if self.contact_person_group is None:
            obj = Group.objects.create(name='%s contact persons' % self.name)
            self.contact_person_group = obj
            update_fields.append('contact_person_group')

        if update_fields:
            super().save(update_fields=update_fields)
        return ret