inlines.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from django_inlines.inlines import TemplateInline
  2. from darkroom.models import Photo
  3. class PhotoInline(TemplateInline):
  4. """
  5. An inline that takes a darkroom photo id, slug, or just a url returns a photo template with proper width and height.
  6. Examples::
  7. {{ photo 34 }}
  8. The inluded template supports width and height arguments::
  9. {{ photo 32 size=small }}
  10. """
  11. help_text = "Takes a darkroom photo id or slug and returns a template for the photo."
  12. inline_args = [
  13. dict(name='size', help_text="Small/Medium/Large/Full")
  14. ]
  15. def get_context(self):
  16. try:
  17. photo = Photo.objects.get(pk=self.value)
  18. except:
  19. photo = Photo.objects.get(slug=self.value)
  20. return { 'photo': photo }
  21. class GraphicInline(TemplateInline):
  22. """
  23. An inline that takes a darkroom graphic id, slug, or just a url returns a template with size and position classes set.
  24. Examples::
  25. {{ graphic 34 }}
  26. The inluded template supports width and height arguments::
  27. {{ graphic 32 size=small float=right }}
  28. """
  29. help_text = "Takes a darkroom graphic id or slug and returns a template for the graphic."
  30. inline_args = [
  31. dict(name='size', help_text="Small/Medium/Large/Full")
  32. ]
  33. def get_context(self):
  34. try:
  35. photo = Graphic.objects.get(pk=self.value)
  36. except:
  37. photo = Graphic.objects.get(slug=self.value)
  38. return { 'graphic': graphic }