image_gallery.models: 25 total statements, 100.0% covered

Generated: Sun 2013-06-16 14:51 CEST

Source file: /home/dkaufhold/projects/cmsplugin-image-gallery/src/image_gallery/models.py

Stats: 15 executed, 0 missed, 10 excluded, 64 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. category = models.ForeignKey(
  18. 'image_gallery.GalleryCategory',
  19. verbose_name=_('Category'),
  20. blank=True, null=True,
  21. )
  22. title = models.CharField(
  23. max_length=100,
  24. verbose_name=_('Title'),
  25. )
  26. date = models.DateTimeField(
  27. verbose_name=_('Date'),
  28. blank=True, null=True,
  29. )
  30. location = models.CharField(
  31. max_length=100,
  32. verbose_name=_('Location'),
  33. blank=True, null=True,
  34. )
  35. description = PlaceholderField(
  36. 'description',
  37. verbose_name=_('Description'),
  38. )
  39. folder = FilerFolderField(
  40. verbose_name=_('Folder'),
  41. )
  42. def __unicode__(self):
  43. return '{0}'.format(self.title)
  44. def get_folder_images(self):
  45. """Returns a set of images, which have been placed in this folder."""
  46. qs_files = self.folder.files.instance_of(Image)
  47. return qs_files.filter(is_public=True)
  48. class GalleryCategory(models.Model):
  49. """
  50. Is used to categorize galleries.
  51. :name: Then human readable name of the category.
  52. :slug: The slug of the category
  53. """
  54. name = models.CharField(
  55. max_length=256,
  56. verbose_name=_('Name'),
  57. )
  58. slug = models.SlugField(
  59. max_length=32,
  60. verbose_name=_('Slug'),
  61. )
  62. def __unicode__(self):
  63. return self.name
  64. class GalleryPlugin(CMSPlugin):
  65. """Plugin model to link to a specific gallery instance."""
  66. gallery = models.ForeignKey(
  67. Gallery,
  68. verbose_name=_('Gallery'),
  69. )