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


Python url.resource_url函数代码示例

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


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

示例1: delete_node

    def delete_node(self):
        """
        Delete node view. Renders either a view to delete the current node
        or handle the deletion of the current node and get back to the
        default view of the node.

        :result: Either a redirect response or a dictionary passed to the
                 template for rendering.
        :rtype: pyramid.httpexceptions.HTTPFound or dict
        """

        action = self.request.POST.get(u'delete')
        if action is not None:

            parent = self.context.__parent__

            if action == u'delete':
                location = resource_url(parent, self.request)
                self.flash(_(u'${title} was deleted.',
                             mapping=dict(title=self.context.title)),
                           u'success')
                del parent[self.context.name]
            else:
                location = resource_url(self.context, self.request)

            return HTTPFound(location=location)

        return {}
开发者ID:gitter-badger,项目名称:Kotti,代码行数:28,代码来源:actions.py

示例2: report_view

def report_view(context, request):
    api = TemplateAPI(context, request, context.title)
    peopledir = find_peopledirectory(context)
    section = context.__parent__
    peopledir_tabs = get_tabs(peopledir, request, section.__name__)
    client_json_data = {"grid_data": get_grid_data(context, request)}

    descriptions = get_report_descriptions(context)
    mgr = ILetterManager(context)
    letter_info = mgr.get_info(request)

    kw, qualifiers = get_search_qualifiers(request)
    print_url = resource_url(context, request, "print.html", **kw)
    csv_url = resource_url(context, request, "csv", **kw)
    pictures_url = resource_url(context, request, "picture_view.html", **kw)
    opensearch_url = resource_url(context, request, "opensearch.xml")

    return dict(
        api=api,
        peopledir=peopledir,
        peopledir_tabs=peopledir_tabs,
        head_data=convert_to_script(client_json_data),
        descriptions=descriptions,
        letters=letter_info,
        print_url=print_url,
        csv_url=csv_url,
        pictures_url=pictures_url,
        qualifiers=qualifiers,
        opensearch_url=opensearch_url,
        actions=get_actions(context, request),
        mailto=_get_mailto(context, peopledir),
    )
开发者ID:hathawsh,项目名称:karl,代码行数:32,代码来源:peopledirectory.py

示例3: forbidden

def forbidden(context, request):
    site = find_site(context)
    environ = request.environ
    referrer = environ.get('HTTP_REFERER', '')
    if 'repoze.who.identity' in environ:
        # the user is authenticated but he is not allowed to access this
        # resource
        api = TemplateAPI(context, request, 'Forbidden')
        response =  render_to_response(
            'templates/forbidden.pt',
            dict(api=api,
                 login_form_url = resource_url(site, request, 'login.html'),
                 homepage_url = resource_url(site, request)),
            request=request,
            )
        response.status = '403 Forbidden'
        return response
    elif '/login.html' in referrer:
        url = request.url
        # this request came from a user submitting the login form
        login_url = resource_url(site, request, 'login.html',
                              query={'reason':'Bad username or password',
                                     'came_from':url})
        return HTTPFound(location=login_url)
    else:
        # the user is not authenticated and did not come in as a result of
        # submitting the login form
        url = request.url
        query = {'came_from':url}
        while url.endswith('/'):
            url = url[:-1]
        if url != request.application_url: # if request isnt for homepage
            query['reason'] = 'Not logged in'
        login_url = resource_url(site, request, 'login.html', query=query)
        return HTTPFound(location=login_url)
开发者ID:Falmarri,项目名称:karl,代码行数:35,代码来源:forbidden.py

