cms.plugins.snippet.models: 22 total statements, 0.0% covered

Generated: Wed 2013-03-13 10:33 CET

Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/cms/plugins/snippet/models.py

Stats: 0 executed, 14 missed, 8 excluded, 21 ignored

  1. from django.db import models
  2. from django.utils.translation import ugettext_lazy as _
  3. from cms.models import CMSPlugin
  4. from cms.utils.helpers import reversion_register
  5. # Stores the actual data
  6. class Snippet(models.Model):
  7. """
  8. A snippet of HTML or a Django template
  9. """
  10. name = models.CharField(_("name"), max_length=255, unique=True)
  11. html = models.TextField(_("HTML"), blank=True)
  12. template = models.CharField(_("template"), max_length=50, blank=True, \
  13. help_text=_('Enter a template (i.e. "snippets/plugin_xy.html") which will be rendered. ' + \
  14. 'If "template" is given, the contents of field "HTML" will be passed as template variable {{ html }} to the template. ' + \
  15. 'Else, the content of "HTML" is rendered.'))
  16. def __unicode__(self):
  17. return self.name
  18. class Meta:
  19. ordering = ['name']
  20. verbose_name = _("Snippet")
  21. verbose_name_plural = _("Snippets")
  22. # Plugin model - just a pointer to Snippet
  23. class SnippetPtr(CMSPlugin):
  24. snippet = models.ForeignKey(Snippet)
  25. class Meta:
  26. verbose_name = _("Snippet")
  27. search_fields = ('snippet__html',)
  28. def __unicode__(self):
  29. # Return the referenced snippet's name rather than the default (ID #)
  30. return self.snippet.name
  31. # We don't both with SnippetPtr, since all the data is actually in Snippet
  32. reversion_register(Snippet)