コード例 #1
0
ファイル: utils.py プロジェクト: jean/NuPlone
def viewType(context, request):
    """Determine what type of view the user is looking at. This returns
    one of three options: ``view`` for normal object views, ``add``
    for add forms, ``edit`` for edit forms, and ``other`` for all other
    types."""

    view=request.other.get("PUBLISHED")
    if view is not None:
        if IAddForm.providedBy(view):
            return "add"
        if IEditForm.providedBy(view):
            return "edit"

    for url in [ "ACTUAL_URL", "VIRTUAL_URL", "URL" ]:
        current_url=request.get(url)
        if current_url is not None:
            break
    else:
        return "view"

    if current_url.endswith("/"):
        current_url=current_url[:-1]

    if current_url.endswith("@@edit"):
        return "edit"
    elif "/++add++" in current_url:
        return "add"

    if current_url==aq_inner(context).absolute_url():
        return "view"

    return "other"
コード例 #2
0
def viewType(context, request):
    """Determine what type of view the user is looking at. This returns
    one of three options: ``view`` for normal object views, ``add``
    for add forms, ``edit`` for edit forms, and ``other`` for all other
    types."""

    view = request.other.get("PUBLISHED")
    if view is not None:
        if IAddForm.providedBy(view):
            return "add"
        if IEditForm.providedBy(view):
            return "edit"

    for url in ["ACTUAL_URL", "VIRTUAL_URL", "URL"]:
        current_url = request.get(url)
        if current_url is not None:
            break
    else:
        return "view"

    if current_url.endswith("/"):
        current_url = current_url[:-1]

    if current_url.endswith("@@edit"):
        return "edit"
    elif "/++add++" in current_url:
        return "add"

    if current_url == aq_inner(context).absolute_url():
        return "view"

    return "other"
コード例 #3
0
ファイル: extender.py プロジェクト: IMIO/ric.core
    def update(self):
        isForm = IEditForm.providedBy(self.form) or IAddForm.providedBy(self.form)
        if not isForm:
            return

        if not hasattr(self.form, 'portal_type'):
            return

        if self.form.portal_type == 'organization':
            self.remove('logo')
            self.remove('activity')
            self.remove('IContactDetails.im_handle')
            self.remove('IContactDetails.country')
            self.remove('IContactDetails.cell_phone')
            self.remove('IContactDetails.fax')
            self.remove('IContactDetails.region')
            sm = getSecurityManager()
            if not sm.checkPermission('RIC: Administer website', self.context):
                self.form.fields['IBasic.title'].mode = 'display'
                self.form.fields['organization_type'].mode = 'display'
            contactFields = self.form.groups[0].fields
            #contactFields['IContactDetails.email'].field.required = True

        elif self.form.portal_type == 'person':
            self.remove('gender')
            self.remove('person_title')
            self.remove('photo')
            self.remove('IContactDetails.im_handle')
            self.remove('IContactDetails.fax')
            self.remove('IContactDetails.country')
            self.remove('IContactDetails.region')
            self.remove('IContactDetails.website')
            self.form.fields['firstname'].field.required = True
            contactFields = self.form.groups[0].fields
            contactFields['IContactDetails.email'].field.required = True
コード例 #4
0
ファイル: widget.py プロジェクト: upiq/plone.app.z3cform
    def _base_args(self):
        """Method which will calculate _base class arguments.

        Returns (as python dictionary):
            - `pattern`: pattern name
            - `pattern_options`: pattern options
            - `name`: field name
            - `value`: field value

        :returns: Arguments which will be passed to _base
        :rtype: dict
        """
        args = super(RelatedItemsWidget, self)._base_args()

        args['name'] = self.name
        args['value'] = self.value
        args.setdefault('pattern_options', {})

        field = None
        if IChoice.providedBy(self.field):
            args['pattern_options']['maximumSelectionSize'] = 1
            field = self.field
        elif ICollection.providedBy(self.field):
            field = self.field.value_type

        vocabulary_name = self.vocabulary

        field_name = self.field and self.field.__name__ or None

        context = self.context
        view_context = get_widget_form(self)
        # For EditForms and non-Forms (in tests), the vocabulary is looked
        # up on the context, otherwise on the view
        if (IEditForm.providedBy(view_context)
                or not IForm.providedBy(view_context)):
            view_context = context

        args['pattern_options'] = dict_merge(
            get_relateditems_options(
                view_context,
                args['value'],
                self.separator,
                vocabulary_name,
                self.vocabulary_view,
                field_name,
            ), args['pattern_options'])
        if (not self.vocabulary_override and field
                and getattr(field, 'vocabulary', None)):
            # widget vocab takes precedence over field
            form_url = self.request.getURL()
            source_url = '{0:s}/++widget++{1:s}/@@getSource'.format(
                form_url, self.name)
            args['pattern_options']['vocabularyUrl'] = source_url

        return args
