Esempio n. 1
0
def cachePage(handler):
    if sh.getSiteConfig('run_use_cache') != 'yes': return handler()

    key = str(sh.getEnv('HTTP_HOST')) + sh.getEnv('REQUEST_URI')
    method = sh.getEnv('REQUEST_METHOD')
    retention = getCacheRetention()
    now = time.time()

    if method == 'GET' and sh.getEnv('HTTP_HOST') != sh.config.HOST_NAME:
        # 如果处于缓存有效期
        data = getData(key)
        if (now - getLastCachedTime(key) < retention) and data:
            html = data['html']
            # 设置charset=utf-8,否则nginx不使用gzip压缩
            web.header('Content-Type', 'text/html; charset=utf-8')
            # 设置etag头,有利益客户端缓存
            web.header('Etag', data['etag'])
            if DEBUG: print 'get cache'
        else:
            html = handler()
            if retention > 0:
                etag = getMD5(str(html))
                cacheData(key, html, etag, int(retention), )
                web.header('Etag', etag)
                if DEBUG: print 'set cache'
            else:
                if DEBUG: print 'retention == 0'
                pass
    else: # POST 与admin 请求不缓存
        if DEBUG: print 'post no cache'
        html = handler()

    return html
Esempio n. 2
0
    def GET(self, name):
        menu_config = sh.ctrl('Editor').getMenuConfig()
        # 禁止访问未公开的路径
        if not menu_config: return sh.redirectTo404()

        key = self.prefix_key + name
        value = sh.getSiteConfig(key)
        return sh.editor.IndentTable(value, menu_config)
Esempio n. 3
0
    def GET(self, name):
        menu_config = sh.ctrl('Editor').getMenuConfig()
        # 禁止访问未公开的路径
        if not menu_config: return sh.redirectTo404()

        key = self.prefix_key + name
        value = sh.getSiteConfig(key)
        return sh.editor.IndentTable(value, menu_config)
Esempio n. 4
0
 def _getWinnerSettings(self, which_month):
     winner_settings = site_helper.getSiteConfig(which_month).split('\n')
     winner_settings = [(w.partition(':')[0].strip(), w.partition(':')[2].strip())
             for w in winner_settings]
     winner_settings = dict(winner_settings)
     if winner_settings.get('winner_id'):
         winner_settings['winner_user'] = getModel('User').get(winner_settings['winner_id'])
     return winner_settings
Esempio n. 5
0
def appendVersionNum(handler):
    res = handler()
    html = sh.unicodeToStr(res) if isinstance(res, unicode) else str(res) 
    curr_v = int(sh.getSiteConfig(CONFIG_KEY, 0))
    if curr_v:
        regex_strings = (
            (''' (?<=<link\ )([^>]*href=")([^":]*?)(\.css)(".*?>) ''', r'\1\2\3?v=%d\4' % curr_v),
            (''' (?<=<script\ )([^>]*src=")([^":]*?)(\.js)(".*?>) ''', r'\1\2\3?v=%d\4' % curr_v),
        )
        for pattern, replace in regex_strings:
            regex = re.compile(pattern, re.I | re.S | re.X)
            html = regex.sub(replace, html)
    return html
Esempio n. 6
0
    def processShareLink(self, user):
        session = site_helper.session
        if session.has_key('share_user_id'):
            share_link_model = getModel('ShareLink')
            ip = site_helper.ipToInt(site_helper.session.ip)
            share_limit = site_helper.getSiteConfig('share_link_ip_limit')
            ip_count = share_link_model.getTodayCountByIP(ip)

            if share_limit.isdigit() and ip_count < int(share_limit):
                source = ''
                if session.has_key('share_referer'):
                    for key in ['qq.com', 'weibo.com', 'renren.com']:
                        if key in session.share_referer:
                            source = key

                share_link_model.insert({'Userid': session.share_user_id, 'register_user_id': user.Userid, 'ip':ip, 'source': source, 'referer': session.get('share_referer', '') })

                follow_model = getModel('Follow')
                follow_model.replaceInsert({'Userid':session.share_user_id, 'followed_id':user.Userid})
                follow_model.replaceInsert({'Userid':user.Userid, 'followed_id':session.share_user_id})

            if DoTask().doTask(session.share_user_id, 'share_link'):
                append_score = getModel('GoalTask').getGoalByName('share_link')
                user_model = getModel('User')
                user_model.addShareScore(session.share_user_id, append_score)
                share_count = user_model.addShareCount(session.share_user_id)
                requirement = site_helper.getSiteConfig('share_link_medal_requirement')
                if requirement.isdigit() and share_count >= int(requirement):
                    medal = getModel('Medal').getOneByWhere('name=%s', ['share_daren'])
                    if medal:
                        getModel('UserHasMedal').insert({'Userid':session.share_user_id, 'Medalid':medal.Medalid, })

            if session.has_key('share_user_id'):
                del session.share_user_id
            if session.has_key('share_referer'):
                del session.share_referer
