plinit.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from django.core.management.base import BaseCommand, CommandError
  2. from photologue.management.commands import get_response, create_photosize
  3. from photologue.models import PhotoEffect
  4. class Command(BaseCommand):
  5. help = "Prompts the user to set up the default photo sizes required by Photologue."
  6. requires_model_validation = True
  7. can_import_settings = True
  8. def handle(self, *args, **kwargs):
  9. return init(*args, **kwargs)
  10. def init(*args, **kwargs):
  11. msg = "\nPhotologue requires a specific photo size to display thumbnail previews in the Django admin application.\nWould you like to generate this size now? (yes, no):"
  12. if get_response(msg, lambda inp: inp == "yes", False):
  13. admin_thumbnail = create_photosize(
  14. "admin_thumbnail", width=100, height=75, crop=True, pre_cache=True
  15. )
  16. msg = "Would you like to apply a sample enhancement effect to your admin thumbnails? (yes, no):"
  17. if get_response(msg, lambda inp: inp == "yes", False):
  18. effect, created = PhotoEffect.objects.get_or_create(
  19. name="Enhance Thumbnail",
  20. description="Increases sharpness and contrast. Works well for smaller image sizes such as thumbnails.",
  21. contrast=1.2,
  22. sharpness=1.3,
  23. )
  24. admin_thumbnail.effect = effect
  25. admin_thumbnail.save()
  26. msg = '\nPhotologue comes with a set of templates for setting up a complete photo gallery. These templates require you to define both a "thumbnail" and "display" size.\nWould you like to define them now? (yes, no):'
  27. if get_response(msg, lambda inp: inp == "yes", False):
  28. thumbnail = create_photosize("thumbnail", width=100, height=75)
  29. display = create_photosize("display", width=400, increment_count=True)
  30. msg = "Would you like to apply a sample reflection effect to your display images? (yes, no):"
  31. if get_response(msg, lambda inp: inp == "yes", False):
  32. effect, created = PhotoEffect.objects.get_or_create(
  33. name="Display Reflection",
  34. description="Generates a reflection with a white background",
  35. reflection_size=0.4,
  36. )
  37. display.effect = effect
  38. display.save()