Esempio n. 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
Esempio n. 2
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. 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
Esempio n. 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
Esempio n. 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
Esempio n. 6
0
def comment_save_callback(sender, **kwargs):
    from comments.models import Comment
    if settings.DEBUG:
        return

    serverport = kwargs['serverport']
    username = kwargs['username']
    comment = Comment.objects.get(id=kwargs['comment_id'])
    site = Site.objects.get_current().domain
    article = comment.article
    # if not settings.DEBUG:
    if True:
        subject = '感谢您发表的评论'
        article_url = "https://{site}{path}".format(site=site, path=comment.article.get_absolute_url())
        html_content = """
        <p>非常感谢您在本站发表评论</p>
        您可以访问
        <a href="%s" rel="bookmark">%s</a>
        来查看您的评论,
        再次感谢您!
        <br />
        如果上面链接无法打开,请将此链接复制至浏览器。
        %s
        """ % (article_url, comment.article.title, article_url)
        tomail = comment.author.email
        send_email([tomail], subject, html_content)

        if comment.parent_comment:
            html_content = """
            您在 <a href="%s" rel="bookmark">%s</a> 的评论 <br/> %s <br/> 收到回复啦.快去看看吧
            <br/>
            如果上面链接无法打开,请将此链接复制至浏览器。
            %s
            """ % (article_url, article.title, comment.parent_comment.body, article_url)
            tomail = comment.parent_comment.author.email
            send_email([tomail], subject, html_content)

    path = article.get_absolute_url()
    site = Site.objects.get_current().domain
    if site.find(':') > 0:
        site = site[0:site.find(':')]

    expire_view_cache(path, servername=site, serverport=serverport, key_prefix='blogdetail')
    if cache.get('seo_processor'):
        cache.delete('seo_processor')
    comment_cache_key = 'article_comments_{id}'.format(id=article.id)
    cache.delete(comment_cache_key)
    from django.core.cache.utils import make_template_fragment_key

    key = make_template_fragment_key('sidebar', [username])
    cache.delete(key)
def comment_save_callback(sender, **kwargs):
    from comments.models import Comment

    serverport = kwargs['serverport']
    username = kwargs['username']
    comment = Comment.objects.get(id=kwargs['comment_id'])
    site = Site.objects.get_current().domain
    article = comment.article
    # if not settings.DEBUG:
    if True:
        subject = 'Thank you for your comment'
        article_url = "https://{site}{path}".format(
            site=site, path=comment.article.get_absolute_url())
        html_content = """
        <p>Thank you for your comment on this site</p>
        You can visit
        <a href="%s" rel="bookmark">%s</a>
        To see your comment,
        Thank you again!
        <br />
        If the above link can not be opened,Please copy this link to the browser。
        %s
        """ % (article_url, comment.article.title, article_url)
        tomail = comment.author.email
        # send_email([tomail], subject, html_content)

        if comment.parent_comment:
            html_content = """
            You received a reply in <a href="%s" rel="bookmark">%s</a> comments <br/> %s <br/> Check it out
            <br/>
            If the above link does not open, please copy this link to your browser.
            %s
            """ % (article_url, article.title, comment.parent_comment.body,
                   article_url)
            tomail = comment.parent_comment.author.email
            # send_email([tomail], subject, html_content)

    path = article.get_absolute_url()
    site = Site.objects.get_current().domain
    if site.find(':') > 0:
        site = site[0:site.find(':')]

    # expire_view_cache(path, servername=site, serverport=serverport, key_prefix='blogdetail')
    if cache.get('seo_processor'):
        cache.delete('seo_processor')
    comment_cache_key = 'article_comments_{id}'.format(id=article.id)
    cache.delete(comment_cache_key)
    from django.core.cache.utils import make_template_fragment_key

    key = make_template_fragment_key('sidebar', [username])
    cache.delete(key)
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
Esempio n. 9
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