当前位置: 首页>>代码示例>>Python>>正文


Python user.User类代码示例

本文整理汇总了Python中past.model.user.User的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _save_user_and_token

def _save_user_and_token(token_dict, user_info, openid_type):
    ua = UserAlias.get(openid_type, user_info.get_user_id())
    if not ua:
        if not g.user:
            ua = UserAlias.create_new_user(openid_type,
                    user_info.get_user_id(), user_info.get_nickname())
        else:
            ua = UserAlias.bind_to_exists_user(g.user, 
                    openid_type, user_info.get_user_id())
    if not ua:
        return None

    ##设置个人资料(头像等等)
    u = User.get(ua.user_id)
    u.set_avatar_url(user_info.get_avatar())
    u.set_icon_url(user_info.get_icon())

    ##保存access token
    if openid_type == config.OPENID_TYPE_DICT[config.OPENID_TWITTER]:
        OAuth2Token.add(ua.id, token_dict.get("access_token"), 
                token_dict.get("access_token_secret", ""))
    else:
        OAuth2Token.add(ua.id, token_dict.get("access_token"), 
                token_dict.get("refresh_token", ""))
    ##set cookie,保持登录状态
    if not g.user:
        g.user = User.get(ua.user_id)
        set_user_cookie(g.user, session)
    
    return g.user
开发者ID:perryhau,项目名称:thepast,代码行数:30,代码来源:views.py

示例2: remove_user

def remove_user(uid, clear_status=True):
    user = User.get(uid)
    if not user:
        print "---no user:%s" % uid

    suicide_log.info("---- delete from user, uid=%s" % uid)
    db_conn.execute("delete from user where id=%s", uid)
    db_conn.commit()
    User._clear_cache(uid)

    if clear_status:
        cursor = db_conn.execute("select id from status where user_id=%s", uid)
        if cursor:
            rows = cursor.fetchall()
            for row in rows:
                sid = row[0]
                suicide_log.info("---- delete status text, sid=%s" % sid)
                RawStatus.remove(sid)

        suicide_log.info("---- delete from status, uid=" % uid)
        db_conn.execute("delete from status where user_id=%s", uid)
        db_conn.commit()
        Status._clear_cache(uid, None)

    suicide_log.info("---- delete from passwd, uid=%s" % uid)
    db_conn.execute("delete from passwd where user_id=%s", uid)
    suicide_log.info("---- delete from sync_task, uid=%s" % uid)
    db_conn.execute("delete from sync_task where user_id=%s", uid)
    suicide_log.info("---- delete from user_alias, uid=%s" % uid)
    db_conn.execute("delete from user_alias where user_id=%s", uid)
    db_conn.commit()
开发者ID:Jeffwan,项目名称:thepast,代码行数:31,代码来源:remove_user.py

示例3: user_explore

def user_explore():
    g.count = 24
    user_ids = User.get_ids(start=g.start, limit=g.count)
    users = [User.get(x) for x in user_ids]
    users = [x for x in users if x.get_profile_item('user_privacy') != consts.USER_PRIVACY_PRIVATE]
    return render_template("user_explore.html",
            users=users, config=config)
开发者ID:icycore,项目名称:thepast,代码行数:7,代码来源:views.py

示例4: home

