예제 #1
0
class DeviceToken(models.Model):
    """
    The iOS device token model.
    """
    token = models.CharField(max_length=80)
    user = LowerCaseCharField(max_length=255)
    platform = LowerCaseCharField(max_length=32)
    version = LowerCaseCharField(max_length=16)
    pversion = LowerCaseCharField(max_length=16)

    class Meta:
        unique_together = (("token", "user"), )

    def __unicode__(self):
        return "/".join(self.user, self.token)
예제 #2
0
파일: models.py 프로젝트: yehuangcn/seahub
class FileComment(models.Model):
    """
    Model used to record file comments.
    """
    uuid = models.ForeignKey(FileUUIDMap, on_delete=models.CASCADE)
    author = LowerCaseCharField(max_length=255, db_index=True)
    comment = models.TextField()
    created_at = models.DateTimeField(default=timezone.now)
    updated_at = models.DateTimeField(default=timezone.now)
    resolved = models.BooleanField(default=False, db_index=True)
    detail = models.TextField(default='')

    objects = FileCommentManager()

    @classmethod
    def normalize_path(self, path):
        return path.rstrip('/') if path != '/' else '/'

    def to_dict(self):
        o = self
        return {
            'id': o.pk,
            'repo_id': o.uuid.repo_id,
            'parent_path': o.uuid.parent_path,
            'item_name': o.uuid.filename,
            'comment': o.comment,
            'created_at': datetime_to_isoformat_timestr(o.created_at),
            'resolved': o.resolved,
            'detail': o.detail,
        }
예제 #3
0
class FileComment(models.Model):
    """
    Model used to record file comments.
    """
    repo_id = models.CharField(max_length=36, db_index=True)
    parent_path = models.TextField()
    repo_id_parent_path_md5 = models.CharField(max_length=100, db_index=True)
    item_name = models.TextField()
    author = LowerCaseCharField(max_length=255, db_index=True)
    comment = models.TextField()
    created_at = models.DateTimeField(default=timezone.now)
    updated_at = models.DateTimeField(default=timezone.now)
    objects = FileCommentManager()

    @classmethod
    def md5_repo_id_parent_path(cls, repo_id, parent_path):
        parent_path = parent_path.rstrip('/') if parent_path != '/' else '/'
        return hashlib.md5(repo_id + parent_path).hexdigest()

    @classmethod
    def normalize_path(self, path):
        return path.rstrip('/') if path != '/' else '/'

    def save(self, *args, **kwargs):
        self.parent_path = self.normalize_path(self.parent_path)
        if not self.repo_id_parent_path_md5:
            self.repo_id_parent_path_md5 = self.md5_repo_id_parent_path(
                self.repo_id, self.parent_path)

        super(FileComment, self).save(*args, **kwargs)

    def to_dict(self):
        o = self
        return {
            'id': o.pk,
            'repo_id': o.repo_id,
            'parent_path': o.parent_path,
            'item_name': o.item_name,
            'comment': o.comment,
            'created_at': datetime_to_isoformat_timestr(o.created_at),
        }