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


Python User.objects方法代码示例

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


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

示例1: main

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
def main():
    #    user = random_user()
    #    with open(FILENAME, "w") as f:
    #        f.write(user.yaml())

    print 70 * "="
    user = User()
    user = read_user(FILENAME)

    print 70 * "="
    pprint(user.json())
    user.save()

    user.update(**{"set__username": "Hallo"})
    user.save()
    print User.objects(username="Hallo")
开发者ID:lee212,项目名称:cloudmesh,代码行数:18,代码来源:read.py

示例2: generate_completed_pie_graphs

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
 def generate_completed_pie_graphs(self, relation_dict, datatype):
     '''
     Generate a complete pie graph from the relation_dict in str type.
     If the relation_dict has no data, then return an empty string.
     If traking less than two sources or less than one targets,
     return an empty string.
     '''
     user = User.objects(name=cherrypy.session["user"]).first()
     # get source and target list based on the datatype
     if datatype == "news":
         sources = user.news_sources.keys()
         targets = user.news_targets.values()
     elif datatype == "twitter":
         sources = user.twitter_sources
         targets = user.twitter_targets
     # initialize the pie graph
     pie_graphs = ""
     i = 0
     # generate the pie graph only if traking more than two sources and more
     # than one targets
     if len(sources) >= 2 and targets:
         for target in targets:
             pie_graphs += self.generate_pie_graph(relation_dict, i, target)
             i += 1
     return pie_graphs
开发者ID:lixiao37,项目名称:team12-Project,代码行数:27,代码来源:userinterface.py

示例3: get_articles

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
    def get_articles(self, number=None):
        global username

        show_article_template = Template(filename='get_articles.html')
        sources = User.objects(name=username).first().news_sources
        targets = User.objects(name=username).first().news_targets
        articles = []

        for s in sources:
            articles += Article.objects(website=Website.objects(name=s).first()).only('title', 'url').all()
        for t in targets:
            articles += Article.objects(website=Website.objects(name=t).first()).only('title', 'url').all()

        if not number:
            number = len(articles)

        return show_article_template.render(articles=articles[ :int(number)])
开发者ID:lixiao37,项目名称:team12-Project,代码行数:19,代码来源:userinterface.py

示例4: process_login

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
def process_login():
    email, password = request.form['email'].lower(), request.form['password']
    user = User.objects(email=email).first()
    if user is None or not user.valid_password(password):
        return render_template('login.html', error="Wrong password or username.", email=email)
    else:
        session['logged_in'] = user.email
        inject_user()
        load_user()
        return redirect('/')
开发者ID:halflings,项目名称:etic-intervenants,代码行数:12,代码来源:web.py

示例5: check_credentials

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
def check_credentials(username, password):
    """Verifies username and password.
    Returns None on success or a string describing the error on failure"""
    # Converts the password to hash md5
    p = hashlib.md5()
    p.update(password)

    # See if the username is in the database, also if the password is correct
    if User.objects(Q(name=username) & Q(password=p.hexdigest())):
        return None
    else:
        return u"Username or password is incorrect or not found in database."
开发者ID:lixiao37,项目名称:team12-Project,代码行数:14,代码来源:authenticator.py

示例6: remove_reviewer

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
 def remove_reviewer(cls, username):
     if username:
         try:
             user = User.objects(username=username).first()
             if user:
                 try:
                     found = Committee.objects(reviewers__contains=user)
                     if found:
                         Committee.objects().update_one(pull__reviewers=user)
                         User.objects(username=username).update_one(pull__roles="reviewer")
                         Console.info("User `{0}` removed as Reviewer.".format(username))
                     else:
                         Console.error("Please specify a valid user name.")
                 except:
                     Console.info("Reviewer {0} removal failed.".format(username))
             else:
                 Console.error("Please specify a valid user")
         except:
             Console.error("Oops! Something went wrong while trying to remove reviewer")
     else:
         Console.error("Please specify a reviewer name to be removed.")
     pass
