Ejemplo n.º 1
0
 def copy_file(self, file_name, file_content):
     # copies a file field from a different value over to this value
     # this is tricky, because we need to trick django_cleanup to not delete the original file
     # important for snapshots and import from projects
     self.file.save(file_name, file_content, save=False)
     cleanup.refresh(self)
     self.save()
Ejemplo n.º 2
0
def test_refresh_from_db(pic1):
    product = Product.objects.create(image=pic1['filename'])
    assert os.path.exists(pic1['path'])
    product.refresh_from_db()
    cleanup.refresh(product)
    assert id(product.image.instance) == id(product)
    product.image = 'new.jpg'
    with transaction.atomic(get_using(product)):
        product.save()
    assert not os.path.exists(pic1['path'])
Ejemplo n.º 3
0
 def save(self, commit=True):
     instance = super(DocumentCreateUpdateForm, self).save(commit=False)
     instance.uploader = self.user
     instance.unique_identifier = self.unique_identifier
     if commit:
         instance.save()
         if instance.file and self.cleaned_data['delete_first_page']:
             tempfile = BytesIO()
             with instance.file as file:
                 pdf = Pdf.open(file)
                 del pdf.pages[0]
                 pdf.save(tempfile)
             file.save(file.name, tempfile)
             instance.update_page_number()
             cleanup.refresh(instance)
     return instance