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


Python user.UserAlias类代码示例

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


在下文中一共展示了UserAlias类的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: before_request

def before_request():
    g.user = auth_user_from_session(session)
    #g.user = User.get(2)
    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 授权已经过期了,会影响数据同步,你可以重新授权 :)", "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:icycore,项目名称:thepast,代码行数:33,代码来源:views.py

示例3: get_client

 def get_client(cls, user_id):                                                  
     alias = UserAlias.get_by_user_and_type(user_id,                            
             config.OPENID_TYPE_DICT[config.OPENID_QQ])                       
     if not alias:                                                              
         return None                                                            
                                                                                
     return cls(alias.alias)
开发者ID:Ailocodjam,项目名称:thepast,代码行数:7,代码来源:api_client.py

示例4: sync_wordpress

def sync_wordpress(t, refresh=False):
    if not t:
        log.warning('no_wordpress_sync_task')
        return

    #一个人可以有多个wordpress的rss源地址
    rs = UserAlias.gets_by_user_id(t.user_id)
    uas = []
    for x in rs:
        if x.type == config.OPENID_TYPE_DICT[config.OPENID_WORDPRESS]:
            uas.append(x)
    if not uas:
        log.warning('no_wordpress_alias')
        return
    for ua in uas:
        try:
            client = Wordpress(ua.alias)
            rs = client.get_feeds(refresh)
            if rs:
                log.info("get wordpress succ, result length is:%s" % len(rs))
                for x in rs:
                    Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
                return 
        except:
            import traceback; print traceback.format_exc()
开发者ID:Ailocodjam,项目名称:thepast,代码行数:25,代码来源:jobs.py

示例5: generate

def generate(user_id, date, order='asc'):
    try:
        uas = UserAlias.gets_by_user_id(user_id)
        if not uas:
            return

        start_date = datetime.datetime(date.year, date.month, 1)
        end_date = datetime.datetime(date.year, date.month,
                calendar.monthrange(date.year, date.month)[1], 23, 59, 59)
        pdf_filename = get_pdf_filename(user_id, date.strftime("%Y%m"))
        print '----generate pdf:', start_date, ' to ', end_date, ' file is', pdf_filename

        if is_pdf_file_exists(pdf_filename):
            print '---- %s exists, so ignore...' % pdf_filename
            return

        status_ids = Status.get_ids_by_date(user_id, start_date, end_date)[:900]
        if order == 'asc':
            status_ids = status_ids[::-1]
        if not status_ids:
            print '----- status ids is none', status_ids
            return
        generate_pdf(pdf_filename, user_id, status_ids, capacity=-1)
        if not is_pdf_file_exists(pdf_filename):
            print '----%s generate pdf for user:%s fail' % (datetime.datetime.now(), user_id)
        else:
            print '----%s generate pdf for user:%s succ' % (datetime.datetime.now(), user_id)
    except Exception, e:
        import traceback
        print '%s %s' % (datetime.datetime.now(), traceback.format_exc())
开发者ID:dianso,项目名称:thepast,代码行数:30,代码来源:generate_pdf.py

示例6: _save_user_and_token

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

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

    ##把各个第三方的uid保存到profile里面
    k = openid_type
    v = {
        "uid": thirdparty_user.get_uid(), 
        "name": thirdparty_user.get_nickname(), 
        "intro": thirdparty_user.get_intro(),
        "signature": thirdparty_user.get_signature(),
        "avatar": thirdparty_user.get_avatar(),
        "icon": thirdparty_user.get_icon(),
        "email": thirdparty_user.get_email(),
        "first_connect": "Y" if first_connect else "N",
    }
    u.set_profile_item(k, json_encode(v))

    ##保存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:loosky,项目名称:thepast,代码行数:46,代码来源:view.py

示例7: before_request

def before_request():
    g.user = auth_user_from_session(session)
    if g.user:
        g.user_alias = UserAlias.gets_by_user_id(g.user.id)
    else:
        g.user_alias = None
    g.start = int(request.args.get("start", 0))
    g.count = int(request.args.get("count", 30))
    g.cate = request.args.get("cate", None)
开发者ID:kadefor,项目名称:thepast,代码行数:9,代码来源:views.py

示例8: get_client

    def get_client(cls, user_id):
        alias = UserAlias.get_by_user_and_type(user_id, config.OPENID_TYPE_DICT[config.OPENID_DOUBAN])
        if not alias:
            return None

        token = OAuth2Token.get(alias.id)
        if not token:
            return None

        return cls(alias.alias, token.access_token, token.refresh_token)
开发者ID:geekontheway,项目名称:thepast,代码行数:10,代码来源:api_client.py

示例9: __init__

    def __init__(self, alias, apikey=None, apikey_secret=None, access_token=None, access_token_secret=None):
        ua = UserAlias.get(config.OPENID_TYPE_DICT[config.OPENID_TWITTER], alias)
        self.apikey = apikey if apikey is not None else config.APIKEY_DICT[config.OPENID_TWITTER].get("key")
        self.apikey_secret = apikey_secret if apikey_secret is not None else config.APIKEY_DICT[config.OPENID_TWITTER].get("secret")
        
        token = OAuth2Token.get(ua.id)
        self.access_token = access_token if access_token is not None else token.access_token
        self.access_token_secret = access_token_secret if access_token_secret is not None else token.refresh_token

        self.auth = tweepy.OAuthHandler(self.apikey, self.apikey_secret)        
        self.auth.set_access_token(self.access_token, self.access_token_secret)
