attachmenttype.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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=[
  17. (ENABLED, _("Allow uploads and downloads")),
  18. (LOCKED, _("Allow downloads only")),
  19. (DISABLED, _("Disallow both uploading and downloading")),
  20. ],
  21. )
  22. limit_uploads_to = models.ManyToManyField('misago_acl.Role', related_name='+', blank=True)
  23. limit_downloads_to = models.ManyToManyField('misago_acl.Role', related_name='+', blank=True)
  24. def __str__(self):
  25. return self.name
  26. @property
  27. def is_enabled(self):
  28. return self.status == AttachmentType.ENABLED
  29. @property
  30. def extensions_list(self):
  31. if self.extensions:
  32. return self.extensions.split(',')
  33. return []
  34. @property
  35. def mimetypes_list(self):
  36. if self.mimetypes:
  37. return self.mimetypes.split(',')
  38. return []