More progress.

This commit is contained in:
Tom Hacohen
2020-02-20 13:56:16 +02:00
parent 4075f775e7
commit 67fb714ddb
6 changed files with 197 additions and 27 deletions

View File

@@ -35,26 +35,6 @@ class Collection(models.Model):
def __str__(self):
return self.uid
@cached_property
def current_items(self):
return self.items.filter(current=True)
class CollectionItem(models.Model):
uid = models.CharField(db_index=True, blank=False, null=False,
max_length=44, validators=[UidValidator])
version = models.PositiveSmallIntegerField()
encryptionKey = models.BinaryField(editable=True, blank=False, null=False)
collection = models.ForeignKey(Collection, related_name='items', on_delete=models.CASCADE)
hmac = models.CharField(max_length=50, blank=False, null=False)
current = models.BooleanField(db_index=True, default=True)
class Meta:
unique_together = ('uid', 'collection')
def __str__(self):
return self.uid
def chunk_directory_path(instance, filename):
col = instance.itemSnapshot.item.collection
@@ -62,15 +42,49 @@ def chunk_directory_path(instance, filename):
return Path('user_{}'.format(user_id), col.uid, instance.uid)
class CollectionItem(models.Model):
uid = models.CharField(db_index=True, blank=False, null=False,
max_length=44, validators=[UidValidator])
collection = models.ForeignKey(Collection, related_name='items', on_delete=models.CASCADE)
class Meta:
unique_together = ('uid', 'collection')
def __str__(self):
return self.uid
@cached_property
def content(self):
return self.snapshots.get(current=True)
class CollectionItemChunk(models.Model):
uid = models.CharField(db_index=True, blank=False, null=False,
max_length=44, validators=[UidValidator])
items = models.ManyToManyField(CollectionItem, related_name='chunks')
item = models.ForeignKey(CollectionItem, related_name='chunks', on_delete=models.CASCADE)
order = models.CharField(max_length=100, blank=False, null=False)
# We probably just want to implement this manually because we can have more than one pointing to a file. chunkFile = models.FileField(upload_to=chunk_directory_path)
class Meta:
unique_together = ('item', 'order')
ordering = ['order']
def __str__(self):
return self.uid
class CollectionItemSnapshot(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)
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)
class Meta:
unique_together = ('item', 'current')
def __str__(self):
return '{} {} current={}'.format(self.item.uid, self.id, self.current)