コード例 #5
0
ファイル: widget.py プロジェクト: sauzher/plone.app.z3cform
 def _view_context(self):
     view_context = get_widget_form(self)
     # For EditForms and non-Forms (in tests), the vocabulary is looked
     # up on the context, otherwise on the view
     if IEditForm.providedBy(view_context):
         if self.is_subform_widget():
             view_context = self.form.parentForm.context
         elif not ISimpleItem.providedBy(self.context):
             view_context = self.form.context
         else:
             view_context = self.context
     elif not IForm.providedBy(view_context):
         view_context = self.context
     return view_context
コード例 #6
0
def change_skin(event):
    # Skip when registry cannot be found
    try:
        registry = getUtility(IRegistry)
    except ComponentLookupError:
        return

    # Skip global registry
    if not isinstance(registry, LocalRegistry):
        return

    # Skip unset values
    try:
        settings = registry.forInterface(ILocalSkin)
    except KeyError:
        return

    # Find context
    context = getContextFromRequest(event.request)

    # Skip context, which cannot change skin
    if not hasattr(context, 'changeSkin'):
        return

    # Skip edit forms of objects with ILocalSkin-behavior
    if ILocalSkin(context, None) is not None:
        published = event.request.get('PUBLISHED', None)
        form = getattr(published, 'form', None)
        if IEditForm.implementedBy(form):
            return

    # Get the vocabulary to match against
    vocabulary = getUtility(
        IVocabularyFactory,
        name='collective.behavior.localskin.vocabularies.skinnames'
    )(context)

    # Change valid skinname when possible
    if settings.skinname in vocabulary:
        context.changeSkin(settings.skinname)
コード例 #7
0
    def update(self):
        isForm = IEditForm.providedBy(self.form) or IAddForm.providedBy(
            self.form)
        if not isForm:
            return

        if not hasattr(self.form, 'portal_type'):
            return

        if self.form.portal_type == 'organization':
            self.remove('logo')
            self.remove('activity')
            self.remove('IContactDetails.im_handle')
            self.remove('IContactDetails.country')
            self.remove('IContactDetails.cell_phone')
            self.remove('IContactDetails.fax')
            self.remove('IContactDetails.region')
            sm = getSecurityManager()
            if not sm.checkPermission('RIC: Administer website', self.context):
                self.form.fields['IBasic.title'].mode = 'display'
                self.form.fields['organization_type'].mode = 'display'
            contactFields = self.form.groups[0].fields
            #contactFields['IContactDetails.email'].field.required = True

        elif self.form.portal_type == 'person':
            self.remove('gender')
            self.remove('person_title')
            self.remove('photo')
            self.remove('IContactDetails.im_handle')
            self.remove('IContactDetails.fax')
            self.remove('IContactDetails.country')
            self.remove('IContactDetails.region')
            self.remove('IContactDetails.website')
            self.form.fields['firstname'].field.required = True
            contactFields = self.form.groups[0].fields
            contactFields['IContactDetails.email'].field.required = True
コード例 #8
0
ファイル: extender.py プロジェクト: sgeulette/ric.core
    def update(self):
        isForm = IEditForm.providedBy(self.form) or IAddForm.providedBy(self.form)
        if not isForm:
            return

        if not hasattr(self.form, 'portal_type'):
            return

        if self.form.portal_type == 'organization':
            self.remove('logo')
            self.remove('activity')
            self.remove('IContactDetails.im_handle')
            self.remove('IContactDetails.country')
            contactFields = self.form.groups[0].fields
            contactFields['IContactDetails.email'].field.required = True

        elif self.form.portal_type == 'person':
            self.remove('gender')
            self.remove('person_title')
            self.remove('photo')
            self.remove('IContactDetails.im_handle')
            self.remove('IContactDetails.country')
            contactFields = self.form.groups[0].fields
            contactFields['IContactDetails.email'].field.required = True
