Exemple #1
0
def seo_processor(requests):
    key = 'seo_processor'
    value = cache.get(key)
    if value:
        logger.info('get processor cache.')
        return value
    else:
        logger.info('set processor cache.')
        setting = get_blog_setting()
        value = {
            'SITE_NAME': setting.sitename,
            'SHOW_GOOGLE_ADSENSE': setting.show_google_adsense,
            'GOOGLE_ADSENSE_CODES': setting.google_adsense_codes,
            'SITE_SEO_DESCRIPTION': setting.site_seo_description,
            'SITE_DESCRIPTION': setting.site_description,
            'SITE_KEYWORDS': setting.site_keywords,
            'SITE_BASE_URL': requests.scheme + '://' + requests.get_host() + '/',
            'ARTICLE_SUB_LENGTH': setting.article_sub_length,
            'nav_category_list': Category.objects.all(),
            'nav_pages': Article.objects.filter(type='p', status='p'),
            'OPEN_SITE_COMMENT': setting.open_site_comment,
            'BEIAN_CODE': setting.beiancode,
            "BEIAN_CODE_GONGAN": setting.gongan_beiancode,
            "SHOW_GONGAN_CODE": setting.show_gongan_code

        }
        cache.set(key, value, 60 * 60 * 10)
        return value
 def get_queryset_from_cache(self, cache_key):
     # raise NotImplementedError()
     value = cache.get(cache_key)
     if value:
         logger.info('get view cache.key:{key}'.format(key=cache_key))
         return value
     else:
         article_list = self.get_queryset_data()
         cache.set(cache_key, article_list)
         logger.info('set view cache.key:{key}'.format(key=cache_key))
         return article_list
Exemple #3
0
 def comment_list(self):
     cache_key = 'article_comments_{id}'.format(id=self.id)
     value = cache.get(cache_key)
     if value:
         logger.info('get article comments:{id}'.format(id=self.id))
         return value
     else:
         comments = self.comment_set.filter(is_enable=True)
         cache.set(cache_key, comments)
         logger.info('set article comments:{id}'.format(id=self.id))
         return comments
Exemple #4
0
 def files_list(self):
     cache_key = 'article_files_{id}'.format(id=self.id)
     value = cache.get(cache_key)
     if value:
         logger.info('get article files:{id}'.format(id=self.id))
         return value
     else:
         files = self.files_set.filter(is_enable=True)
         cache.set(cache_key, files)
         logger.info('set article files:{id}'.format(id=self.id))
         return files
Exemple #5
0
 def links_list(self):
     cache_key = 'article_links_{id}'.format(id=self.id)
     value = cache.get(cache_key)
     if value:
         logger.info('get article links:{id}'.format(id=self.id))
         return value
     else:
         links = self.links_set.filter(is_enable=True)
         cache.set(cache_key, links)
         logger.info('set article links:{id}'.format(id=self.id))
         return links
def seo_processor(requests):
    key = 'seo_processor'
    value = cache.get(key)
    if value:
        return value
    else:
        logger.info('set processor cache.')
        setting = get_web_setting()
        contact = get_contact_info()
        value = {
            'SITE_ADDRESS': setting.site_address,
            'SITE_NAME': setting.sitename,
            'SHOW_GOOGLE_ADSENSE': setting.show_google_adsense,
            'GOOGLE_ADSENSE_CODES': setting.google_adsense_codes,
            'SITE_SEO_DESCRIPTION': setting.site_seo_description,
            'SITE_DESCRIPTION': setting.site_description,
            'SITE_KEYWORDS': setting.site_keywords,
            'COPYRIGHT': setting.copyright,
            'BLOG_NAME': setting.blogname,
            'BLOG_SEO_DESCRIPTION': setting.blog_seo_description,
            'BLOG_DESCRIPTION': setting.blog_description,
            'BLOG_KEYWORDS': setting.blog_keywords,
            'SITE_BASE_URL': requests.scheme + '://' + requests.get_host() + '/',
            'BLOG_BASE_URL': requests.scheme + '://' + requests.get_host() + '/blog/',
            'ARTICLE_SUB_LENGTH': setting.article_sub_length,
            'nav_category_list': Category.objects.all(),
            'nav_pages': Article.objects.filter(type='p', status='p'),
            'OPEN_BLOG_COMMENT': setting.open_blog_comment,
            'BEIAN_CODE': setting.beiancode,
            'ANALYTICS_CODE': setting.analyticscode,
            "BEIAN_CODE_GONGAN": setting.gongan_beiancode,
            "SHOW_GONGAN_CODE": setting.show_gongan_code,
            "CURRENT_YEAR": datetime.now().year,
            "LOGO_IMG": setting.logo_img.url,
            "LOGO_FOOTER_IMG": setting.logo_footer_img.url,
            "PHONE_IMG": setting.phone_img.url,
            "WECHART_IMG": setting.wechart_img.url,
            "COMPANY": contact.company,
            "PHONE": contact.phone,
            "PHONE_USER": contact.phone_user,
            "WECHART": contact.wechart,
            "QQ": contact.qq,
            "PHONE_AFTER_SALE": contact.phone_after_sale,
            "PHONE_AFTER_SALE_USER": contact.phone_after_sale_user,
            "EMAIL": contact.email,
            "EMAIL_HR": contact.email_hr,
            "ADDRESS": contact.address,
        }
        cache.set(key, value, 60 * 60 * 10)
        return value
Exemple #7
0
def gravatar_url(email, size=40):
    """获得gravatar头像"""
    cachekey = 'gravatat/' + email
    if cache.get(cachekey):
        return cache.get(cachekey)
    else:
        usermodels = OAuthUser.objects.filter(email=email)
        if usermodels:
            o = list(filter(lambda x: x.picture is not None, usermodels))
            if o:
                return o[0].picture
        email = email.encode('utf-8')

        default = "https://xxxxxxxxxxxxxx/image/2017/03/26/120117.jpg".encode(
            'utf-8')

        url = "https://www.gravatar.com/avatar/%s?%s" % (
            hashlib.md5(email.lower()).hexdigest(),
            urllib.parse.urlencode({
                'd': default,
                's': str(size)
            }))
        cache.set(cachekey, url, 60 * 60 * 10)
        return url