开发者ID:rajaramcomputers,项目名称:management,代码行数:24,代码来源:committee.py

示例7: add_reviewer

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
 def add_reviewer(cls, username):
     if username:
         try:
             user = User.objects(username=username).first()
             if user:
                 try:
                     found = Committee.objects(reviewers__contains=user)
                     if not found:
                         Committee.objects().update_one(push__reviewers=user)
                         User.objects(username=username).update_one(push__roles="reviewer")
                         Console.info("User {0} added as Reviewer.".format(username))
                     else:
                         Console.error("User {0} already exists as a reviewer.".format(username))
                 except:
                     print sys.exc_info()
                     Console.info("Reviewer {0} addition failed.".format(username))
             else:
                 Console.error("Please specify a valid user")
         except:
             print sys.exc_info()
             Console.error("Oops! Something went wrong while trying to add project reviewer")
     else:
         Console.error("Please specify a reviewer name to be added.")
     pass
开发者ID:rajaramcomputers,项目名称:management,代码行数:26,代码来源:committee.py

示例8: generate_basic_graphs

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
 def generate_basic_graphs(self, relation_dict):
     '''
     Generate several basic bar graphs from the relation_dict in str type.
     Each source has one bar graph.
     '''
     user = User.objects(name=cherrypy.session["user"]).first()
     news_targets = user.news_targets.values()
     # initialize the total basic graphs
     total_basic_graphs = ""
     graph_generator_template = Template(filename='basic_graph_generator.html')
     # add each basic bar graph into total basic graphs
     for source, target_count in relation_dict.iteritems():
         news_targets_str = str(news_targets).replace("u'","'")
         total_basic_graphs += graph_generator_template.render(source=source,
             targets=news_targets_str, target_count=target_count)
     return total_basic_graphs
开发者ID:lixiao37,项目名称:team12-Project,代码行数:18,代码来源:userinterface.py

示例9: twitter_analysis_graph

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
 def twitter_analysis_graph(self, source=None):
     graph_template = \
                Template(filename="twitter_analysis_graph.html", lookup=mylookup)
     count_map = {}
     if source:
         twitter_parser = TwitterParser(data=data)
         twitter_parser.authorize()
         count_map = twitter_parser.count_tweets_day(source)
         # mentions = twitter_parser.count_mentions(source)
         # mentions = dict(sorted(mentions.iteritems(),
                                                  # key=operator.itemgetter(1),
                                      # reverse=True)[:min(len(mentions), 10)])
     user = User.objects(name=cherrypy.session["user"]).first()
     sources = list(set(user.twitter_sources + user.twitter_targets))
     return graph_template.render(sources=sources, data=count_map, source=source,
                                           username=cherrypy.session["user"],
                                                       twitter_analysis="active")
开发者ID:lixiao37,项目名称:team12-Project,代码行数:19,代码来源:userinterface.py

示例10: beta_twitter_graphs

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
 def beta_twitter_graphs(self, source=None):
     beta_twitter_graphs_template = \
                Template(filename="beta_twitter_graph.html", lookup=mylookup)
     mentions = None
     if source:
         twitter_parser = TwitterParser(data=data)
         twitter_parser.authorize()
         mentions = twitter_parser.count_mentions(source)
         mentions = dict(sorted(mentions.iteritems(),
                                                  key=operator.itemgetter(1),
                                      reverse=True)[:min(len(mentions), 10)])
     user = User.objects(name=cherrypy.session["user"]).first()
     sources = list(set(user.twitter_sources + user.twitter_targets))
     return beta_twitter_graphs_template.render(sources=sources,
                                                data=mentions, source=source,
                                           username=cherrypy.session["user"],
                                                       beta_twitter="active")
开发者ID:lixiao37,项目名称:team12-Project,代码行数:19,代码来源:userinterface.py