示例4: add_form

    def add_form(self):
        post = self.request.POST
        if 'cancel' in post:
            self.api.flash_messages.add(_(u"Canceled"))
            url = resource_url(self.context, self.request)
            return HTTPFound(location=url)

        schema = createSchema('AddUserSchema')
        add_csrf_token(self.context, self.request, schema)
        schema = schema.bind(context=self.context, request=self.request, api = self.api)
        form = Form(schema, buttons=(button_add, button_cancel))
        self.api.register_form_resources(form)

        if 'add' in post:
            controls = post.items()
            try:
                #appstruct is deforms convention. It will be the submitted data in a dict.
                appstruct = form.validate(controls)
            except ValidationFailure, e:
                self.response['form'] = e.render()
                return self.response
            
            #Userid and name should be consistent
            name = appstruct['userid']
            del appstruct['userid']
            
            #creators takes care of setting the role owner as well as adding it to creators attr.
            obj = createContent('User', creators=[name], **appstruct)
            self.context[name] = obj

            self.api.flash_messages.add(_(u"Successfully added"))

            url = resource_url(self.context, self.request)            
            return HTTPFound(location=url)
开发者ID:tobsan,项目名称:voteit.core,代码行数:34,代码来源:users.py

示例5: view_url

def view_url(context, request, key, default_name, **extra_qs):
    configured = request.registry.settings.get('cartouche.%s' % key)
    if configured is None:
        if extra_qs:
            return resource_url(context, request, default_name, query=extra_qs)
        return resource_url(context, request, default_name)
    return _fixup_url(context, request, configured, **extra_qs)
开发者ID:marcinkuzminski,项目名称:cartouche,代码行数:7,代码来源:util.py

示例6: pastebin_manage_view

def pastebin_manage_view(context, request):
    params = request.params
    message = params.get('message', u'')

    if params.has_key('form.submitted'):
        form = marshal(request.environ, request.body_file)
        checkboxes = form.get('delete', [])
        for checkbox in checkboxes:
            del context[checkbox]
        message = '%s pastes deleted' % len(checkboxes)
        url = resource_url(context, request, 'manage',
                           query={'message':message})
        response = HTTPFound(location=url)
        response.headers['Location'] = url
        return response

    pastebin_url = resource_url(context, request)
    pastes = utils.get_pastes(context, request, sys.maxint)

    return dict(
        api = utils.API(context, request),
        pastes = pastes,
        message = message,
        pastebin_url = pastebin_url,
        )
开发者ID:mcdonc,项目名称:marlton,代码行数:25,代码来源:paste.py

示例7: pastebin_view

def pastebin_view(context, request):
    params = request.params
    author_name = utils.preferred_author(context, request)
    language = u''
    paste = u''
    message = u''
    pastebin_url = resource_url(context, request)
    can_manage = has_permission('manage', context, request)

    if params.has_key('form.submitted'):
        if params.get('text'): # trap spambots
            return HTTPFound(location=resource_url(context, request))
        paste = params.get('paste_', '')
        author_name = params.get('author_name_', '')
        language = params.get('language_', '')
        schema = PasteAddSchema()
        message = None
        try:
            schema.to_python(request.params)
        except formencode.validators.Invalid, why:
            message = str(why)
        else:
            pobj = PasteEntry(author_name, paste, language)
            pasteid = context.add_item(pobj)
            url = '%s%s' % (pastebin_url, pasteid)
            response = HTTPFound(location=url)
            response.set_cookie(utils.COOKIE_AUTHOR, author_name,
                                max_age=864000)
            response.set_cookie(utils.COOKIE_LANGUAGE, language)
            return response
开发者ID:mcdonc,项目名称:marlton,代码行数:30,代码来源:paste.py

示例8: chatter_user_info

