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


Python User.objects方法代码示例

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


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

示例1: single_user

# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import objects [as 别名]
def single_user(email):
    if User.objects(email=email).count() != 1:
        abort(404)
    user = User.objects().get(email=email)
    """
    args = {
        k: v[0] for (k, v) in request.args.items()
    }
    """
    db = client.cloakedhipster
    dbdiff = db.diff
    dbwindow = db.active_window

    query = {
        'user': user['id'],
    }

    if 'after' in request.args or 'before' in request.args:
        query['time'] = {}
        if 'after' in request.args:
            query['time']['$gte'] = long(request.args['after'])
        if 'before' in request.args:
            query['time']['$lte'] = long(request.args['before'])

    derped = list(dbdiff.find(query))
    derped2 = list(dbwindow.find(query))

    commits = get_num_commits()

    return render_template('user.html', commits=commits, userRaw=user.dict(), user=json.dumps(user.dict()), diffs=json.dumps(derped, cls=MongoJsonEncoder), actWindows=json.dumps(derped2, cls=MongoJsonEncoder))
开发者ID:schlosser,项目名称:go-to-sleep,代码行数:32,代码来源:routes.py

示例2: get_home_page

# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import objects [as 别名]
def get_home_page(commits):
    page = cache.get('homepage')
    if page is None:
        users = User.objects()
        page = render_template("home.html", users=users, commits=commits)
        cache.set('homepage', page, timeout=60)
        print 'rendered homepage'
    return page
开发者ID:schlosser,项目名称:go-to-sleep,代码行数:10,代码来源:routes.py

示例3: sleep

# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import objects [as 别名]
def sleep(email):
    try:
        user = User.objects().get(email=email)
    except Exception:
        abort(400)
    user.should_sleep = True
    user.save()
    return redirect(url_for('user.single_user', email=email))
开发者ID:schlosser,项目名称:go-to-sleep,代码行数:10,代码来源:routes.py

示例4: check_if_fit_for_sleep

# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import objects [as 别名]
def check_if_fit_for_sleep(email):
    try:
        user = User.objects().get(email=email)
        current_time = long(datetime.now().strftime('%s'))
        param_60_mva = {
            'user': user['id'],
            'time': {'$lte': current_time},
            'time': {'$gte': long((datetime.now() - timedelta(seconds=60*60)).strftime('%s'))},
        }
        param_10_mva = {
            'user': user['id'],
            'time': {'$lte': current_time},
            'time': {'$gte': long((datetime.now() - timedelta(seconds=10*60)).strftime('%s'))},
        }

        db = client.cloakedhipster
        dbdiff = db.diff

        hour_records = list(dbdiff.find(param_60_mva))
        ten_min_records = list(dbdiff.find(param_10_mva))

        if hour_records:
            hour_mva = 1.0 * sum((
                x['lines_inserted'] + x['lines_deleted']
                for x in hour_records
                if x['lines_inserted'] + x['lines_deleted'] < MAGIC2)
            ) / len(hour_records)
        else:
            hour_mva = 0.0

        if ten_min_records:
            ten_mva = 1.0 * sum(
                (x['lines_inserted'] + x['lines_deleted']
                for x in ten_min_records
                if x['lines_inserted'] + x['lines_deleted'] < MAGIC2)
            ) / len(ten_min_records)
        else:
            ten_mva = 0.0

        print 'hour:{}, ten_minutes:{}'.format(hour_mva, ten_mva)

        if hour_mva * MAGIC > ten_mva or user.should_sleep:
            user.should_sleep = False
            user.save()
            return json.dumps({'outcome': True})

        return json.dumps({'outcome': False})
    except DoesNotExist:
      abort(403)
开发者ID:schlosser,项目名称:go-to-sleep,代码行数:51,代码来源:routes.py

示例5: create_user

# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import objects [as 别名]
def create_user():
    email = request.form.get('email')
    name = request.form.get('name')

    if not email or not name:
        abort(400)

    try:
        user = User.objects().get(email=email)
    except DoesNotExist:
        user = User(email=email, name=name)
        user.save()
    except MultipleObjectsReturned:
        abort(500)
    except NotUniqueError:
        abort(203)

    resp = {'user': user.dict()}
    return jsonify(resp)
开发者ID:schlosser,项目名称:go-to-sleep,代码行数:21,代码来源:routes.py

示例6: new_diff

# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import objects [as 别名]
def new_diff(email):
    try:
        user = User.objects().get(email=email)
    except (MultipleObjectsReturned, DoesNotExist):
        abort(403)

    if not FIELDS.issubset(set(request.form.keys())):
        abort(400)

    diff_resource = dict((key, request.form[key]) for key in FIELDS)
    fc = diff_resource.get('files_changed')
    diff_resource['files_changed'] = json.loads(fc)
    rem = diff_resource.get('remotes')

    repo_re = re.compile(r'(\w+://)?([email protected])*([\w\d\.]+)(:[\d]+)?/*:?(.*)/(.*).git')

    diff_resource['remotes'] = []
    for remote_url in json.loads(rem):
        matches = repo_re.match(remote_url)
        repo_url = '{}:{}'.format(matches.group(5), matches.group(6))
        repo_username = matches.group(6)
        try:
            repo = Repo.objects().get(slug=repo_url)
        except DoesNotExist:
            repo = Repo(name=repo_username, slug=repo_url)
            repo.save()
        except MultipleObjectsReturned:
            abort(500)

        diff_resource['remotes'].append(repo)

    diff_resource['user'] = user

    diff = Diff(**diff_resource)
    diff.save()

    user.diffs.append(diff)
    user.save()

    return jsonify(diff.dict())
开发者ID:schlosser,项目名称:go-to-sleep,代码行数:42,代码来源:routes.py

示例7: users

# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import objects [as 别名]
def users():
    """All users DEV ONLY"""
    return jsonify({"users": [user.dict() for user in User.objects()]})
开发者ID:schlosser,项目名称:go-to-sleep,代码行数:5,代码来源:routes.py


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