attachmenttype.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from __future__ import unicode_literals
  2. from django.db import models
  3. from django.utils.encoding import python_2_unicode_compatible
  4. from django.utils.translation import ugettext_lazy as _
  5. @python_2_unicode_compatible
  6. class AttachmentType(models.Model):
  7. ENABLED = 0
  8. LOCKED = 1
  9. DISABLED = 2
  10. name = models.CharField(max_length=255)
  11. extensions = models.CharField(max_length=255)
  12. mimetypes = models.CharField(null=True, blank=True, max_length=255)
  13. size_limit = models.PositiveIntegerField(default=1024)
  14. status = models.PositiveIntegerField(
  15. default=ENABLED,
  16. choices=((ENABLED, _("Allow uploads and downloads")), (LOCKED, _("Allow downloads only")),
  17. (DISABLED, _("Disallow both uploading and downloading")), )
  18. )
  19. limit_uploads_to = models.ManyToManyField('misago_acl.Role', related_name='+', blank=True)
  20. limit_downloads_to = models.ManyToManyField('misago_acl.Role', related_name='+', blank=True)
  21. def __str__(self):
  22. return self.name
  23. @property
  24. def is_enabled(self):
  25. return self.status == AttachmentType.ENABLED
  26. @property
  27. def extensions_list(self):
  28. if self.extensions:
  29. return self.extensions.split(',')
  30. return []
  31. @property
  32. def mimetypes_list(self):
  33. if self.mimetypes:
  34. return self.mimetypes.split(',')
  35. return []