コード例 #9
0
    def _base_args(self):
        """Method which will calculate _base class arguments.

        Returns (as python dictionary):
            - `pattern`: pattern name
            - `pattern_options`: pattern options
            - `name`: field name
            - `value`: field value

        :returns: Arguments which will be passed to _base
        :rtype: dict
        """
        args = super(RelatedItemsWidget, self)._base_args()

        args['name'] = self.name
        args['value'] = self.value
        args.setdefault('pattern_options', {})

        field = None
        if IChoice.providedBy(self.field):
            args['pattern_options']['maximumSelectionSize'] = 1
            field = self.field
        elif ICollection.providedBy(self.field):
            field = self.field.value_type

        vocabulary_name = self.vocabulary

        field_name = self.field and self.field.__name__ or None

        context = self.context
        view_context = get_widget_form(self)
        # For EditForms and non-Forms (in tests), the vocabulary is looked
        # up on the context, otherwise on the view
        if (
            IEditForm.providedBy(view_context) or
            not IForm.providedBy(view_context)
        ):
            view_context = context

        args['pattern_options'] = dict_merge(
            get_relateditems_options(
                view_context,
                args['value'],
                self.separator,
                vocabulary_name,
                self.vocabulary_view,
                field_name,
            ),
            args['pattern_options']
        )
        if (
            not self.vocabulary_override and
            field and
            getattr(field, 'vocabulary', None)
        ):
            # widget vocab takes precedence over field
            form_url = self.request.getURL()
            source_url = '{0:s}/++widget++{1:s}/@@getSource'.format(
                form_url,
                self.name
            )
            args['pattern_options']['vocabularyUrl'] = source_url

        return args
コード例 #10
0
    def _base_args(self):
        """Method which will calculate _base class arguments.

        Returns (as python dictionary):
            - `pattern`: pattern name
            - `pattern_options`: pattern options
            - `name`: field name
            - `value`: field value

        :returns: Arguments which will be passed to _base
        :rtype: dict
        """

        args = super(AjaxSelectWidget, self)._base_args()

        args['name'] = self.name
        args['value'] = self.value

        args.setdefault('pattern_options', {})

        field_name = self.field and self.field.__name__ or None

        context = self.context
        view_context = get_widget_form(self)
        # For EditForms and non-Forms (in tests), the vocabulary is looked
        # up on the context, otherwise on the view
        if (
            IEditForm.providedBy(view_context) or
            not IForm.providedBy(view_context)
        ):
            view_context = context

        vocabulary_name = self.vocabulary
        field = None
        if IChoice.providedBy(self.field):
            args['pattern_options']['maximumSelectionSize'] = 1
            field = self.field
        elif ICollection.providedBy(self.field):
            field = self.field.value_type
        if IChoice.providedBy(field):
            args['pattern_options']['allowNewItems'] = 'false'

        args['pattern_options'] = dict_merge(
            get_ajaxselect_options(view_context, args['value'], self.separator,
                                   vocabulary_name, self.vocabulary_view,
                                   field_name),
            args['pattern_options'])

        if field and getattr(field, 'vocabulary', None):
            form_url = self.request.getURL()
            source_url = '{0:s}/++widget++{1:s}/@@getSource'.format(
                form_url,
                self.name
            )
            args['pattern_options']['vocabularyUrl'] = source_url

        # ISequence represents an orderable collection
        if ISequence.providedBy(self.field) or self.orderable:
            args['pattern_options']['orderable'] = True

        if self.vocabulary == 'plone.app.vocabularies.Keywords':
            membership = getToolByName(context, 'portal_membership')
            user = membership.getAuthenticatedMember()

            registry = getUtility(IRegistry)
            roles_allowed_to_add_keywords = registry.get(
                'plone.roles_allowed_to_add_keywords', [])
            roles = set(user.getRolesInContext(context))

            allowNewItems = 'false'
            if roles.intersection(roles_allowed_to_add_keywords):
                allowNewItems = 'true'
            args['pattern_options']['allowNewItems'] = allowNewItems

        return args
