Rename Snapshot to Revision

master
Tom Hacohen 5 years ago
parent 052483d38c
commit cc00391504

@ -0,0 +1,17 @@
# Generated by Django 3.0.3 on 2020-02-20 20:37
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('django_etesync', '0010_auto_20200220_1248'),
]
operations = [
migrations.RenameModel(
old_name='CollectionItemSnapshot',
new_name='CollectionItemRevision',
),
]

@ -0,0 +1,19 @@
# Generated by Django 3.0.3 on 2020-02-20 20:38
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('django_etesync', '0011_auto_20200220_2037'),
]
operations = [
migrations.AlterField(
model_name='collectionitemrevision',
name='item',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='revisions', to='django_etesync.CollectionItem'),
),
]

@ -50,7 +50,7 @@ class CollectionItem(models.Model):
@cached_property
def content(self):
return self.snapshots.get(current=True)
return self.revisions.get(current=True)
def chunk_directory_path(instance, filename):
@ -75,10 +75,10 @@ class CollectionItemChunk(models.Model):
return self.uid
class CollectionItemSnapshot(models.Model):
class CollectionItemRevision(models.Model):
version = models.PositiveSmallIntegerField()
encryptionKey = models.BinaryField(editable=True, blank=False, null=False)
item = models.ForeignKey(CollectionItem, related_name='snapshots', on_delete=models.CASCADE)
item = models.ForeignKey(CollectionItem, related_name='revisions', on_delete=models.CASCADE)
chunks = models.ManyToManyField(CollectionItemChunk, related_name='items')
hmac = models.CharField(max_length=50, blank=False, null=False)
current = models.BooleanField(db_index=True, default=True)

@ -64,7 +64,7 @@ class CollectionItemChunkSerializer(serializers.ModelSerializer):
fields = ('uid', 'chunkFile')
class CollectionItemSnapshotBaseSerializer(serializers.ModelSerializer):
class CollectionItemRevisionBaseSerializer(serializers.ModelSerializer):
encryptionKey = BinaryBase64Field()
chunks = serializers.SlugRelatedField(
slug_field='uid',
@ -73,15 +73,15 @@ class CollectionItemSnapshotBaseSerializer(serializers.ModelSerializer):
)
class Meta:
model = models.CollectionItemSnapshot
model = models.CollectionItemRevision
fields = ('version', 'encryptionKey', 'chunks', 'hmac')
class CollectionItemSnapshotSerializer(CollectionItemSnapshotBaseSerializer):
class CollectionItemRevisionSerializer(CollectionItemRevisionBaseSerializer):
chunksUrls = serializers.SerializerMethodField('get_chunks_urls')
class Meta(CollectionItemSnapshotBaseSerializer.Meta):
fields = CollectionItemSnapshotBaseSerializer.Meta.fields + ('chunksUrls', )
class Meta(CollectionItemRevisionBaseSerializer.Meta):
fields = CollectionItemRevisionBaseSerializer.Meta.fields + ('chunksUrls', )
# FIXME: currently the user is exposed in the url. We don't want that, and we can probably avoid that but still save it under the user.
# We would probably be better off just let the user calculate the urls from the uid and a base url for the snapshot.
@ -94,11 +94,11 @@ class CollectionItemSnapshotSerializer(CollectionItemSnapshotBaseSerializer):
return ret
class CollectionItemSnapshotInlineSerializer(CollectionItemSnapshotBaseSerializer):
class CollectionItemRevisionInlineSerializer(CollectionItemRevisionBaseSerializer):
chunksData = serializers.SerializerMethodField('get_chunks_data')
class Meta(CollectionItemSnapshotBaseSerializer.Meta):
fields = CollectionItemSnapshotBaseSerializer.Meta.fields + ('chunksData', )
class Meta(CollectionItemRevisionBaseSerializer.Meta):
fields = CollectionItemRevisionBaseSerializer.Meta.fields + ('chunksData', )
def get_chunks_data(self, obj):
ret = []
@ -109,7 +109,7 @@ class CollectionItemSnapshotInlineSerializer(CollectionItemSnapshotBaseSerialize
return ret
class CollectionItemSerializer(serializers.ModelSerializer):
content = CollectionItemSnapshotSerializer(read_only=True, many=False)
content = CollectionItemRevisionSerializer(read_only=True, many=False)
class Meta:
model = models.CollectionItem
@ -117,4 +117,4 @@ class CollectionItemSerializer(serializers.ModelSerializer):
class CollectionItemInlineSerializer(CollectionItemSerializer):
content = CollectionItemSnapshotInlineSerializer(read_only=True, many=False)
content = CollectionItemRevisionInlineSerializer(read_only=True, many=False)

@ -34,8 +34,8 @@ from .serializers import (
CollectionSerializer,
CollectionItemSerializer,
CollectionItemInlineSerializer,
CollectionItemSnapshotSerializer,
CollectionItemSnapshotInlineSerializer,
CollectionItemRevisionSerializer,
CollectionItemRevisionInlineSerializer,
CollectionItemChunkSerializer
)
@ -115,7 +115,7 @@ class CollectionItemViewSet(BaseViewSet):
collection = self.get_collection_queryset(Collection.objects).get(uid=collection_uid)
except Collection.DoesNotExist:
raise Http404("Collection does not exist")
# XXX Potentially add this for performance: .prefetch_related('snapshots__chunks')
# XXX Potentially add this for performance: .prefetch_related('revisions__chunks')
queryset = type(self).queryset.filter(collection__pk=collection.pk)
return queryset
@ -149,11 +149,11 @@ class CollectionItemViewSet(BaseViewSet):
return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
@action_decorator(detail=True, methods=['GET'])
def snapshots(self, request, collection_uid=None, uid=None):
def revision(self, request, collection_uid=None, uid=None):
col = get_object_or_404(Collection.objects, uid=collection_uid)
col_it = get_object_or_404(col.items, uid=uid)
serializer = CollectionItemSnapshotSerializer(col_it.snapshots.order_by('-id'), many=True)
serializer = CollectionItemRevisionSerializer(col_it.revisions.order_by('-id'), many=True)
return Response(serializer.data)

Loading…
Cancel
Save