Пример #1
0
def download():
    si = StringIO.StringIO()
    cw = unicodecsv.writer(si)
    cw.writerow([u"Name", u"出生年月", u"性别", u"身高", u"体重", u"颈围",
                 u"肩宽", u"臂长", u"臂围", u"胸围", u"腰围", u"臀围",
                 u"腿长", u"大腿围"])
    for info in Info.all():
        cw.writerow(info.str_infos)
    output = make_response(si.getvalue())
    output.headers["Content-Disposition"] = "attachment; filename=befit.csv"
    output.headers["Content-type"] = "text/csv"
    return output
Пример #2
0
def sweep():
    """清理所有已读信息"""
    u = current_user()
    owner_id = int(request.form.get('owner_id', -1))
    owner = cached_user_id2user(owner_id)
    if owner is not None:
        if owner_id == u.id:
            read_infos = Info.all(receiver_id=owner_id, been_read=True)
            with data_cache.pipeline(transaction=False) as pipe:
                for i in read_infos:
                    Info.delete(i)
                    key = 'user_id_{}.received_info'.format(u.id)
                    pipe.delete(key)
                pipe.execute()

    return redirect(url_for('.info'))
Пример #3
0
def set_read():
    """一键标记所有信息为已读"""
    u = current_user()
    owner_id = int(request.form.get('owner_id', -1))
    owner = cached_user_id2user(owner_id)
    if owner is not None:
        if owner_id == u.id:
            unread_info = Info.all(receiver_id=owner_id, been_read=False)

            with data_cache.pipeline(transaction=False) as pipe:
                for i in unread_info:
                    i.been_read = True
                    i.save()
                    key = 'info_id_{}.info'.format(i.id)
                    pipe.delete(key)
                pipe.execute()

    return redirect(url_for('.info'))
Пример #4
0
def cached_received_info(user_id):
    """缓存该用户收到的所有系统消息的id"""
    key = 'user_id_{}.received_info'.format(user_id)
    try:
        # 缓存命中
        info_ids_json = data_cache[key]
    except KeyError:
        # 缓存未命中,数据库中拉取数据model
        info_models = list(Info.all(receiver_id=user_id))
        info_models.sort(key=lambda x: x.created_time, reverse=True)
        # 加到redis缓存中的是id
        data_cache.set(key, json.dumps([i.id for i in info_models]), 3600)
        log('缓存丢失,向数据库拉取数据,重建缓存')
        return info_models
    else:
        # 从缓存中拿到多个Info id
        info_models = [
            cached_info_id2info(info_id)
            for info_id in json.loads(info_ids_json)
        ]
        log('缓存命中,直接使用')
        return info_models
Пример #5
0
def index():
    return tpl("admin.html", infos=Info.all())