开发者ID:Ailocodjam,项目名称:thepast,代码行数:11,代码来源:api_client.py

示例10: before_request

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

    if request.method == 'POST':
        try:
            g.start = int(request.form.get('start', 0))
        except ValueError:
            g.start = 0
        try:
            g.count = int(request.form.get('count', 24))
        except ValueError:
            g.count = 0
        g.cate = request.form.get("cate", "")
    else:
        try:
            g.start = int(request.args.get('start', 0))
        except ValueError:
            g.start = 0
        try:
            g.count = int(request.args.get('count', 24))
        except ValueError:
            g.count = 0
        g.cate = request.args.get("cate", "")
    g.cate = int(g.cate) if g.cate.isdigit() else ""
        
    if g.user:
        g.binds = [ua.type for ua in g.user.get_alias()]
        unbinded = list(set(config.OPENID_TYPE_DICT.values()) - 
                set(g.binds) - 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(_)
        g.expired = expired_providers
        if expired_providers:
            msg = " ".join([x[-1] for x in expired_providers])
            flash(u"你的 %s 授权已经过期了,会影响数据同步,你可以重新授权 :)" % msg, "tip")
    else:
        g.unbinded = None
开发者ID:EdwinHi,项目名称:thepast,代码行数:49,代码来源:__init__.py

示例11: bind

def bind(uid, feed_uri):
    user = User.get(uid)
    if not user:
        print 'no user'
        return
    ua = UserAlias.bind_to_exists_user(user, 
            config.OPENID_TYPE_DICT[config.OPENID_WORDPRESS], feed_uri)
    if not ua:
        print "no user alias"
    else:
        ##添加同步任务
        t = SyncTask.add(config.CATE_WORDPRESS_POST, user.id)
        t and TaskQueue.add(t.id, t.kind)
        ##删除confiration记录
        mc.delete("wordpress_bind:%s" %user.id)
开发者ID:Ailocodjam,项目名称:thepast,代码行数:15,代码来源:bind_wordpress.py

示例12: before_request

def before_request():
    g.user = auth_user_from_session(session)
    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()]))
        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]
    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", None)
开发者ID:puzzlega,项目名称:thepast,代码行数:19,代码来源:views.py

示例13: __init__

    def __init__(self, alias=None, 
            apikey=None, apikey_secret=None, redirect_uri=None, 
            token=None, token_secret=None, openid=None, openkey=None):

        self.consumer_key = apikey or config.APIKEY_DICT[config.OPENID_QQ]['key']
        self.consumer_secret = apikey_secret or config.APIKEY_DICT[config.OPENID_QQ]['secret']
        self.callback = redirect_uri or config.APIKEY_DICT[config.OPENID_QQ]['redirect_uri']

        self.token = token
        self.token_secret = token_secret
        #XXX:no use?
        self.openid = openid
        self.openkey = openkey

        self.alias=alias
        if alias:
            self.user_alias = UserAlias.get(
                    config.OPENID_TYPE_DICT[config.OPENID_QQ], alias)
        else:
            self.user_alias = None
开发者ID:icycore,项目名称:thepast,代码行数:20,代码来源:qqweibo.py

示例14: sync

def sync(cates):
    cates = cates.split("|")
    if not (cates and isinstance(cates, list)):
        return "no cates"

    cates = filter(lambda x: x in [str(y) for y in config.CATE_LIST], cates)
    if not cates:
        abort(400, "not support such cates")

    provider = category2provider(int(cates[0]))
    redir = "/connect/%s" % provider

    if not g.user:
        print '--- no g.user...'
        return redirect(redir)

    if request.form.get("remove"):
        for c in cates:
            r = SyncTask.gets_by_user_and_cate(g.user, str(c))
            for x in r:
                x.remove()
        return json_encode({'ok':'true'})

    uas = UserAlias.gets_by_user_id(g.user.id)
    r = filter(lambda x: x.type == config.OPENID_TYPE_DICT[provider], uas)
    user_alias = r and r[0]
    
    if not user_alias:
        print '--- no user_alias...'
        return json_encode({'ok':'false', 'redir':redir})

    token = OAuth2Token.get(user_alias.id)   
    
    if not token:
        print '--- no token...'
        return json_encode({'ok':'false', 'redir':redir})

    for c in cates:
        SyncTask.add(c, g.user.id)
    
    return json_encode({'ok':'true'})
开发者ID:icycore,项目名称:thepast,代码行数:41,代码来源:views.py

示例15: __init__

    def __init__(self, provider=None, apikey=None, apikey_secret=None, redirect_uri=None, 
            scope=None, state=None, display=None, 
            alias=None, access_token=None, refresh_token=None):

        self.provider = provider
        self.apikey = apikey
        self.apikey_secret = apikey_secret
        self.redirect_uri = redirect_uri

        self.scope = scope
        self.state = state
        self.display = display

        self.alias = alias
        if alias:
            self.user_alias = UserAlias.get(
                    config.OPENID_TYPE_DICT[provider], alias)
        else:
            self.user_alias = None
        self.access_token = access_token
        self.refresh_token = refresh_token
开发者ID:EdwinHi,项目名称:thepast,代码行数:21,代码来源:oauth2.py


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