示例11: setup_committee

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
 def setup_committee(cls):
     try:
         user = User.objects(username="super").first()
         count = Committee.objects.count()
         print count
         if count > 0:
             Console.error("Committee has already been setup.")
             return
         data = Committee(
             reviewers=[user],
             reviews=[]
         )
         data.save()
         Console.info("Committee setup successful.")
     except:
         print sys.exc_info()
         Console.error("Committee setup failed.")
开发者ID:rajaramcomputers,项目名称:management,代码行数:19,代码来源:committee.py

示例12: post

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
 def post(self):
     if not request.json:
         abort(400)
     user = User.objects(user_id=request.json['user_id'])
     if user.first() != None:
         return jsonify({'Result':'User ID already exists'})
     user = User(
         user_id= request.json['user_id'],
         cliqs= request.json['cliqs'],
         first_name= request.json['first_name'],
         last_name= request.json['last_name'],
         gender= request.json['gender'],
         phone= request.json['phone'],
         age= request.json['age'],
         _id= ObjectId()
     )
     user.save()
     return user.to_json()
开发者ID:dadavis21,项目名称:json_rest_api,代码行数:20,代码来源:userView.py

示例13: put

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
 def put(id):
     if not request.json:
         abort(400)
     user = User.objects(user_id=id)
     if user.first() == None:
         return jsonify({'Result':'User does not exist'})
     if 'cliqs' in request.json:
         user.update(cliqs, request.json['cliqs'])
     if 'first_name' in request.json:
         user.update(first_name, request.json['first_name'])
     if 'last_name' in request.json:
         user.update(last_name, request.json['last_name'])
     if 'gender' in request.json:
         user.update(gender=request.json['gender'])
     if 'phone' in request.json:
         user.update(phone, request.json['phone'])
     if 'age' in request.json:
         user.update(age, request.json['age'])
     return user.first().to_json()
开发者ID:dadavis21,项目名称:json_rest_api,代码行数:21,代码来源:userView.py

示例14: get_list

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
 def get_list(self, list_type = None):
     '''
     Gets the user's list accordingly and returns it to the tracking page
     '''
     user = User.objects(name=cherrypy.session["user"]).first()
     show_list_template = Template(filename='show_list.html')
     show_twitter_list_template = Template(filename='show_twitter_list.html')
     if 'news_source_list' == list_type:
         list_name = user.news_sources
         return show_list_template.render(list_name=list_name)
     elif 'news_target_list' == list_type:
         list_name = user.news_targets
         return show_list_template.render(list_name=list_name)
     elif 'twitter_source_list' == list_type:
         list_name = user.twitter_sources
         return show_twitter_list_template.render(list_name=list_name)
     elif 'twitter_target_list' == list_type:
         list_name = user.twitter_targets
         return show_twitter_list_template.render(list_name=list_name)
开发者ID:lixiao37,项目名称:team12-Project,代码行数:21,代码来源:userinterface.py

示例15: betaGraphs

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import objects [as 别名]
 def betaGraphs(self, targetlist=None, sourcelist=None):
     graphs = None
     if targetlist and sourcelist:
         if not isinstance(targetlist, list):
             targetlist = [targetlist]
         if not isinstance(sourcelist, list):
             sourcelist = [sourcelist]
         relation_dict = self.generate_relation_dict_beta(sourcelist,
                                                                  targetlist)
         graphs = self.generate_detailed_graph(relation_dict, "news",
                                                          targets=targetlist)
     beta_graph_template = Template(filename='beta_graphs.html',
                                                             lookup=mylookup)
     user = User.objects(name=cherrypy.session["user"]).first()
     sources = user.news_sources
     targets = user.news_targets
     twitter_sources = user.twitter_sources
     twitter_targets = user.twitter_targets
     return beta_graph_template.render(username=cherrypy.session["user"],
                                           beta="active", targetlist=targets,
                                           sourcelist=sources, graphs=graphs)
开发者ID:lixiao37,项目名称:team12-Project,代码行数:23,代码来源:userinterface.py


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