fix:model-folder
This commit is contained in:
parent
1861bd9131
commit
face989118
18
src/documents/migrations/1055_folder_checksum.py
Normal file
18
src/documents/migrations/1055_folder_checksum.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.11 on 2024-06-12 02:10
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('documents', '1054_folder_document_folder_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='folder',
|
||||
name='checksum',
|
||||
field=models.CharField(editable=False, help_text='The checksum of the original folder.', max_length=32, null=True, unique=True, verbose_name='checksum'),
|
||||
),
|
||||
]
|
@ -156,6 +156,14 @@ class Warehouse(MatchingModel):
|
||||
class Folder(MatchingModel):
|
||||
parent_folder = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True )
|
||||
path = models.TextField(_("path"), null=True, blank=True)
|
||||
checksum = models.CharField(
|
||||
_("checksum"),
|
||||
max_length=32,
|
||||
editable=False,
|
||||
unique=True,
|
||||
null=True,
|
||||
help_text=_("The checksum of the original folder."),
|
||||
)
|
||||
|
||||
class Meta(MatchingModel.Meta):
|
||||
verbose_name = _("folder")
|
||||
|
@ -1,3 +1,4 @@
|
||||
import hashlib
|
||||
import itertools
|
||||
import json
|
||||
import logging
|
||||
@ -2128,6 +2129,7 @@ class FolderViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||
|
||||
@action(methods=["get"], detail=True)
|
||||
def folders_documents_by_id(self, request, pk=None):
|
||||
print("dkljfskljf")
|
||||
currentUser = request.user
|
||||
try:
|
||||
fol = Folder.objects.get(pk=pk)
|
||||
@ -2164,11 +2166,13 @@ class FolderViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||
folder = serializer.save()
|
||||
folder.path = str(folder.id)
|
||||
folder.owner = currentUser
|
||||
folder.checksum = hashlib.md5(f'{folder.id}.{folder.name}'.encode()).hexdigest()
|
||||
folder.save()
|
||||
elif parent_folder:
|
||||
folder = serializer.save(parent_folder=parent_folder)
|
||||
folder.path = f"{parent_folder.path}/{folder.id}"
|
||||
folder.owner = currentUser
|
||||
folder.checksum = hashlib.md5(f'{folder.id}.{folder.name}'.encode()).hexdigest()
|
||||
folder.save()
|
||||
else:
|
||||
return Response(status=status.HTTP_400_BAD_REQUEST)
|
||||
@ -2199,7 +2203,7 @@ class FolderViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||
if old_parent_folder != instance.parent_folder:
|
||||
if instance.parent_folder:
|
||||
instance.path = f"{instance.parent_folder.path}/{instance.id}"
|
||||
|
||||
|
||||
else:
|
||||
instance.path = f"{instance.id}"
|
||||
instance.save()
|
||||
|
Loading…
x
Reference in New Issue
Block a user