• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python helpers.get_challenge_or_404函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: task_by_id

def task_by_id(challenge_slug, task_id):
    "Either displays a task (assigning it) or else posts the commit"
    # make sure we're authenticated
    challenge = get_challenge_or_404(challenge_slug, True)
    task = get_task_or_404(challenge, task_id)
    osmid = session.get('osm_id')
    if request.method == 'GET':
        try:
            assign = int(request.args.get('assign', 1))
        except ValueError:
            abort(400)
        if assign:
            action = Action(task.id, "assigned", osmid)
            task.current_state = action
            db.session.add(action)
            db.session.add(task)
        return jsonify(marshal(task, task_fields))

    elif request.method == 'POST':
        valid_actions = [button.action for button in challenge.dlg['buttons']]
        action = None
        for key in valid_actions:
            if request.form.get(key):
                action = Action(task.id, key, osmid)
                task.current_action = action
                db.session.add(action)
                break
        if not action:
            abort(400)
        new_state = challenge.task_status(task)
        action = Action(task.id, new_state, osmid)
        task.current_action = action
        db.session.add(action)
        db.session.add(task)
        db.commit()
开发者ID:xivk,项目名称:maproulette,代码行数:35,代码来源:__init__.py


示例2: put

 def put(self, slug):
     exists = challenge_exists(slug)
     try:
         payload = json.loads(request.data)
     except Exception:
         abort(400, "JSON bad")
     if not exists and 'title' not in payload:
         abort(400, "No title")
         return {}
     if exists:
         app.logger.debug('challenge existed, retrieving')
         c = get_challenge_or_404(slug, abort_if_inactive=False)
         if 'title' in payload:
             c.title = payload.get('title')
     else:
         c = Challenge(slug, payload.get('title'))
     if 'geometry' in payload:
         c.geometry = payload.get('geometry')
     if 'description' in payload:
         c.description = payload.get('description')
     if 'blurb' in payload:
         c.blurb = payload.get('blurb')
     if 'help' in payload:
         c.help = payload.get('help')
     if 'instruction' in payload:
         c.instruction = payload.get('instruction')
     if 'active' in payload:
         c.active = payload.get('active')
     if 'difficulty' in payload:
         c.difficulty = payload.get('difficulty')
     db.session.add(c)
     db.session.commit()
     return {}
开发者ID:mappingdc,项目名称:maproulette,代码行数:33,代码来源:__init__.py


示例3: put

 def put(self, slug):
     c = get_challenge_or_404(slug, abort_if_inactive=False)
     if not re.match("^[\w\d_-]+$", slug):
         abort(400, message='slug should contain only a-z, A-Z, 0-9, _, -')
     try:
         payload = json.loads(request.data)
     except Exception:
         abort(400, message="There is something wrong with your JSON.")
     app.logger.debug(payload)
     c.title = payload.get('title')
     c.geometry = payload.get('geometry')
     c.description = payload.get('description')
     c.blurb = payload.get('blurb')
     c.help = payload.get('help')
     c.instruction = payload.get('instruction')
     c.active = payload.get('active')
     c.difficulty = payload.get('difficulty')
     c.options = payload.get('options')
     db.session.add(c)
     try:
         db.session.commit()
     except Exception as e:
         if type(e) == IntegrityError:
             app.logger.warn(e)
             db.session.rollback()
             abort(409, message='the session and the database did not agree: {}'.format(e))
         else:
             app.logger.warn(e)
             abort(500, message=message_internal_server_error)
     return {}, 200
开发者ID:emacsen,项目名称:maproulette,代码行数:30,代码来源:__init__.py


