예제 #1
0
    def get_form_map(cls, meta_name):
        item_map = []
        word_cloud = []
        if redis_cli.exists('form_service:{}:map'.format(meta_name)):
            item_map = json.loads(
                redis_cli.get('form_service:{}:map'.format(meta_name)))
        if redis_cli.exists('form_service:{}:word_cloud'.format(meta_name)):
            word_cloud = json.loads(
                redis_cli.get('form_service:{}:word_cloud'.format(meta_name)))

        return {'item_map': item_map, 'word_cloud': word_cloud}
예제 #2
0
def pop_submission_task():
    task_id = redis_cli.lpop(__key_submission_task_queue)
    if task_id is not None:
        key = __key_submission_task(task_id.decode('utf8'))
        task = loads(redis_cli.get(key))
        redis_cli.delete(key)
        return task
예제 #3
0
def activate_email():
    parser = reqparse.RequestParser()
    parser.add_argument('e', location='args', type=str, required=True)
    parser.add_argument('c', location='args', type=str, required=True)
    args = parser.parse_args()

    try:
        email = base64.urlsafe_b64decode(args['e'])
    except Exception as e:
        return '无效链接'

    user = UserModel.query.filter_by(email=email).first()
    if user is None:
        return '无效链接'

    if user.activated:
        return '用户已激活'

    activated = args['c'] == redis_cli.get(__key_activate_email_code(email))

    if activated:
        user.activated = True
        db.session.commit()

    return render_template('activate_email.html',
                           email=email,
                           activated=activated)
예제 #4
0
def count_visits(hostname):
    total_visits_count = redis_cli.get('visits')
    if not total_visits_count:
        total_visits_count = 0
        redis_cli.set('visits', total_visits_count)
    else:
        total_visits_count = int(total_visits_count) + 1
        redis_cli.set('visits', total_visits_count)

    host_visits_count = redis_cli.get(hostname)
    if not host_visits_count:
        host_visits_count = 0
        redis_cli.set(hostname, host_visits_count)
    else:
        host_visits_count = int(host_visits_count) + 1
        redis_cli.set(hostname, host_visits_count)

    return total_visits_count, host_visits_count
예제 #5
0
 def read_ret(cls, jid):
     try:
         keys = redis_cli.keys('*:{0}'.format(jid))
         ret = {}
         for k in keys:
             value = redis_cli.get(k)
             ret.setdefault(k, json.loads(value))
         return ret
     except Exception as ex:
         from app import app
         import traceback
         app.logger.warn(str(traceback.print_exc()))
예제 #6
0
    def get_page_data(cls):
        data_dict = {
            "sys:form_num": {},
            "sys:guider_num": 0,
            "sys:notice_lesson_num": 0,
            "sys:submitted_form": 0,
            "sys:wait_submitted_form": 0
        }

        submitted_form = redis_cli.get("sys:submitted_form")
        if submitted_form is None:
            submitted_form = 0
        else:
            submitted_form = json.loads(submitted_form)

        wait_submitted_form = redis_cli.get("sys:wait_submitted_form")
        if wait_submitted_form is None:
            wait_submitted_form = 0
        else:
            wait_submitted_form = json.loads(wait_submitted_form)

        data_dict["sys:submitted_form"] = wait_submitted_form
        data_dict["sys:submitted_form"] = submitted_form
        now_term = TermService.get_now_term()
        data_dict["sys:guider_num"] = dao.Supervisor.count(
            query_dict={'term': [now_term['name']]})
        data_dict["sys:notice_lesson_num"] = dao.NoticeLesson.count(
            query_dict={'term': [now_term['name']]})
        form_num = {}
        for unit in UNIT_LIST:
            num = redis_cli.get('sys:form_num:{unit}'.format(unit=unit))
            if not num:
                num = 0
            form_num[unit] = int(num)
        data_dict["sys:form_num"] = form_num
        return data_dict
예제 #7
0
def _get_user_oauth_state(provider_name):
    if current_user.is_authenticated:
        return redis_cli.get(
            __key_user_oauth_state(provider_name, current_user))
    return ''
예제 #8
0
    def get_page_data(cls):
        data_dict = {
            "sys:form_num": {},
            "sys:current_term_form_num": {},
            "sys:guider_num": 0,
            "sys:notice_lesson_num": 0,
            "sys:submitted_form": 0,
            "sys:wait_submitted_form": 0,
            "sys:form_unsatisfy_num": 0,
            "sys:form_just_num": 0,
            "sys:form_statisfy_num": 0,
            "sys:current_term_submitted_form": 0,
            "sys:current_term_wait_submitted_form": 0,
        }

        # 计算已提交的问卷
        submitted_form = redis_cli.get("sys:submitted_form")
        if submitted_form is None:
            submitted_form = 0
        else:
            submitted_form = json.loads(submitted_form)

        # 计算当前学期已提交的问卷数量
        current_term_submitted_form = redis_cli.get(
            "sys:current_term_submitted_form")
        if current_term_submitted_form is None:
            current_term_submitted_form = 0
        else:
            current_term_submitted_form = json.loads(
                current_term_submitted_form)

        # 计算当前学期【待提交、草稿】的问卷总数
        current_term_wait_submitted_form = redis_cli.get(
            "sys:current_term_wait_submitted_form")
        if current_term_wait_submitted_form is None:
            current_term_wait_submitted_form = 0
        else:
            current_term_wait_submitted_form = json.loads(
                current_term_wait_submitted_form)

        # 计算带提交
        wait_submitted_form = redis_cli.get("sys:wait_submitted_form")
        if wait_submitted_form is None:
            wait_submitted_form = 0
        else:
            wait_submitted_form = json.loads(wait_submitted_form)

        form_statisfy_num = redis_cli.get("sys:form_statisfy_num")
        form_just_num = redis_cli.get("sys:form_just_num")
        form_unsatisfy_num = redis_cli.get("sys:form_unsatisfy_num")

        data_dict["sys:form_statisfy_num"] = json.loads(
            form_statisfy_num) if form_statisfy_num else 0
        data_dict["sys:form_just_num"] = json.loads(
            form_just_num) if form_just_num else 0
        data_dict["sys:form_unsatisfy_num"] = json.loads(
            form_unsatisfy_num) if form_unsatisfy_num else 0

        data_dict["sys:wait_submitted_form"] = wait_submitted_form
        data_dict["sys:submitted_form"] = submitted_form
        data_dict[
            "sys:current_term_submitted_form"] = current_term_submitted_form
        data_dict[
            "sys:current_term_wait_submitted_form"] = current_term_wait_submitted_form
        now_term = TermService.get_now_term()
        data_dict["sys:guider_num"] = dao.Supervisor.count(
            query_dict={'term': [now_term['name']]})
        data_dict["sys:notice_lesson_num"] = dao.NoticeLesson.count(
            query_dict={'term': [now_term['name']]})
        form_num = {}
        for unit in UNIT_LIST:
            num = redis_cli.get('sys:form_num:{unit}'.format(unit=unit))
            if not num:
                num = 0
            form_num[unit] = int(num)
        data_dict["sys:form_num"] = form_num

        current_term_form_num = {}
        for unit in UNIT_LIST:
            current_term_num = redis_cli.get(
                'sys:current_term_form_num:{unit}'.format(unit=unit))
            if not current_term_num:
                current_term_num = 0
            current_term_form_num[unit] = int(current_term_num)
        data_dict['sys:current_term_form_num'] = current_term_form_num
        return data_dict