import datetime
import django.db.models.deletion
from django.conf import settings
+import django.core.files.storage
import dvcs.models
-import dvcs.storage
class Migration(migrations.Migration):
('description', models.TextField(default=b'', verbose_name='description', blank=True)),
('created_at', models.DateTimeField(default=datetime.datetime.now, editable=False, db_index=True)),
('publishable', models.BooleanField(default=False, verbose_name='publishable')),
- ('data', models.FileField(upload_to=dvcs.models.data_upload_to, storage=dvcs.storage.GzipFileSystemStorage(location=settings.CATALOGUE_REPO_PATH), verbose_name='data')),
+ ('data', models.FileField(upload_to=dvcs.models.data_upload_to, storage=django.core.files.storage.FileSystemStorage(location=settings.CATALOGUE_REPO_PATH), verbose_name='data')),
('author', models.ForeignKey(verbose_name='author', blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE)),
('merge_parent', models.ForeignKey(related_name='merge_children', default=None, blank=True, to='catalogue.ChunkChange', null=True, verbose_name='merge parent', on_delete=models.CASCADE)),
('parent', models.ForeignKey(related_name='children', default=None, blank=True, to='catalogue.ChunkChange', null=True, verbose_name='parent', on_delete=models.CASCADE)),
('description', models.TextField(default=b'', verbose_name='description', blank=True)),
('created_at', models.DateTimeField(default=datetime.datetime.now, editable=False, db_index=True)),
('publishable', models.BooleanField(default=False, verbose_name='publishable')),
- ('data', models.FileField(upload_to=dvcs.models.data_upload_to, storage=dvcs.storage.GzipFileSystemStorage(location=settings.CATALOGUE_IMAGE_REPO_PATH), verbose_name='data')),
+ ('data', models.FileField(upload_to=dvcs.models.data_upload_to, storage=django.core.files.storage.FileSystemStorage(location=settings.CATALOGUE_IMAGE_REPO_PATH), verbose_name='data')),
('author', models.ForeignKey(verbose_name='author', blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE)),
('merge_parent', models.ForeignKey(related_name='merge_children', default=None, blank=True, to='catalogue.ImageChange', null=True, verbose_name='merge parent', on_delete=models.CASCADE)),
('parent', models.ForeignKey(related_name='children', default=None, blank=True, to='catalogue.ImageChange', null=True, verbose_name='parent', on_delete=models.CASCADE)),
#
from datetime import datetime
import os.path
+from zlib import compress, decompress
from django.contrib.auth.models import User
from django.core.files.base import ContentFile
+from django.core.files.storage import FileSystemStorage
from django.db import models, transaction
from django.db.models.base import ModelBase
from django.utils.text import format_lazy
from django.conf import settings
from dvcs.signals import post_commit, post_publishable
-from dvcs.storage import GzipFileSystemStorage
class Tag(models.Model):
self.revision = tree_rev + 1
return super(Change, self).save(*args, **kwargs)
+ def save_text(self, text, **kwargs):
+ self.data.save(
+ '',
+ ContentFile(compress(text.encode('utf-8'))),
+ **kwargs
+ )
+
def materialize(self):
- f = self.data.storage.open(self.data.name)
- text = f.read()
- f.close()
- return str(text, 'utf-8')
+ with self.data.open('rb') as f:
+ content = f.read()
+ return decompress(content).decode('utf-8')
def merge_with(self, other, author=None,
author_name=None, author_email=None,
author_name=author_name,
author_email=author_email,
description=description)
- merge_node.data.save('', ContentFile(result))
+ merge_node.save_text(result)
return merge_node
def revert(self, **kwargs):
def create_change_model(model):
name = model.__name__ + 'Change'
- repo = GzipFileSystemStorage(location=model.REPO_PATH)
+ repo = FileSystemStorage(location=model.REPO_PATH)
class Meta(Change.Meta):
app_label = model._meta.app_label
description=kwargs.get('description', ''), publishable=publishable, parent=parent)
change.tags.set(tags)
- change.data.save('', ContentFile(text.encode('utf-8')))
+ change.save_text(text)
change.save()
if self.head:
+++ /dev/null
-# This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
-#
-from zlib import compress, decompress
-
-from django.core.files.base import ContentFile, File
-from django.core.files.storage import FileSystemStorage
-from django.utils.deconstruct import deconstructible
-from django.utils.encoding import force_bytes
-
-
-@deconstructible
-class GzipFileSystemStorage(FileSystemStorage):
- def _open(self, name, mode='rb'):
- """TODO: This is good for reading; what about writing?"""
- f = open(self.path(name), 'rb')
- text = f.read()
- f.close()
- return ContentFile(decompress(text))
-
- def _save(self, name, content):
- data = force_bytes(content.read())
- content = ContentFile(compress(data))
-
- return super(GzipFileSystemStorage, self)._save(name, content)
import datetime
import os.path
from django.conf import settings
+import django.core.files.storage
from django.db import migrations, models
import django.db.models.deletion
import dvcs.models
-import dvcs.storage
class Migration(migrations.Migration):
('description', models.TextField(blank=True, default=b'', verbose_name='description')),
('created_at', models.DateTimeField(db_index=True, default=datetime.datetime.now, editable=False)),
('publishable', models.BooleanField(default=False, verbose_name='publishable')),
- ('data', models.FileField(storage=dvcs.storage.GzipFileSystemStorage(location=os.path.join(settings.MEDIA_ROOT, 'dvcs')), upload_to=dvcs.models.data_upload_to, verbose_name='data')),
+ ('data', models.FileField(storage=django.core.files.storage.FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT, 'dvcs')), upload_to=dvcs.models.data_upload_to, verbose_name='data')),
('author', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='author')),
('merge_parent', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='merge_children', to='tests.ADocumentChange', verbose_name='merge parent')),
('parent', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='tests.ADocumentChange', verbose_name='parent')),