def chatter_user_info(context, request, userid=None):
    chatter = find_chatter(context)
    chatter_url = resource_url(chatter, request)
    profiles = find_profiles(context)
    if userid is None:
        userid = request.GET.get('userid')
    if userid is None:
        userid = authenticated_userid(request)
    profile = profiles.get(userid)
    profile_url = profile and resource_url(profile, request) or None
    photo = profile and profile.get('photo') or None
    if photo is not None:
        photo_url = thumb_url(photo, request, CHATTER_THUMB_SIZE)
    else:
        photo_url = get_static_url(request) + "/images/defaultUser.gif"
    posts = sum(1 for p in chatter.recentWithCreators(*[userid]))
    following = sum(1 for u in chatter.listFollowed(userid))
    followers = sum(1 for u in chatter.listFollowing(userid))
    return {'creator': getattr(profile, 'title', 'anonymous'),
            'creator_url': '%s%s' % (chatter_url, userid),
            'creator_profile_url': profile_url,
            'creator_image_url': photo_url,
            'creator_userid': userid,
            'chatter_url': chatter_url,
            'posts': posts,
            'following': following,
            'followers': followers}
开发者ID:mindreframer,项目名称:python-pyramid-stuff,代码行数:27,代码来源:panels.py

示例9: login_view

def login_view(context, request):
    whence = request.registry.queryUtility(ICameFromURL)
    if whence is not None:
        came_from = whence(request)
    else:
        came_from = resource_url(context, request)
    form = Form(Login(), buttons=('login',))
    rendered_form = form.render({'came_from': came_from})
    message = request.GET.get('message')

    if 'login' in request.POST:
        try:
            appstruct = form.validate(request.POST.items())
        except ValidationFailure, e:
            rendered_form = e.render()
            message = 'Please supply required values'
        else:
            credentials = {'login': appstruct['login_name'],
                           'password': appstruct['password'],
                          }
            api = get_api(request.environ)
            identity, headers =  api.login(credentials)
            if identity is not None:
                came_from = appstruct.get('came_from')
                if came_from is None:
                    came_from = resource_url(context, request)
                return HTTPFound(location=came_from, headers=headers)
            message = 'Login failed'
开发者ID:marcinkuzminski,项目名称:cartouche,代码行数:28,代码来源:login.py

示例10: lock_info_for_view

def lock_info_for_view(context, request, from_time=None):
    """return a structure suitable for displaying in a template"""

    if is_locked(context, from_time):
        lock = lock_info(context)
        userid = lock['userid']
        profiles = find_profiles(context)
        profile = profiles.get(userid, None)
        if profile is not None:
            return dict(
                is_locked = True,
                url = resource_url(profile, request),
                name = '%s %s' % (profile.firstname,
                                            profile.lastname),
                email = profile.email,
                )
        else:
            return dict(
                is_locked = True,
                url = resource_url(profiles, request),
                name = 'Unknown',
                email = '',
                )
    else:
        return dict(
            is_locked = False,
            url = None,
            name = None,
            email = None,
            )
开发者ID:Falmarri,项目名称:karl,代码行数:30,代码来源:lock.py

示例11: display_deleted_item

 def display_deleted_item(docid, tree_node):
     deleted_item = tree_node.deleted_item
     version = repo.history(docid, only_current=True)[0]
     if tree_node:
         url = resource_url(context, request, 'trash', query={
             'subfolder': str(docid)})
     else:
         url = None
     if deleted_item:
         deleted_by = profiles[deleted_item.deleted_by]
         return {
             'date': format_local_date(deleted_item.deleted_time, tz),
             'deleted_by': {
                 'name': deleted_by.title,
                 'url': resource_url(deleted_by, request),
                 },
             'restore_url': resource_url(
                 context, request, 'restore',
                 query={'docid': str(deleted_item.docid),
                        'name': deleted_item.name}),
             'title': version.title,
             'url': url}
     else:
         return {
             'date': None,
             'deleted_by': None,
             'restore_url': None,
             'title': version.title,
             'url': url}
开发者ID:Falmarri,项目名称:karl,代码行数:29,代码来源:versions.py

示例12: calendar_setup_view

