1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-26 07:22:34 +00:00

SeadocRevisions

This commit is contained in:
skywalker
2023-06-27 18:29:55 +08:00
committed by er-pai-r
parent 178b5b0e78
commit 0da16303f5
4 changed files with 287 additions and 3 deletions

View File

@@ -1,6 +1,9 @@
import os
from django.db import models
from seahub.utils.timeutils import datetime_to_isoformat_timestr
from seahub.base.templatetags.seahub_tags import email2nickname
class SeadocHistoryNameManager(models.Manager):
@@ -28,7 +31,6 @@ class SeadocHistoryName(models.Model):
def to_dict(self):
return {
'id': self.pk,
'doc_uuid': self.doc_uuid,
'obj_id': self.obj_id,
'name': self.name,
@@ -75,3 +77,75 @@ class SeadocDraft(models.Model):
'username': self.username,
'created_at': datetime_to_isoformat_timestr(self.created_at),
}
class SeadocRevisionManager(models.Manager):
def get_by_doc_uuid(self, doc_uuid):
return self.filter(doc_uuid=doc_uuid).first()
def list_by_doc_uuids(self, doc_uuid_list):
return self.filter(doc_uuid__in=doc_uuid_list)
def list_by_origin_doc_uuid(self, origin_doc_uuid):
return self.filter(origin_doc_uuid=origin_doc_uuid)
def list_by_username(self, username):
return self.filter(username=username)
def list_by_repo_id(self, repo_id):
return self.filter(repo_id=repo_id)
def publish(self, doc_uuid, publisher, publish_file_version):
return self.filter(doc_uuid=doc_uuid).update(
publisher=publisher,
publish_file_version=publish_file_version,
is_published=True,
)
class SeadocRevision(models.Model):
"""
"""
doc_uuid = models.CharField(max_length=36, unique=True)
origin_doc_uuid = models.CharField(max_length=36, db_index=True)
repo_id = models.CharField(max_length=36, db_index=True)
origin_doc_path = models.TextField() # used when origin file deleted
username = models.CharField(max_length=255, db_index=True)
origin_file_version = models.CharField(max_length=100)
publish_file_version = models.CharField(max_length=100, null=True)
publisher = models.CharField(max_length=255, null=True)
is_published = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True, db_index=True)
objects = SeadocRevisionManager()
class Meta:
db_table = 'sdoc_revision'
def to_dict(self):
from seahub.tags.models import FileUUIDMap
file_uuid = FileUUIDMap.objects.get_fileuuidmap_by_uuid(self.origin_doc_uuid)
if file_uuid:
origin_parent_path = file_uuid.parent_path
origin_filename = file_uuid.filename
else:
origin_parent_path = os.path.dirname(self.origin_doc_path)
origin_filename = os.path.basename(self.origin_doc_path)
return {
'username': self.username,
'nickname': email2nickname(self.username),
'repo_id': self.repo_id,
'doc_uuid': self.doc_uuid,
'origin_doc_uuid': self.origin_doc_uuid,
'origin_parent_path': origin_parent_path,
'origin_filename': origin_filename,
'origin_file_version': self.origin_file_version,
'publish_file_version': self.publish_file_version,
'publisher': self.publisher,
'publisher_nickname': email2nickname(self.publisher),
'is_published': self.is_published,
'created_at': datetime_to_isoformat_timestr(self.created_at),
'updated_at': datetime_to_isoformat_timestr(self.updated_at),
}