def home():
    user_ids = User.get_ids(limit=10000)

    user = None
    i = 0
    while i <= 3:
        random_uid = random.choice(user_ids)
        user = User.get(random_uid)
        r = check_access_user(user)
        if not r:
            break
        i+=1

    if user:
        history_ids = Status.get_ids(user.id, start=0, limit=20)
        status_list = Status.gets(history_ids)
        status_list  = statuses_timelize(status_list)
        intros = [user.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
        intros = filter(None, intros)
    else:
        status_list = []
        intros = []

    if g.user:
        sync_list = get_sync_list(g.user)
    else:
        sync_list = []

    d = defaultdict(list)
    for x in status_list:
        t = x.create_time.strftime("%Y年%m月%d日")
        d[t].append(x)
    history_status = d

    return render_template("v2/explore.html", **locals())
开发者ID:HengeSense,项目名称:thepast,代码行数:35,代码来源:user_past.py

示例5: remove_user

def remove_user(uid):
    user = User.get(uid)
    if not user:
        print '---no user:%s' % uid

    print "---- delete from user, uid=", uid
    db_conn.execute("delete from user where id=%s", uid)
    db_conn.commit()
    User._clear_cache(uid)

    cursor = db_conn.execute("select id from status where user_id=%s", uid)
    if cursor:
        rows = cursor.fetchall()
        for row in rows:
            sid = row[0]
            print "---- delete mongo text, sid=", sid
            RawStatus.remove(sid)

    print "---- delete from status, uid=", uid
    db_conn.execute("delete from status where user_id=%s", uid)
    db_conn.commit()
    Status._clear_cache(uid, None)

    print "---- delete from passwd, uid=", uid
    db_conn.execute("delete from passwd where user_id=%s", uid)
    print "---- delete from sync_task, uid=", uid
    db_conn.execute("delete from sync_task where user_id=%s", uid)
    print "---- delete from user_alias, uid=", uid
    db_conn.execute("delete from user_alias where user_id=%s", uid)
    db_conn.commit()
开发者ID:geekontheway,项目名称:thepast,代码行数:30,代码来源:remove_user.py

示例6: send_today_in_history

def send_today_in_history(user_id):
    u = User.get(user_id)
    if not u:
        return

    setting = u.get_profile_item("email_remind_today_in_history")
    if setting == 'N':
        print '---user %s does not like to receive remind mail' % u.id
        return

    email = u.get_email()
    if not email:
        print '---- user %s no email' % u.id
        return
    
    yesterday_ids = get_status_ids_yesterday(u.id, 
            day=(datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y-%m-%d"))
    status_of_yesterday = Status.gets(yesterday_ids)

    history_ids = get_status_ids_today_in_history(u.id, 
            day=datetime.datetime.now().strftime("%Y-%m-%d"))
    status_of_today_in_history = Status.gets(history_ids)

    intros = [u.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
    intros = filter(None, intros)
    
    history_ids = get_status_ids_today_in_history(u.id, 
            day=datetime.datetime.now().strftime("%Y-%m-%d"))
    d = {}
    for s in Status.gets(history_ids):
        t = s.create_time.strftime("%Y-%m-%d")
        if d.has_key(t):
            d[t].append(s)
        else:
            d[t] = [s]
    status_of_today_in_history = d
    from past.consts import YESTERDAY


    if not (status_of_yesterday or status_of_today_in_history):
        print '--- user %s has no status in history' % u.id
        return

    from jinja2 import Environment, PackageLoader
    env = Environment(loader=PackageLoader('past', 'templates'))
    env.filters['wrap_long_line'] = wrap_long_line
    env.filters['nl2br'] = filters.nl2br
    env.filters['clear_html_element'] = clear_html_element
    t = env.get_template('mail.html')
    m = t.module


    html = m.status_in_past(status_of_yesterday, status_of_today_in_history, YESTERDAY, config, intros)
    html = html.encode("utf8")

    subject = '''来自thepast.me的提醒 %s''' % datetime.datetime.now().strftime("%Y-%m-%d")
    text = ''
    
    print '--- send reminding to %s %s' %(user_id, email)
    send_mail(["%s" % email], "Today of The Past<[email protected]>", subject, text, html, files=[], server="localhost")
开发者ID:MistShi,项目名称:thepast,代码行数:60,代码来源:send_reminding.py

示例7: cmd_bind

def cmd_bind(from_user, thepast_id):
    u = User.get(thepast_id)
    if not u:
        return "不存在这个id啊,是不是搞错了啊"

    UserWeixin.add(u.id, from_user)
    return "绑定成功了,输入「past 日期」查看过往的碎碎念"
开发者ID:EdwinHi,项目名称:thepast,代码行数:7,代码来源:view.py

示例8: user_by_domain

def user_by_domain(uid):
    u = User.get(uid)
    if not u:
        abort(404, "no such user")

    r = check_access_user(u)
    if r:
        flash(r[1].decode("utf8"), "tip")
        return redirect(url_for("home"))

    ids = Status.get_ids(user_id=u.id, start=g.start, limit=g.count, cate=g.cate)
    status_list = Status.gets(ids)
    if g.user and g.user.id == uid:
        pass
    elif g.user and g.user.id != uid:
        status_list = [x for x in status_list if x.privacy() != consts.STATUS_PRIVACY_PRIVATE]
    elif not g.user:
        status_list = [x for x in status_list if x.privacy() == consts.STATUS_PRIVACY_PUBLIC]
        
    status_list  = statuses_timelize(status_list)
    tags_list = []
    intros = [u.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
    intros = filter(None, intros)

    if g.user:
        sync_list = get_sync_list(g.user)
    else:
        sync_list = []

    return render_template("timeline.html", user=u, unbinded=[], 
            tags_list=tags_list, intros=intros, 
            status_list=status_list, config=config, sync_list=sync_list)
开发者ID:loosky,项目名称:thepast,代码行数:32,代码来源:timelines.py

示例9: visual

def visual(uid):
    u = User.get(uid)
    if not u:
        abort(404, "no such user")

    return render_template("visual_timeline.html", user=u, unbinded=[], 
            config=config)
开发者ID:funfunsay,项目名称:thepast,代码行数:7,代码来源:timelines.py

示例10: before_request

def before_request():
    g.user = auth_user_from_session(session)
    g.user = User.get(8)
    if g.user:
        g.user_alias = UserAlias.gets_by_user_id(g.user.id)
    else:
        g.user_alias = None

    if g.user:
        unbinded = list(set(config.OPENID_TYPE_DICT.values()) - 
                set([ua.type for ua in g.user.get_alias()]) - set([config.OPENID_TYPE_DICT[config.OPENID_THEPAST]]))
        tmp = {}
        for k, v in config.OPENID_TYPE_DICT.items():
            tmp[v] = k
        g.unbinded = [[x, tmp[x], config.OPENID_TYPE_NAME_DICT[x]] for x in unbinded]

        expired_providers = []
        for t in [ua.type for ua in g.user.get_alias()]:
            p = g.user.get_thirdparty_profile(t)
            if p and p.get("expired"):
                _ = [t, config.OPENID_TYPE_DICT_REVERSE.get(t), config.OPENID_TYPE_NAME_DICT.get(t, "")]
                expired_providers.append(_)
        if expired_providers:
            msg = " ".join([x[-1] for x in expired_providers])
            flash(u"你的 %s 授权已经过期了,会影响数据同步,你可以重新授权 :)" % msg, "tip")
    else:
        g.unbinded = None

    g.start = int(request.args.get('start', 0))
    g.count = int(request.args.get('count', 30))
    g.cate = request.args.get("cate", "")
    if not g.cate.isdigit():
        g.cate = ""
开发者ID:mobiwolf,项目名称:thepast,代码行数:33,代码来源:views.py

示例11: generate_pdf

def generate_pdf(filename, uid, start, count, cate=None, with_head=True, capacity=50*1024):

    #########Set FONT################
    from xhtml2pdf.default import DEFAULT_FONT
    from xhtml2pdf.document import pisaDocument
    from reportlab.pdfbase import pdfmetrics
    from reportlab.pdfbase.ttfonts import TTFont

    pdfmetrics.registerFont(TTFont('zhfont', os.path.join(app.root_path, 'static/font/yahei-consolas.ttf')))
    DEFAULT_FONT["helvetica"] = "zhfont"
    css = open(os.path.join(app.root_path, "static/css/pdf.css")).read()

    #result = StringIO.StringIO()
    full_file_name = get_pdf_full_filename(filename)
    if not full_file_name:
        return None
    result = open(full_file_name, 'wb', 1024*1000)

    user = User.get(uid)
    if not user:
        return None

    # get status
    ids = Status.get_ids(user_id=uid, start=start, limit=count, cate=cate)
    status_list = Status.gets(ids)
    _html = render(user, status_list, with_head)
    _pdf = pisaDocument(_html, result, default_css=css, link_callback=link_callback, capacity=capacity)
    result.close()

    if not _pdf.err:
        return full_file_name
    else:
        return None
开发者ID:funfunsay,项目名称:thepast,代码行数:33,代码来源:pdf.py

示例12: send_pdf

def send_pdf(user_id):
    u = User.get(user_id)

    if not u:
        return

    setting = u.get_profile_item("email_remind_today_in_history")
    if setting == 'N':
        print '---user %s does not like to receive remind mail' % u.id
        return

    email = u.get_email()
    if not email:
        print '---- user %s no email' % u.id
        return

    subject = '''你在thepast.me上的timeline PDF版本'''
    text = '''Hi,感谢你使用thepast.me来聚合、管理、备份自己的timeline.

离线PDF版本现在可以下载了,请猛击 http://thepast.me/%s/pdf

http://thepast.me | 个人杂志计划
thanks''' % user_id
    
    print '--- send pdf file to %s %s' %(user_id, email)
    send_mail(["%s" % email], "thepast<[email protected]>", subject, text, "")
开发者ID:daqing15,项目名称:thepast,代码行数:26,代码来源:send_reminding.py

示例13: user_notes

def user_notes(uid):
    
    user = User.get(uid)
    if not user:
        abort(403, "no_such_user")

    return redirect("/user/%s?cate=%s" % (uid, config.CATE_THEPAST_NOTE))
开发者ID:mobiwolf,项目名称:thepast,代码行数:7,代码来源:note.py

示例14: user_more_by_domain

def user_more_by_domain(uid):
    u = User.get(uid)
    if not u:
        abort(404, "no such user")

    r = check_access_user(u)
    if r:
        abort(400, "no priv to access")

    ids = Status.get_ids(user_id=u.id, start=g.start, limit=g.count, cate=g.cate)
    status_list = Status.gets(ids)
    if g.user and g.user.id == uid:
        pass
    elif g.user and g.user.id != uid:
        status_list = [x for x in status_list if x.privacy() != consts.STATUS_PRIVACY_PRIVATE]
    elif not g.user:
        status_list = [x for x in status_list if x.privacy() == consts.STATUS_PRIVACY_PUBLIC]
        
    status_list  = statuses_timelize(status_list)
    intros = [u.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
    intros = filter(None, intros)

    if g.user:
        sync_list = get_sync_list(g.user)
    else:
        sync_list = []

    now = datetime.datetime.now().strftime("%Y年%m月%d日 %H:%M:%S")
    return render_template("v2/user_more.html", user=u, intros=intros, 
            status_list=status_list, config=config, sync_list=sync_list, 
            now = now)
开发者ID:HengeSense,项目名称:thepast,代码行数:31,代码来源:user_past.py

示例15: tag

def tag(uid):
    u = User.get(uid)
    if not u:
        abort(404, "no such user")
    count = min(g.count, 50)
    kws = get_keywords(u.id, count)
    return ",".join([x[0] for x in kws])
开发者ID:icycore,项目名称:thepast,代码行数:7,代码来源:views.py


注:本文中的past.model.user.User类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。