def calendar_setup_view(context, request):
    default_category_name = ICalendarCategory.getTaggedValue('default_name')
    categories = filter(lambda x: x.__name__ != default_category_name,
                        _get_calendar_categories(context))

    default_layer_name = ICalendarLayer.getTaggedValue('default_name')
    layers = filter(lambda x: x.__name__ != default_layer_name,
                    _get_calendar_layers(context))

    fielderrors = {}
    fielderrors_target = None

    page_title = 'Calendar Setup'
    api = TemplateAPI(context, request, page_title)

    return render_to_response(
        'templates/calendar_setup.pt',
        dict(back_to_calendar_url=resource_url(context, request),
             categories_url=resource_url(context, request, 'categories.html'),
             layers_url=resource_url(context, request, 'layers.html'),
             formfields=api.formfields,
             fielderrors=fielderrors,
             fielderrors_target = fielderrors_target,
             api=api,
             editable_categories = categories,
             editable_layers = layers,
             all_categories = _get_all_calendar_categories(context, request),
             colors = _COLORS),
        request = request,
        )
开发者ID:Falmarri,项目名称:karl,代码行数:30,代码来源:calendar_events.py

示例13: add

    def add(self):
        if 'cancel' in self.request.POST:
            url = resource_url(self.context, self.request)
            return HTTPFound(location=url)

        type = self.request.GET['type']
        obj = createContent(type)
        schema = createSchema(obj.schemas['add']).bind(context = self.context, request = self.request)
        form = Form(schema, buttons=('save', 'cancel',))
        self.register_form_resources(form)

        if 'save' in self.request.POST:
            controls = self.request.POST.items()
            try:
                appstruct = form.validate(controls)
            except ValidationFailure, e:
                self.response['form'] = e.render()
                return self.response
            
            obj.set_field_appstruct(appstruct)
            name = obj.suggest_name(self.context)
            self.context[name] = obj

            url = resource_url(self.context, self.request)
            return HTTPFound(location=url)
开发者ID:robinharms,项目名称:Progress,代码行数:25,代码来源:crud.py

示例14: get_previous_next

def get_previous_next(context, request, viewname=''):

    # Reference Manual sections have inter-item navigation, which
    # means (sigh) that files and pages do as well.

    # Only works on resources whose parents are orderable
    parent = context.__parent__
    ordering = getattr(parent, 'ordering', None)
    if ordering is None:
        return None, None

    # Be a chicken and sync
    ordering.sync(parent.keys())

    # Find the prev/next names, then flatten some info about them for
    # the ZPT
    current_name = context.__name__
    previous = parent.get(ordering.previous_name(current_name))
    next = parent.get(ordering.next_name(current_name))

    if previous:
        if _find_view(previous, request, viewname) is not None:
            href = resource_url(previous, request, viewname)
        else:
            href = resource_url(previous, request)
        previous = {'title': previous.title, 'href': href}

    if next:
        if _find_view(next, request, viewname) is not None:
            href = resource_url(next, request, viewname)
        else:
            href = resource_url(next, request)
        next = {'title': next.title, 'href': href}

    return previous, next
开发者ID:Falmarri,项目名称:karl,代码行数:35,代码来源:utils.py

示例15: error_monitor_subsystem_view

def error_monitor_subsystem_view(context, request):
    error_monitor_dir = get_setting(context, 'error_monitor_dir', '')
    subsystems = get_setting(context, 'error_monitor_subsystems')
    subsystem = request.params.get('subsystem', None)
    if subsystem is None or subsystem not in subsystems:
        raise NotFound()

    back_url = resource_url(context, request, 'error_monitor.html')
    if 'clear' in request.params:
        path = os.path.join(error_monitor_dir, subsystem)
        os.remove(path)
        return HTTPFound(location=back_url)


    clear_url = resource_url(context, request, request.view_name,
                          query={'clear': '1', 'subsystem': subsystem})
    entries = _get_error_monitor_state(error_monitor_dir, subsystem)

    return dict(
        api=AdminTemplateAPI(context, request),
        menu=_menu_macro(),
        subsystem=subsystem,
        entries=entries,
        back_url=back_url,
        clear_url=clear_url,
    )
开发者ID:Falmarri,项目名称:karl,代码行数:26,代码来源:admin.py


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