示例4: get

    def get(self, slug):
        """Returns a task for specified challenge"""
        challenge = get_challenge_or_404(slug, True)
        parser = reqparse.RequestParser()
        parser.add_argument('lon', type=float,
                            help='longitude could not be parsed')
        parser.add_argument('lat', type=float,
                            help='longitude could not be parsed')
        parser.add_argument('assign', type=int, default=1,
                            help='Assign could not be parsed')
        args = parser.parse_args()
        osmid = session.get('osm_id')
        assign = args['assign']
        lon = args['lon']
        lat = args['lat']

        task = None
        if lon and lat:
            coordWKT = 'POINT(%s %s)' % (lat, lon)
            task = Task.query.filter(Task.location.ST_Intersects(
                ST_Buffer(coordWKT, app.config["NEARBUFFER"]))).first()
        if task is None:  # we did not get a lon/lat or there was no task close
            # If no location is specified, or no tasks were found, gather
            # random tasks
            task = get_random_task(challenge)
            app.logger.debug('got task %s' % task.id)
            # If no tasks are found with this method, then this challenge
            # is complete
        if task is None:
            # Send a mail to the challenge admin
            requests.post(
                "https://api.mailgun.net/v2/maproulette.org/messages",
                auth=("api", app.config["MAILGUN_API_KEY"]),
                data={"from": "MapRoulette <[email protected]>",
                      "to": ["[email protected]"],
                      "subject":
                      "Challenge {} is complete".format(challenge.slug),
                      "text":
                      "{challenge} has no remaining tasks on server {server}".format(
                          challenge=challenge.title,
                          server=url_for('index', _external=True))})
            # Deactivate the challenge
            challenge.active = False
            db.session.add(challenge)
            db.session.commit()
            # Is this the right error?
            return osmerror("ChallengeComplete",
                            "Challenge {} is complete".format(challenge.title))
        if assign:
            task.append_action(Action("assigned", osmid))
            db.session.add(task)

        db.session.commit()
        return marshal(task, task_fields)
开发者ID:CristianCantoro,项目名称:maproulette,代码行数:54,代码来源:__init__.py


示例5: challenge_stats

def challenge_stats(challenge_slug):
    "Returns stat data for a challenge"
    challenge = get_challenge_or_404(challenge_slug, True)
    total = Task.query.filter(challenge_slug == challenge.slug).count()
    tasks = Task.query.filter(challenge_slug == challenge.slug).all()
    osmid = session.get('osm_id')
    logging.info("{user} requested challenge stats for {challenge}".format(
            user=osmid, challenge=challenge_slug))
    available = len([task for task in tasks
                     if challenge.task_available(task, osmid)])
    return jsonify(stats={'total': total, 'available': available})
开发者ID:xivk,项目名称:maproulette,代码行数:11,代码来源:__init__.py


示例6: get

    def get(self, slug):
        """Returns a task for specified challenge"""
        challenge = get_challenge_or_404(slug, True)
        parser = reqparse.RequestParser()
        parser.add_argument('lon', type=float,
                            help='longitude could not be parsed')
        parser.add_argument('lat', type=float,
                            help='longitude could not be parsed')
        parser.add_argument('assign', type=int, default=1,
                            help='Assign could not be parsed')
        args = parser.parse_args()
        osmid = session.get('osm_id')
        assign = args['assign']
        lon = args['lon']
        lat = args['lat']

        task = None
        if lon and lat:
            coordWKT = 'POINT(%s %s)' % (lat, lon)
            task = Task.query.filter(Task.location.ST_Intersects(
                ST_Buffer(coordWKT, app.config["NEARBUFFER"]))).first()
        if task is None:  # we did not get a lon/lat or there was no task close
            # If no location is specified, or no tasks were found, gather
            # random tasks
            task = get_random_task(challenge)
            # If no tasks are found with this method, then this challenge
            # is complete
        if task is None:
            if not user_area_is_defined():
                # send email and deactivate challenge only when
                # there are no more tasks for the entire challenge,
                # not if the user has defined an area to work on.
                subject = "Challenge {} is complete".format(challenge.slug)
                body = "{challenge} has no remaining tasks"
                " on server {server}".format(
                    challenge=challenge.title,
                    server=url_for('index', _external=True))
                send_email("[email protected]", subject, body)

                # Deactivate the challenge
                challenge.active = False
                db.session.add(challenge)
                db.session.commit()

            # Is this the right error?
            return osmerror("ChallengeComplete",
                            "Challenge {} is complete".format(challenge.title))
        if assign:
            task.append_action(Action("assigned", osmid))
            db.session.add(task)

        db.session.commit()
        return marshal(task, task_fields)
