context_processors.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from .models import Category, Article, Tag, BlogSettings
  2. from django.conf import settings
  3. from comments.models import Comment
  4. from website.utils import cache, get_blog_setting
  5. import logging
  6. logger = logging.getLogger(__name__)
  7. def seo_processor(requests):
  8. key = 'seo_processor'
  9. value = cache.get(key)
  10. if value:
  11. logger.info('get processor cache.')
  12. return value
  13. else:
  14. logger.info('set processor cache.')
  15. setting = get_blog_setting()
  16. value = {
  17. 'SITE_NAME': setting.sitename,
  18. 'SHOW_GOOGLE_ADSENSE': setting.show_google_adsense,
  19. 'GOOGLE_ADSENSE_CODES': setting.google_adsense_codes,
  20. 'SITE_SEO_DESCRIPTION': setting.site_seo_description,
  21. 'SITE_DESCRIPTION': setting.site_description,
  22. 'SITE_KEYWORDS': setting.site_keywords,
  23. 'SITE_BASE_URL': requests.scheme + '://' + requests.get_host() + '/',
  24. 'ARTICLE_SUB_LENGTH': setting.article_sub_length,
  25. 'nav_category_list': Category.objects.all(),
  26. 'nav_pages': Article.objects.filter(type='p', status='p'),
  27. 'OPEN_SITE_COMMENT': setting.open_site_comment,
  28. 'BEIAN_CODE': setting.beiancode,
  29. "BEIAN_CODE_GONGAN": setting.gongan_beiancode,
  30. "SHOW_GONGAN_CODE": setting.show_gongan_code
  31. }
  32. cache.set(key, value, 60 * 60 * 10)
  33. return value