Esempio n. 7
0
def appendVersionNum(handler):
    res = handler()
    html = sh.unicodeToStr(res) if isinstance(res, unicode) else str(res)
    curr_v = int(sh.getSiteConfig(CONFIG_KEY, 0))
    if curr_v:
        regex_strings = (
            (''' (?<=<link\ )([^>]*href=")([^":]*?)(\.css)(".*?>) ''',
             r'\1\2\3?v=%d\4' % curr_v),
            (''' (?<=<script\ )([^>]*src=")([^":]*?)(\.js)(".*?>) ''',
             r'\1\2\3?v=%d\4' % curr_v),
        )
        for pattern, replace in regex_strings:
            regex = re.compile(pattern, re.I | re.S | re.X)
            html = regex.sub(replace, html)
    return html
Esempio n. 8
0
def cachePage(handler):
    if sh.getSiteConfig('run_use_cache') != 'yes': return handler()

    key = str(sh.getEnv('HTTP_HOST')) + sh.getEnv('REQUEST_URI')
    method = sh.getEnv('REQUEST_METHOD')
    retention = getCacheRetention()
    now = time.time()

    if method == 'GET' and sh.getEnv('HTTP_HOST') != sh.config.HOST_NAME:
        # 如果处于缓存有效期
        data = getData(key)
        if (now - getLastCachedTime(key) < retention) and data:
            html = data['html']
            # 设置charset=utf-8,否则nginx不使用gzip压缩
            web.header('Content-Type', 'text/html; charset=utf-8')
            # 设置etag头,有利益客户端缓存
            web.header('Etag', data['etag'])
            if DEBUG: print 'get cache'
        else:
            html = handler()
            if retention > 0:
                etag = getMD5(str(html))
                cacheData(
                    key,
                    html,
                    etag,
                    int(retention),
                )
                web.header('Etag', etag)
                if DEBUG: print 'set cache'
            else:
                if DEBUG: print 'retention == 0'
                pass
    else:  # POST 与admin 请求不缓存
        if DEBUG: print 'post no cache'
        html = handler()

    return html
Esempio n. 9
0
def increaseVersionNum():
    curr_v = sh.getSiteConfig(CONFIG_KEY)
    next_v = int(curr_v) + 1 if curr_v else 0
    sh.setSiteConfig(CONFIG_KEY, next_v)
Esempio n. 10
0
 def getChineseColumnName(self):
     config = sh.getSiteConfig('editor_column_ch_name')
     return dict([sh.splitAndStrip(c) for c in config.split('\n') if len(sh.splitAndStrip(c))==2]) \
             if config else sh.storage()
Esempio n. 11
0
 def getAppKey(self):
     return sh.getSiteConfig('oauth2_appkey_%s' % self.SITE_NAME.lower())
Esempio n. 12
0
 def getAppID(self):
     return sh.getSiteConfig('oauth2_appid_%s' % self.SITE_NAME.lower())
Esempio n. 13
0
 def getAppID(self):
     return sh.getSiteConfig('oauth2_appid_%s' % self.SITE_NAME.lower())
Esempio n. 14
0
 def getAppKey(self):
     return sh.getSiteConfig('oauth2_appkey_%s' % self.SITE_NAME.lower())
Esempio n. 15
0
 def getChineseColumnName(self):
     config = sh.getSiteConfig('editor_column_ch_name')
     return dict([sh.splitAndStrip(c) for c in config.split('\n') if len(sh.splitAndStrip(c))==2]) \
             if config else sh.storage()
Esempio n. 16
0
def increaseVersionNum():
    curr_v = sh.getSiteConfig(CONFIG_KEY)
    next_v = int(curr_v) + 1 if curr_v else 0
    sh.setSiteConfig(CONFIG_KEY, next_v)