コード例 #11
0
ファイル: widget.py プロジェクト: sauzher/plone.app.z3cform
    def _base_args(self):
        """Method which will calculate _base class arguments.

        Returns (as python dictionary):
            - `pattern`: pattern name
            - `pattern_options`: pattern options
            - `name`: field name
            - `value`: field value

        :returns: Arguments which will be passed to _base
        :rtype: dict
        """
        args = super(RelatedItemsWidget, self)._base_args()

        args['name'] = self.name
        args['value'] = self.value
        args.setdefault('pattern_options', {})

        field = None
        if IChoice.providedBy(self.field):
            args['pattern_options']['maximumSelectionSize'] = 1
            field = self.field
        elif ICollection.providedBy(self.field):
            field = self.field.value_type

        vocabulary_name = self.vocabulary

        field_name = self.field and self.field.__name__ or None

        context = self.context
        view_context = get_widget_form(self)
        # For EditForms and non-Forms (in tests), the vocabulary is looked
        # up on the context, otherwise on the view
        if IEditForm.providedBy(view_context):
            if self.is_subform_widget():
                view_context = self.form.parentForm.context
            elif not ISimpleItem.providedBy(context):
                view_context = self.form.context
            else:
                view_context = context
        elif not IForm.providedBy(view_context):
            view_context = context
        else:
            pass
            # view_context is defined above already

        root_search_mode = (args['pattern_options'].get('mode', None)
                            and 'basePath' not in args['pattern_options'])

        args['pattern_options'] = dict_merge(
            get_relateditems_options(
                view_context,
                args['value'],
                self.separator,
                vocabulary_name,
                self.vocabulary_view,
                field_name,
            ),
            args['pattern_options'],
        )
        if root_search_mode:
            # Delete default basePath option in search mode, when no basePath
            # was explicitly set.
            del args['pattern_options']['basePath']
        if (not self.vocabulary_override and field
                and getattr(field, 'vocabulary', None)):
            # widget vocab takes precedence over field
            form_url = self.request.getURL()
            source_url = '{0:s}/++widget++{1:s}/@@getSource'.format(
                form_url,
                self.name,
            )
            args['pattern_options']['vocabularyUrl'] = source_url

        return args
コード例 #12
0
    def _base_args(self):
        """Method which will calculate _base class arguments.

        Returns (as python dictionary):
            - `pattern`: pattern name
            - `pattern_options`: pattern options
            - `name`: field name
            - `value`: field value

        :returns: Arguments which will be passed to _base
        :rtype: dict
        """

        args = super(AjaxSelectWidget, self)._base_args()

        args['name'] = self.name
        args['value'] = self.value

        args.setdefault('pattern_options', {})

        field_name = self.field and self.field.__name__ or None

        context = self.context
        view_context = get_widget_form(self)
        # For EditForms and non-Forms (in tests), the vocabulary is looked
        # up on the context, otherwise on the view
        if (IEditForm.providedBy(view_context)
                or not IForm.providedBy(view_context)):
            view_context = context

        vocabulary_name = self.vocabulary
        field = None
        if IChoice.providedBy(self.field):
            args['pattern_options']['maximumSelectionSize'] = 1
            field = self.field
        elif ICollection.providedBy(self.field):
            field = self.field.value_type
        if IChoice.providedBy(field):
            args['pattern_options']['allowNewItems'] = 'false'

        args['pattern_options'] = dict_merge(
            get_ajaxselect_options(view_context, args['value'], self.separator,
                                   vocabulary_name, self.vocabulary_view,
                                   field_name), args['pattern_options'])

        if field and getattr(field, 'vocabulary', None):
            form_url = self.request.getURL()
            source_url = '{0:s}/++widget++{1:s}/@@getSource'.format(
                form_url,
                self.name,
            )
            args['pattern_options']['vocabularyUrl'] = source_url

        # ISequence represents an orderable collection
        if ISequence.providedBy(self.field) or self.orderable:
            args['pattern_options']['orderable'] = True

        if self.vocabulary == 'plone.app.vocabularies.Keywords':
            membership = getToolByName(context, 'portal_membership')
            user = membership.getAuthenticatedMember()

            registry = getUtility(IRegistry)
            roles_allowed_to_add_keywords = registry.get(
                'plone.roles_allowed_to_add_keywords', [])
            roles = set(user.getRolesInContext(context))

            allowNewItems = 'false'
            if roles.intersection(roles_allowed_to_add_keywords):
                allowNewItems = 'true'
            args['pattern_options']['allowNewItems'] = allowNewItems

        return args
コード例 #13
0
ファイル: info.py プロジェクト: robertmuehsig/opengever.core
 def is_edit_form(self):
     return (IEditForm.providedBy(self.view)
             or IEditForm.providedBy(getattr(self.view, "form_instance", None)))