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


Python url.route_path函数代码示例

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


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

示例1: project_new_arbitrary

def project_new_arbitrary(request):
    _ = request.translate
    ngettext = request.plural_translate

    user_id = authenticated_userid(request)
    user = DBSession.query(User).get(user_id)

    try:
        project = Project(
            _(u'Untitled project'),
            user
        )
        count = project.import_from_geojson(request.POST['geometry'])
        request.session.flash(
            ngettext('Successfully imported ${n} geometry',
                     'Successfully imported ${n} geometries',
                     count,
                     mapping={'n': count}),
            'success')
        return HTTPFound(location=route_path('project_edit', request,
                         project=project.id))
    except Exception, e:
        msg = _("Sorry, could not create the project. <br />%s") % e.message
        request.session.flash(msg, 'alert')
        raise HTTPFound(location=route_path('project_new', request))
开发者ID:mapcolabora,项目名称:osm-tasking-manager2,代码行数:25,代码来源:project.py

示例2: test_resources_with_parent_resource

 def test_resources_with_parent_resource(self):
     self.config.add_resource('pyramid_routehelper.tests:DummyCrudHandler',
                              'message', 'messages',
                              parent_resource = dict(member_name='category', collection_name='categories'))
     
     assert route_path('category_messages', testing.DummyRequest(), category_id=2) == '/categories/2/messages'
     assert route_path('category_message', testing.DummyRequest(), category_id=2, id=1) == '/categories/2/messages/1'
开发者ID:Pylons,项目名称:pyramid_routehelper,代码行数:7,代码来源:tests.py

示例3: menu

def menu(request):
    """
        returns the main menu
    """
    # TODO : view/edit permission ...
    menu = (
        dict(label="Users", url=route_path("users", request), title="User management", icon=""),
        dict(label="Contacts", url=route_path("contacts", request), title="Contact and relationships", icon=""),
    )
    return dict(menu=menu)
开发者ID:tonthon,项目名称:pyramidCrm,代码行数:10,代码来源:views.py

示例4: test_basic_resources

    def test_basic_resources(self):
        from nefertari.resource import add_resource_routes
        add_resource_routes(self.config, DummyCrudView, 'message', 'messages')

        self.assertEqual(
            '/messages',
            route_path('messages', testing.DummyRequest())
        )
        self.assertEqual(
            '/messages/1',
            route_path('message', testing.DummyRequest(), id=1)
        )
开发者ID:karthikmm,项目名称:nefertari,代码行数:12,代码来源:test_resource.py

示例5: test_singular_resource

    def test_singular_resource(self, *a):
        View = get_test_view_class()
        config = _create_config()
        root = config.get_root_resource()
        root.add('thing', view=View)
        grandpa = root.add('grandpa', 'grandpas', view=View)
        wife = grandpa.add('wife', view=View, renderer='string')
        wife.add('child', 'children', view=View)

        config.begin()
        app = TestApp(config.make_wsgi_app())

        self.assertEqual(
            '/grandpas/1/wife',
            route_path('grandpa:wife', testing.DummyRequest(), grandpa_id=1)
        )

        self.assertEqual(
            '/grandpas/1',
            route_path('grandpa', testing.DummyRequest(), id=1)
        )

        self.assertEqual(
            '/grandpas/1/wife/children/2',
            route_path('grandpa_wife:child', testing.DummyRequest(),
                       grandpa_id=1, id=2)
        )

        self.assertEqual(app.put('/grandpas').body, six.b('update_many'))
        self.assertEqual(app.head('/grandpas').body, six.b(''))
        self.assertEqual(app.options('/grandpas').body, six.b(''))

        self.assertEqual(app.delete('/grandpas/1').body, six.b('delete'))
        self.assertEqual(app.head('/grandpas/1').body, six.b(''))
        self.assertEqual(app.options('/grandpas/1').body, six.b(''))

        self.assertEqual(app.put('/thing').body, six.b('replace'))
        self.assertEqual(app.patch('/thing').body, six.b('update'))
        self.assertEqual(app.delete('/thing').body, six.b('delete'))
        self.assertEqual(app.head('/thing').body, six.b(''))
        self.assertEqual(app.options('/thing').body, six.b(''))

        self.assertEqual(app.put('/grandpas/1/wife').body, six.b('replace'))
        self.assertEqual(app.patch('/grandpas/1/wife').body, six.b('update'))
        self.assertEqual(app.delete('/grandpas/1/wife').body, six.b('delete'))
        self.assertEqual(app.head('/grandpas/1/wife').body, six.b(''))
        self.assertEqual(app.options('/grandpas/1/wife').body, six.b(''))

        self.assertEqual(six.b('show'), app.get('/grandpas/1').body)
        self.assertEqual(six.b('show'), app.get('/grandpas/1/wife').body)
        self.assertEqual(
            six.b('show'), app.get('/grandpas/1/wife/children/1').body)
