context_processors.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. """ customize the info available in context for rendering templates """
  2. from bookwyrm import models, settings
  3. def site_settings(request): # pylint: disable=unused-argument
  4. """include the custom info about the site"""
  5. request_protocol = "https://"
  6. if not request.is_secure():
  7. request_protocol = "http://"
  8. site = models.SiteSettings.objects.get()
  9. theme = "css/themes/bookwyrm-light.scss"
  10. if (
  11. hasattr(request, "user")
  12. and request.user.is_authenticated
  13. and request.user.theme
  14. ):
  15. theme = request.user.theme.path
  16. elif site.default_theme:
  17. theme = site.default_theme.path
  18. return {
  19. "site": site,
  20. "site_theme": theme,
  21. "active_announcements": models.Announcement.active_announcements(),
  22. "thumbnail_generation_enabled": settings.ENABLE_THUMBNAIL_GENERATION,
  23. "media_full_url": settings.MEDIA_FULL_URL,
  24. "preview_images_enabled": settings.ENABLE_PREVIEW_IMAGES,
  25. "request_protocol": request_protocol,
  26. "js_cache": settings.JS_CACHE,
  27. }