Esempio n. 1
0
def seo_processor(requests):
    key = 'seo_processor'
    value = cache.get(key)
    if value:
        return value
    else:
        # logger.debug('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'),
            'ENABLE_SITE_COMMENT': setting.enable_site_comment,
            'FOOTER_TITLE': setting.footer_title,
            'ANALYTICS_CODE': setting.analyticscode,
            "CURRENT_YEAR": datetime.now().year,
            "SHOW_CATEGORY_BAR": setting.show_category_bar,
        }
        cache.set(key, value, 60 * 60 * 10)
        return value
Esempio n. 2
0
def seo_processor(requests):
    key = 'seo_processor'
    value = cache.get(key)
    if value:
        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,
            'ANALYTICS_CODE': setting.analyticscode,
            "BEIAN_CODE_GONGAN": setting.gongan_beiancode,
            "SHOW_GONGAN_CODE": setting.show_gongan_code

        }
        cache.set(key, value, 60 * 60 * 10)
        return value
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,
            'ANALYTICS_CODE': setting.analyticscode,
            "BEIAN_CODE_GONGAN": setting.gongan_beiancode,
            "SHOW_GONGAN_CODE": setting.show_gongan_code

        }
        cache.set(key, value, 60 * 60 * 10)
        return value
Esempio n. 4
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, 60 * 100)
         logger.info('set article comments:{id}'.format(id=self.id))
         return comments
Esempio n. 5
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.all()
         cache.set(cache_key, comments)
         logger.info('set article comments:{id}'.format(id=self.id))
         return comments
Esempio n. 6
0
 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
Esempio n. 7
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
Esempio n. 8
0
 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
Esempio n. 9
0
 def get_queryset_from_cache(self, cache_key):
     '''
     Cache page data
     :param cache_key: key
     :return:
     '''
     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
Esempio n. 10
0
 def get_queryset_from_cache(self, cache_key):
     '''
     缓存页面数据
     :param cache_key: 缓存key
     :return:
     '''
     value = cache.get(cache_key)
     if value:
         logger.info('获取 view 缓存的 key:{key}'.format(key=cache_key))
         return value
     else:
         article_list = self.get_queryset_data()
         cache.set(cache_key, article_list)
         logger.info('设置 view 缓存的 key:{key}'.format(key=cache_key))
         return article_list
Esempio n. 11
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 = "plcnwjj94.bkt.clouddn.com/b3c62e943e1669d7400c12068d8a9ec4b4d3010d2003f-OYVWqm.png".encode('utf-8') 

        url = "http://plcnwjj94.bkt.clouddn.com/b3c62e943e1669d7400c12068d8a9ec4b4d3010d2003f-OYVWqm.png"
        cache.set(cachekey, url, 60 * 60 * 10)
        return url
Esempio n. 12
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://resource.lylinux.net/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
Esempio n. 13
0
    def get_queryset_from_cache(self, cache_key):
        """
        缓存页面数据
        :param cache_key: 缓存 key
        :return:
        """

        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
Esempio n. 14
0
def gravatar_url(email, size=40):
    """Get gravatar avatar"""
    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://mtuktarov.ru/static/blog/img/avatar.png".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
Esempio n. 15
0
    def process_view(self, request, view_func, view_args, view_kwargs):
        """
        处理当前在线人数
        """
        http_user_agent = request.META.get('HTTP_USER_AGENT', [])
        if 'Spider' in http_user_agent or 'spider' in http_user_agent:
            return

        online_ips = cache.get("online_ips", [])
        if online_ips:
            online_ips = cache.get_many(online_ips).keys()
            online_ips = list(online_ips)
        ip = get_real_ip(request)

        cache.set(ip, 0, 5 * 60)

        if ip not in online_ips:
            online_ips.append(ip)
            s = type(online_ips)
            cache.set("online_ips", online_ips)
Esempio n. 16
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.')
        value = {
            'SITE_NAME': settings.SITE_NAME,
            'SHOW_GOOGLE_ADSENSE': settings.SHOW_GOOGLE_ADSENSE,
            'SITE_SEO_DESCRIPTION': settings.SITE_SEO_DESCRIPTION,
            'SITE_DESCRIPTION': settings.SITE_DESCRIPTION,
            'SITE_KEYWORDS': settings.SITE_SEO_KEYWORDS,
            'SITE_BASE_URL': requests.scheme + '://' + requests.get_host() + '/',
            'ARTICLE_SUB_LENGTH': settings.ARTICLE_SUB_LENGTH,
            'nav_category_list': Category.objects.all(),
            'nav_pages': Article.objects.filter(type='p', status='p'),
            # 'MAX_COMMENTID': Comment.objects.latest().pk,
            # 'MAX_ARTICLEID': Article.objects.latest().pk
        }
        cache.set(key, value, 60 * 60 * 10)
        return value