开发者ID:mbijon,项目名称:nefertari,代码行数:52,代码来源:test_resource.py

示例6: motion_add

def motion_add(request):
    """create a new motion.
    
    1. show new motion form
    2. save to database after user submit
    """
    
    # initialize the form to select all participants
    all_users = load_users()
    all_user_options = [(itm.id, itm.name) for itm in all_users]
    selected_users = [itm.id for itm in all_users]

    # add four blank options on new motion form
    form = Form(request, schema=MotionSchema, defaults=dict(participants = selected_users, 
                                                            options=["","","",""]))
    
    if form.validate():
        title = form.data.get("title")
        desc = form.data.get("desc")
        options = form.data.get("options")
        users = form.data.get("participants")

        add_motion(title, desc, options, users)

        return HTTPFound(location=route_path('motion_list', request))
        
    return dict(renderer=FormRenderer(form), all_user_options=all_user_options)
开发者ID:eryxlee,项目名称:MotionMan,代码行数:27,代码来源:motion.py

示例7: result_view

def result_view(request):
  logger.info("result_view")
  image = request.session.get('image')
  logger.debug('From session got image: {0}'.format(image))
  if not image:
    return HTTPFound(location=route_path('home', request))

  def retrieve_similar_images(ref, images):
    img_distance_pairs = [(img, ImgStatisticCounter.distance(ref, img)
                           , ImgStatisticCounter.deviation_distance(ref, img))
                          for img in images]
    img_distance_pairs.sort(key=lambda (image, distance, deviation): distance)
    result = []
    for pair in img_distance_pairs:
        if not ImgStatisticCounter.are_similar(ref, pair[0]):
            break
        result.append(pair)
    return result

  images = retrieve_similar_images(
    ref=image,
    images=DBManager.retrieve_all_except_one(image_id=image['id'])
  )

  return {
    'image': image,
    'images': images,
    'page_name': 'Result'
  }
开发者ID:A-Kulikov,项目名称:python2012,代码行数:29,代码来源:views.py

示例8: route

    def route(self, route_name, *elements, **kw):
        """Generate a route URL.

        I return a URL based on a named route. Calling the URLGenerator 
        instance is the same as calling me.
        If the constructor arg 'qualified' is true, I call
        ``pyramid.url.route_url``, otherwise I call ``pyramid.url.route_path``.

        Arguments: 

        * ``route_name``: the name of a route.
        * ``*elements``: additional segments to append to the URL path.


        Keyword arguments are passed to the underlying function. The following
        are recognized:

        * ``_query``: the query parameters. May be a dict-like object with
          a ``.items()`` method or a sequence of 2-tuples.
        * ``_anchor``: the URL's "#ancor" fragment without the "#".
        * ``_app_url``: override the "scheme://host" prefix. (This also causes
          the result to be qualified if it wouldn't otherwise be.)
        * Other keyword args override path variables defined in the route.

        If the relevant route has a *pregenerator* defined, it may modify the
        elements or keyword args.
        """
        if self.qualified or "_app_url" in kw:
            return url.route_url(route_name, self.request, *elements, **kw)
        else:
            return url.route_path(route_name, self.request, *elements, **kw)
开发者ID:koansys,项目名称:akhet,代码行数:31,代码来源:urlgenerator.py

示例9: project

