image_gallery.models: 19 total statements, 100.0% covered

Generated: Tue 2013-06-11 14:10 CEST

Source file: /home/tobi/Projects/cmsplugin-image-gallery/src/image_gallery/models.py

Stats: 11 executed, 0 missed, 8 excluded, 42 ignored

  1. """Models for the ``image_gallery`` app."""
  2. from django.db import models
  3. from django.utils.translation import ugettext_lazy as _
  4. from cms.models import CMSPlugin
  5. from cms.models.fields import PlaceholderField
  6. from filer.fields.folder import FilerFolderField
  7. from filer.models.imagemodels import Image
  8. class Gallery(models.Model):
  9. """
  10. Model to display a filer folder's contents and provide extra information.
  11. :title: Gallery title.
  12. :date: Date/Time of the gallery event.
  13. :location: Location of the gallery items.
  14. :description: Description of the gallery.
  15. :folder: Linked folder of the filer app.
  16. """
  17. title = models.CharField(
  18. max_length=100,
  19. verbose_name=_('Title'),
  20. )
  21. date = models.DateTimeField(
  22. verbose_name=_('Date'),
  23. blank=True, null=True,
  24. )
  25. location = models.CharField(
  26. max_length=100,
  27. verbose_name=_('Location'),
  28. blank=True, null=True,
  29. )
  30. description = PlaceholderField(
  31. 'description',
  32. verbose_name=_('Description'),
  33. )
  34. folder = FilerFolderField(
  35. verbose_name=_('Folder'),
  36. )
  37. def __unicode__(self):
  38. return '{0}'.format(self.title)
  39. def get_folder_images(self):
  40. """Returns a set of images, which have been placed in this folder."""
  41. qs_files = self.folder.files.instance_of(Image)
  42. return qs_files.filter(is_public=True)
  43. class GalleryPlugin(CMSPlugin):
  44. """Plugin model to link to a specific gallery instance."""
  45. gallery = models.ForeignKey(
  46. Gallery,
  47. verbose_name=_('Gallery'),
  48. )