def setUpEditWidgets(form_fields, form_prefix, context, request,
                     adapters=None, for_display=False,
                     ignore_request=False):
    if adapters is None:
        adapters = {}

    widgets = []
    for form_field in form_fields:
        field = form_field.field
        # Adapt context, if necessary
        interface = form_field.interface
        adapter = adapters.get(interface)
        if adapter is None:
            if interface is None:
                adapter = context
            else:
                adapter = interface(context, context)  # Work around.
            adapters[interface] = adapter
            if interface is not None:
                adapters[interface.__name__] = adapter

        field = field.bind(adapter)

        readonly = form_field.for_display
        readonly = readonly or (field.readonly and not form_field.for_input)
        readonly = readonly or (
            (form_field.render_context & DISPLAY_UNWRITEABLE) and not canWrite(adapter, field))
        readonly = readonly or for_display

        if readonly:
            iface = IDisplayWidget
        else:
            iface = IInputWidget
        widget = _createWidget(form_field, field, request, iface)

        prefix = form_prefix
        if form_field.prefix:
            prefix = expandPrefix(prefix) + form_field.prefix

        widget.setPrefix(prefix)

        if ignore_request or readonly or not widget.hasInput():
            # Get the value to render
            value = field.get(adapter)
            widget.setRenderedValue(value)

        widgets.append((not readonly, widget))

    return Widgets(widgets, prefix=form_prefix)
Beispiel #2
0
    def _getNavigationURL(self, b_start):
        target = self._getViewURL()
        kw = self._getNavigationVars().copy()

        kw['b_start'] = b_start
        for k, v in kw.items():
            if not v or k == 'portal_status_message':
                del kw[k]
            else:
                new_key = "%s%s" % (form.expandPrefix(self.prefix), k)
                if new_key != k:
                    kw[new_key] = v
                    del kw[k]

        query = kw and ('?%s' % urllib.urlencode(kw)) or ''
        return u'%s%s' % (target, query)
    def _getNavigationURL(self, b_start):
        target = self._getViewURL()
        kw = self._getNavigationVars().copy()

        kw['b_start'] = b_start
        for k, v in kw.items():
            if not v or k == 'portal_status_message':
                del kw[k]
            else:
                new_key = "%s%s" % (form.expandPrefix(self.prefix), k)
                if new_key != k:
                    kw[new_key] = v
                    del kw[k]

        query = kw and ('?%s' % urllib.urlencode(kw)) or ''
        return u'%s%s' % (target, query)
Beispiel #4
0
def create_oauth_permission_actions():
    """Make two `Actions` objects containing each possible `OAuthPermission`.

    The first `Actions` object contains every action supported by the
    OAuthAuthorizeTokenView. The second list contains a good default
    set of actions, omitting special actions like the
    DESKTOP_INTEGRATION ones.
    """
    all_actions = Actions()
    ordinary_actions = Actions()
    desktop_permission = OAuthPermission.DESKTOP_INTEGRATION
    for permission in OAuthPermission.items:
        action = Action(
            permission.title, name=permission.name,
            success=token_review_success,
            condition=token_exists_and_is_not_reviewed)
        action.permission = permission
        action.duration = None
        all_actions.append(action)
        if permission != desktop_permission:
            ordinary_actions.append(action)

    # Add special actions for the time-limited DESKTOP_INTEGRATION
    # tokens.
    for duration in (
        TemporaryIntegrations.HOUR, TemporaryIntegrations.DAY,
        TemporaryIntegrations.WEEK):
        action = Action(
            ("For One %s" % duration),
            name=expandPrefix(desktop_permission.name) + duration,
            success=token_review_success,
            condition=token_exists_and_is_not_reviewed)
        action.permission = desktop_permission
        action.duration = duration
        all_actions.append(action)

    return all_actions, ordinary_actions
Beispiel #5
0
 def expand_prefix(
     self,
     key,
 ):
     """Return a form specific query key for use in GET strings"""
     return "%s%s" % (form.expandPrefix(self.prefix), key)
Beispiel #6
0
 def expand_prefix(self, key,):
     """Return a form specific query key for use in GET strings"""
     return "%s%s" % (form.expandPrefix(self.prefix), key)