def project(request):
    check_project_expiration()
    id = request.matchdict['project']
    project = DBSession.query(Project).get(id)

    if project is None:
        _ = request.translate
        request.session.flash(_("Sorry, this project doesn't  exist"))
        return HTTPFound(location=route_path('home', request))

    project.locale = get_locale_name(request)

    filter = and_(TaskState.project_id == id,
                  TaskState.state != TaskState.state_removed,
                  TaskState.state != TaskState.state_ready)
    history = DBSession.query(TaskState) \
                       .filter(filter) \
                       .order_by(TaskState.date.desc()) \
                       .limit(20).all()

    user_id = authenticated_userid(request)
    locked_task = None
    user = None
    if user_id:
        user = DBSession.query(User).get(user_id)
        locked_task = get_locked_task(project.id, user)

    features = []
    for area in project.priority_areas:
        features.append(Feature(geometry=shape.to_shape(area.geometry)))

    return dict(page_id='project', project=project,
                locked_task=locked_task,
                history=history,
                priority_areas=FeatureCollection(features),)
开发者ID:KaiBot3000,项目名称:osm-tasking-manager2,代码行数:35,代码来源:project.py

示例10: project_new_grid

def project_new_grid(request):
    if 'zoom' in request.params:

        user_id = authenticated_userid(request)
        user = DBSession.query(User).get(user_id)
        project = Project(
            u'Untitled project',
            user
        )

        DBSession.add(project)
        DBSession.flush()

        zoom = int(request.params['zoom'])

        geometry = request.params['geometry']

        polygons = parse_geojson(geometry)
        from shapely.geometry import MultiPolygon
        multipolygon = MultiPolygon([polygon for polygon in polygons])

        geometry = shape.from_shape(multipolygon, 4326)
        project.area = Area(geometry)
        project.auto_fill(zoom)

        _ = request.translate
        request.session.flash(_("Project #${project_id} created successfully",
                              mapping={'project_id': project.id}),
                              'success')
        return HTTPFound(location=route_path('project_edit', request,
                                             project=project.id))

    return dict(page_id='project_new_grid')
开发者ID:DavidS,项目名称:osm-tasking-manager2,代码行数:33,代码来源:project.py

示例11: promote_owner

def promote_owner(request):
	userid = request.matchdict['id']
	promuser = DBSession.query(User).get(userid)

	promuser.role = User.role_owner if not promuser.is_owner else None
	DBSession.flush()

	return HTTPFound(location=route_path('admin_user_list',request))
开发者ID:ethan-nelson,项目名称:osmhm_site,代码行数:8,代码来源:admin.py

示例12: project_publish

def project_publish(request):
    id = request.matchdict['project']
    project = DBSession.query(Project).get(id)

    project.status = project.status_published

    return HTTPFound(location=route_path('project', request,
                                         project=project.id))
开发者ID:KaiBot3000,项目名称:osm-tasking-manager2,代码行数:8,代码来源:project.py

示例13: book_delete

def book_delete(request):
    try:
        book_id = int(request.matchdict['id'])
        if book_id:
            DBSession.query(Book).filter(Book.id==book_id).delete()
        return HTTPFound(location=route_path("book_list", request))
    except Exception:
        return HTTPForbidden()
开发者ID:eryxlee,项目名称:pyramid_koans,代码行数:8,代码来源:views.py

示例14: test_resources_with_path_prefix_with_trailing_slash

    def test_resources_with_path_prefix_with_trailing_slash(self):
        from nefertari.resource import add_resource_routes
        add_resource_routes(
            self.config,
            DummyCrudView,
            'message',
            'messages',
            path_prefix='/category/{category_id}/'
        )

        self.assertEqual(
            '/category/2/messages',
            route_path('messages', testing.DummyRequest(), category_id=2)
        )
        self.assertEqual(
            '/category/2/messages/1',
            route_path('message', testing.DummyRequest(), id=1, category_id=2)
        )
开发者ID:karthikmm,项目名称:nefertari,代码行数:18,代码来源:test_resource.py

示例15: user_validator

def user_validator(request):
    id = request.matchdict['id']
    user = DBSession.query(User).get(id)

    user.role ^= User.role_validator
    DBSession.flush()

    return HTTPFound(location=route_path("user", request,
                                         username=user.username))
开发者ID:mapcolabora,项目名称:osm-tasking-manager2,代码行数:9,代码来源:user.py


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