inlines.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 = (
  12. "Takes a darkroom photo id or slug and returns a template for the photo."
  13. )
  14. inline_args = [dict(name="size", help_text="Small/Medium/Large/Full")]
  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 = (
  30. "Takes a darkroom graphic id or slug and returns a template for the graphic."
  31. )
  32. inline_args = [dict(name="size", help_text="Small/Medium/Large/Full")]
  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}