models.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from importlib import import_module
  2. from django.db import models
  3. from django.utils import timezone
  4. from django.utils.encoding import python_2_unicode_compatible
  5. from django.utils.translation import ugettext_lazy as _
  6. @python_2_unicode_compatible
  7. class Bookmark(models.Model):
  8. url = models.URLField(verbose_name=_('URL'))
  9. title = models.CharField(verbose_name=_('title'), max_length=255)
  10. user = models.PositiveIntegerField(verbose_name=_('user'))
  11. date_add = models.DateTimeField(verbose_name=_('date created'), default=timezone.now)
  12. class Meta:
  13. verbose_name = _('bookmark')
  14. verbose_name_plural = _('bookmarks')
  15. ordering = ('date_add',)
  16. def __str__(self):
  17. return self.title
  18. @python_2_unicode_compatible
  19. class PinnedApplication(models.Model):
  20. app_label = models.CharField(verbose_name=_('application name'), max_length=255)
  21. user = models.PositiveIntegerField(verbose_name=_('user'))
  22. date_add = models.DateTimeField(verbose_name=_('date created'), default=timezone.now)
  23. class Meta:
  24. verbose_name = _('pinned application')
  25. verbose_name_plural = _('pinned applications')
  26. ordering = ('date_add',)
  27. def __str__(self):
  28. return self.app_label
  29. @python_2_unicode_compatible
  30. class UserDashboardModule(models.Model):
  31. title = models.CharField(verbose_name=_('Title'), max_length=255)
  32. module = models.CharField(verbose_name=_('module'), max_length=255)
  33. app_label = models.CharField(verbose_name=_('application name'), max_length=255, null=True, blank=True)
  34. user = models.PositiveIntegerField(verbose_name=_('user'))
  35. column = models.PositiveIntegerField(verbose_name=_('column'))
  36. order = models.IntegerField(verbose_name=_('order'))
  37. settings = models.TextField(verbose_name=_('settings'), default='', blank=True)
  38. children = models.TextField(verbose_name=_('children'), default='', blank=True)
  39. collapsed = models.BooleanField(verbose_name=_('collapsed'), default=False)
  40. class Meta:
  41. verbose_name = _('user dashboard module')
  42. verbose_name_plural = _('user dashboard modules')
  43. ordering = ('column', 'order')
  44. def __str__(self):
  45. return self.module
  46. def load_module(self):
  47. package, module_name = self.module.rsplit('.', 1)
  48. package = import_module(package)
  49. module = getattr(package, module_name)
  50. return module