开发者ID:CharlieTLe,项目名称:maproulette,代码行数:53,代码来源:__init__.py


示例7: delete

 def delete(self, slug):
     """delete a challenge"""
     challenge = get_challenge_or_404(slug, abort_if_inactive=False)
     db.session.delete(challenge)
     try:
         db.session.commit()
     except Exception as e:
         if type(e) == IntegrityError:
             app.logger.warn(e)
             db.session.rollback()
             abort(409, message='the session and the database did not agree: {}'.format(e))
         else:
             app.logger.warn(e)
             abort(500, message='Something really unexpected happened...')
     return {}, 204
开发者ID:emacsen,项目名称:maproulette,代码行数:15,代码来源:__init__.py


示例8: challenge_tasks

def challenge_tasks(challenge_slug):
    "Returns a task for specified challenge"
    challenge = get_challenge_or_404(challenge_slug, True)
    parser = reqparse.RequestParser()
    parser.add_argument('num', type=int, default=1,
                        help='Number of return results cannot be parsed')
    parser.add_argument('near', type=GeoPoint,
                        help='Near argument could not be parsed')
    parser.add_argument('assign', type=int, default=1,
                        help='Assign could not be parsed')
    args = parser.parse_args()
    osmid = session.get('osm_id')
    # By default, we return a single task, but no more than 10
    num = min(args['num'], 10)
    assign = args['assign']
    near = args['near']
    logging.info("{user} requesting {num} tasks from {challenge} near {near} assiging: {assign}".format(user=osmid, num=num, challenge=challenge_slug, near=near, assign=assign))
    task_list = []
    if near:
        coordWKT = 'POINT(%s %s)' % (near.lat, near.lon)
        task_query = Task.query.filter(Task.location.ST_Intersects(
                ST_Buffer(coordWKT, app.config["NEARBUFFER"]))).limit(num)
        task_list = [task for task in task_query
                     if challenge.task_available(task, osmid)]
    if not near or not task_list:
        # If no location is specified, or no tasks were found, gather
        # random tasks
        task_list = [get_random_task(challenge) for _ in range(num)]
        task_list = filter(None, task_list)
        # If no tasks are found with this method, then this challenge
        # is complete
    if not task_list:
        # Is this the right error?
        osmerror("ChallengeComplete",
                 "Challenge {} is complete".format(challenge_slug))
    if assign:
        for task in task_list:
            action = Action(task.id, "assigned", osmid)
            task.current_state = action
            db.session.add(action)
            db.session.add(task)
        db.session.commit()
    logging.info(
        "{num} tasks found matching criteria".format(num=len(task_list)))
    tasks = [marshal(task, task_fields) for task in task_list]
    for query in get_debug_queries():
        app.logger.debug(query)
    return jsonify(tasks=tasks)
开发者ID:xivk,项目名称:maproulette,代码行数:48,代码来源:__init__.py


示例9: get

    def get(self, slug):
        """Returns a task for specified challenge"""
        challenge = get_challenge_or_404(slug, True)
        parser = reqparse.RequestParser()
        parser.add_argument('lon', type=float,
                            help='longitude could not be parsed')
        parser.add_argument('lat', type=float,
                            help='longitude could not be parsed')
        parser.add_argument('assign', type=int, default=1,
                            help='Assign could not be parsed')
        args = parser.parse_args()
        osmid = session.get('osm_id')
        assign = args['assign']
        lon = args['lon']
        lat = args['lat']

        app.logger.info(
            "{user} requesting task from {challenge} near\
             ({lon}, {lat}) assiging: {assign}".format(
            user=osmid,
            challenge=slug,
            lon=lon,
            lat=lat,
            assign=assign))

        task = None
        if lon and lat:
            coordWKT = 'POINT(%s %s)' % (lat, lon)
            task = Task.query.filter(Task.location.ST_Intersects(
                ST_Buffer(coordWKT, app.config["NEARBUFFER"]))).first()
        if task is None:  # we did not get a lon/lat or there was no task close
            # If no location is specified, or no tasks were found, gather
            # random tasks
            app.logger.debug('getting random task')
            task = get_random_task(challenge)
            # If no tasks are found with this method, then this challenge
            # is complete
        if task is None:
            # Is this the right error?
            return osmerror("ChallengeComplete",
                            "Challenge {} is complete".format(slug))
        if assign:
            task.append_action(Action("assigned", osmid))
            db.session.add(task)

        db.session.commit()
        return marshal(task, task_fields)
开发者ID:claysmalley,项目名称:maproulette,代码行数:47,代码来源:__init__.py


示例10: get

    def get(self, challenge_slug):
        """Return statistics for the challenge identified by 'slug'"""
        # get the challenge
        challenge = get_challenge_or_404(challenge_slug, abort_if_inactive=False)

        # query the number of tasks
        query = db.session.query(Task).filter_by(challenge_slug=challenge.slug)
        # refine with the user defined editing area
        query = refine_with_user_area(query)
        # emit count
        total = query.count()

        # get the approximate number of available tasks
        unfixed = query.filter(Task.status.in_(
            ['available', 'created', 'skipped'])).count()

        return {'total': total, 'unfixed': unfixed}
开发者ID:emacsen,项目名称:maproulette,代码行数:17,代码来源:__init__.py


示例11: put

 def put(self, slug):
     c = get_challenge_or_404(slug, abort_if_inactive=False)
     if not re.match("^[\w\d_-]+$", slug):
         abort(400, 'slug should contain only a-z, A-Z, 0-9, _, -')
     try:
         payload = json.loads(request.data)
     except Exception:
         abort(400, "JSON bad")
     if 'title' in payload:
         c.title = payload.get('title')
     if 'geometry' in payload:
         c.geometry = payload.get('geometry')
     if 'description' in payload:
         c.description = payload.get('description')
     if 'blurb' in payload:
         c.blurb = payload.get('blurb')
     if 'help' in payload:
         c.help = payload.get('help')
     if 'instruction' in payload:
         c.instruction = payload.get('instruction')
     if 'active' in payload:
         c.active = payload.get('active')
     if 'difficulty' in payload:
         c.difficulty = payload.get('difficulty')
     db.session.add(c)
     try:
         db.session.commit()
     except Exception as e:
         if type(e) == IntegrityError:
             app.logger.warn(e.message)
             db.session.rollback()
             abort(409, 'the session and the database did not agree: {}'.format(e.message))
         else:
             app.logger.warn(e.message)
             abort(500, 'something unexpected happened')
     return {}, 200
开发者ID:CloCkWeRX,项目名称:maproulette,代码行数:36,代码来源:__init__.py


示例12: delete

 def delete(self, slug):
     """delete a challenge"""
     challenge = get_challenge_or_404(slug)
     db.session.delete(challenge)
     db.session.commit()
     return {}, 204
开发者ID:CharlieTLe,项目名称:maproulette,代码行数:6,代码来源:__init__.py


示例13: get

 def get(self, slug):
     """Return statistics for the challenge identified by 'slug'"""
     challenge = get_challenge_or_404(slug, True)
     total = len(challenge.tasks)
     unfixed = challenge.approx_tasks_available
     return {'total': total, 'unfixed': unfixed}
开发者ID:Koblaid,项目名称:maproulette,代码行数:6,代码来源:__init__.py


示例14: challenge_by_slug

def challenge_by_slug(challenge_slug):
    """Returns the metadata for a challenge"""
    challenge = get_challenge_or_404(challenge_slug, "Default")
    app.logger.debug('done dialog for challenge: %s' % (challenge.done_dlg))
    return challenge
开发者ID:xivk,项目名称:maproulette,代码行数:5,代码来源:__init__.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python maps.draw_dot函数代码示例发布时间:2022-05-27
下一篇:
Python util.for_name函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap