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(DateWidget, self)._base_args() args['name'] = self.name args['value'] = (self.request.get(self.name, self.value) or u'').strip() args.setdefault('pattern_options', {}) args['pattern_options'].setdefault('date', {}) args['pattern_options']['date'] = dict_merge( args['pattern_options']['date'], get_date_options(self.request)) args['pattern_options']['time'] = False return args
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(DatetimeWidget, self)._base_args() if args['value'] and len(args['value'].split(' ')) == 1: args['value'] += ' 00:00' args.setdefault('pattern_options', {}) if 'time' in args['pattern_options']: del args['pattern_options']['time'] args['pattern_options'] = dict_merge( get_datetime_options(self.request), args['pattern_options']) return args
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(DatetimeWidget, self)._base_args() if args['value'] and len(args['value'].split(' ')) == 1: args['value'] += ' 00:00' args.setdefault('pattern_options', {}) if 'time' in args['pattern_options']: # Time gets set in parent class to false. Remove. del args['pattern_options']['time'] if 'time' in self.pattern_options: # Re-apply custom set time options. args['pattern_options']['time'] = self.pattern_options['time'] args['pattern_options'] = dict_merge( get_datetime_options(self.request), args['pattern_options']) return args
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(LayoutWidget, self)._base_args() args['name'] = self.name args['value'] = self.value args.setdefault('pattern_options', {}) args['pattern_options'] = dict_merge( self.get_options(), args['pattern_options']) if not self.enabled: args['pattern'] = self.pattern + '-disabled' return args
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(LayoutWidget, self)._base_args() args['name'] = self.name args['value'] = self.value args.setdefault('pattern_options', {}) args['pattern_options'] = dict_merge( self.get_options(), args['pattern_options']) # Disable Mosaic editor when the selected layout for the current # context is not custom layout # XXX: This also always disables the editor outside the content space current_browser_layout = ( self._add_form_portal_type_default_view() or self._context_selected_layout() ) if current_browser_layout not in ['view', '@@view']: args['pattern'] = self.pattern + '-disabled' return args
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(DateWidget, self)._base_args() args['name'] = self.name args['value'] = (self.request.get(self.name, self.value) or u'').strip() args.setdefault('pattern_options', {}) if self.field.required: # Required fields should not have a "Clear" button args['pattern_options']['clear'] = False args['pattern_options'] = dict_merge(get_date_options(self.request), args['pattern_options']) return args
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', {}) if IChoice.providedBy(self.field): args['pattern_options']['maximumSelectionSize'] = 1 field_name = self.field and self.field.__name__ or None args['pattern_options'] = dict_merge( get_relateditems_options(self.context, args['value'], self.separator, self.vocabulary, self.vocabulary_view, field_name), args['pattern_options']) return args
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(DatetimeWidget, self)._base_args() if args['value'] and len(args['value'].split(' ')) == 1: args['value'] += ' 00:00' if args['pattern_options']['time'] is False: args['pattern_options']['time'] = {} args['pattern_options']['time'] = base.dict_merge( args['pattern_options']['time'], get_time_options(self.request)) return args
def _base_args(self, context, field, request): args = super(RelatedItemsWidget, self)._base_args(context, field, request) value = request.get(field.getName(), None) if value is None: value = [IUUID(o) for o in field.getAccessor(context)() if o] else: value = [ v.split('/')[0] for v in value.strip().split(self.separator) ] vocabulary_factory = getattr(field, 'vocabulary_factory', None) if not self.vocabulary: self.vocabulary = vocabulary_factory args['name'] = field.getName() args['value'] = self.separator.join(value) args.setdefault('pattern_options', {}) args['pattern_options']['orderable'] = self.allow_sorting args['pattern_options'] = dict_merge( get_relateditems_options(context, args['value'], self.separator, self.vocabulary, self.vocabulary_view, field.getName()), args['pattern_options']) return args
def _base_args(self, context, field, request): args = super(RelatedItemsWidget, self)._base_args(context, field, request) value = request.get(field.getName(), None) if value is None: value = [IUUID(o) for o in field.getAccessor(context)() if o] else: value = [v.split('/')[0] for v in value.strip().split(self.separator)] vocabulary_factory = getattr(field, 'vocabulary_factory', None) if not self.vocabulary: self.vocabulary = vocabulary_factory args['name'] = field.getName() args['value'] = self.separator.join(value) args.setdefault('pattern_options', {}) args['pattern_options']['orderable'] = self.allow_sorting args['pattern_options'] = dict_merge( get_relateditems_options(context, args['value'], self.separator, self.vocabulary, self.vocabulary_view, field.getName()), args['pattern_options']) return args
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', {}) context = self.context 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(self._ajaxselect_options(), 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', set()) roles = set(user.getRolesInContext(context)) allowNewItems = bool( roles.intersection(roles_allowed_to_add_keywords), ) args['pattern_options']['allowNewItems'] = str( allowNewItems, ).lower() return args
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
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 # We need special handling for AddForms if IAddForm.providedBy(getattr(self, "form")): context = self.form 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 not vocabulary_name and field is not None: vocabulary_name = field.vocabularyName args["pattern_options"] = dict_merge( get_ajaxselect_options( 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 = "%s/++widget++%s/@@getSource" % (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 return args
def _base_args(self, context, field, request): args = super(QueryStringWidget, self)._base_args(context, field, request) args["name"] = field.getName() args["value"] = request.get(field.getName(), json.dumps([dict(c) for c in field.getRaw(context)])) args.setdefault("pattern_options", {}) args["pattern_options"] = dict_merge( get_querystring_options(context, self.querystring_view), args["pattern_options"] ) return args
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 # We need special handling for AddForms if IAddForm.providedBy(getattr(self, 'form')): context = self.form 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 not vocabulary_name and field is not None: vocabulary_name = field.vocabularyName args['pattern_options'] = dict_merge( get_ajaxselect_options(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 = "%s/++widget++%s/@@getSource" % (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 return args
def _base_args(self, context, field, request): args = super(TinyMCEWidget, self)._base_args(context, field, request) args["name"] = field.getName() properties = getToolByName(context, "portal_properties") charset = properties.site_properties.getProperty("default_charset", "utf-8") args["value"] = (request.get(field.getName(), field.getAccessor(context)())).decode(charset) args.setdefault("pattern_options", {}) merged = dict_merge(get_tinymce_options(context, field, request), args["pattern_options"]) args["pattern_options"] = merged return args
def _base_args(self): args = super(RichTextWidget, self)._base_args() args['name'] = self.name value = self.value and self.value.raw_encoded or '' args['value'] = (self.request.get( self.field.getName(), value)).decode('utf-8') args.setdefault('pattern_options', {}) merged = dict_merge(get_tinymce_options(self.context, self.field, self.request), # noqa args['pattern_options']) args['pattern_options'] = merged['pattern_options'] return args
def _base_args(self, context, field, request): """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(DatetimeWidget, self)._base_args(context, field, request) args['name'] = field.getName() args['value'] = (request.get(field.getName(), field.getAccessor(context)())) if args['value'] and isinstance(args['value'], DateTime): args['value'] = ( '{year:}-{month:02}-{day:02} {hour:02}:{minute:02}' ).format( year=args['value'].year(), month=args['value'].month(), day=args['value'].day(), hour=args['value'].hour(), minute=args['value'].minute(), ) elif args['value'] and isinstance(args['value'], datetime): args['value'] = ( '{year:}-{month:02}-{day:02} {hour:02}:{minute:02}' ).format( year=args['value'].year, month=args['value'].month, day=args['value'].day, hour=args['value'].hour, minute=args['value'].minute, ) if args['value'] and len(args['value'].split(' ')) == 1: args['value'] += ' 00:00' args.setdefault('pattern_options', {}) if 'time' in args['pattern_options']: del args['pattern_options']['time'] args['pattern_options'] = dict_merge( get_datetime_options(request), args['pattern_options']) return args
def _base_args(self, context, field, request): args = super(QueryStringWidget, self)._base_args(context, field, request) args['name'] = field.getName() args['value'] = request.get( field.getName(), json.dumps([dict(c) for c in field.getRaw(context)])) args.setdefault('pattern_options', {}) args['pattern_options'] = dict_merge( get_querystring_options(context, self.querystring_view), args['pattern_options']) return args
def _base_args(self): args = super(RichTextWidget, self)._base_args() args["name"] = self.name properties = getToolByName(self.context, "portal_properties") charset = properties.site_properties.getProperty("default_charset", "utf-8") value = self.value and self.value.raw_encoded or "" args["value"] = (self.request.get(self.field.getName(), value)).decode(charset) args.setdefault("pattern_options", {}) merged = dict_merge( get_tinymce_options(self.context, self.field, self.request), args["pattern_options"] # noqa ) args["pattern_options"] = merged["pattern_options"] return args
def _base_args(self): args = super(RichTextWidget, self)._base_args() args['name'] = self.name properties = getToolByName(self.context, 'portal_properties') charset = properties.site_properties.getProperty('default_charset', 'utf-8') value = self.value and self.value.raw_encoded or '' args['value'] = (self.request.get( self.field.getName(), value)).decode(charset) args.setdefault('pattern_options', {}) merged = dict_merge(get_tinymce_options(self.context, self.field, self.request), # noqa args['pattern_options']) args['pattern_options'] = merged['pattern_options'] return args
def _base_args(self, context, field, request): args = super(TinyMCEWidget, self)._base_args(context, field, request) args['name'] = field.getName() properties = getToolByName(context, 'portal_properties') charset = properties.site_properties.getProperty('default_charset', 'utf-8') args['value'] = (request.get(field.getName(), field.getAccessor(context)()) ).decode(charset) args.setdefault('pattern_options', {}) merged = dict_merge(get_tinymce_options(context, field, request), args['pattern_options']) args['pattern_options'] = merged['pattern_options'] return args
def _base_args(self, context, field, request): args = super(TinyMCEWidget, self)._base_args(context, field, request) args['name'] = field.getName() properties = getToolByName(context, 'portal_properties') charset = properties.site_properties.getProperty( 'default_charset', 'utf-8') args['value'] = (request.get( field.getName(), field.getAccessor(context)())).decode(charset) args.setdefault('pattern_options', {}) merged = dict_merge(get_tinymce_options(context, field, request), args['pattern_options']) args['pattern_options'] = merged['pattern_options'] return args
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 if not vocabulary_name: if field is not None and field.vocabularyName: vocabulary_name = field.vocabularyName else: vocabulary_name = 'plone.app.vocabularies.Catalog' field_name = self.field and self.field.__name__ or None args['pattern_options'] = dict_merge( get_relateditems_options(self.context, args['value'], self.separator, vocabulary_name, self.vocabulary_view, field_name), args['pattern_options']) if not self.vocabulary: # widget vocab takes precedence over field if field and getattr(field, 'vocabulary', None): form_url = self.request.getURL() source_url = "%s/++widget++%s/@@getSource" % ( form_url, self.name) args['pattern_options']['vocabularyUrl'] = source_url return args
def _base_args(self, context, field, request): """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(DatetimeWidget, self)._base_args(context, field, request) args['name'] = field.getName() args['value'] = (request.get(field.getName(), field.getAccessor(context)())) if args['value'] and isinstance(args['value'], DateTime): args['value'] = ( '{year:}-{month:02}-{day:02} {hour:02}:{minute:02}').format( year=args['value'].year(), month=args['value'].month(), day=args['value'].day(), hour=args['value'].hour(), minute=args['value'].minute(), ) elif args['value'] and isinstance(args['value'], datetime): args['value'] = ( '{year:}-{month:02}-{day:02} {hour:02}:{minute:02}').format( year=args['value'].year, month=args['value'].month, day=args['value'].day, hour=args['value'].hour, minute=args['value'].minute, ) if args['value'] and len(args['value'].split(' ')) == 1: args['value'] += ' 00:00' args.setdefault('pattern_options', {}) if 'time' in args['pattern_options']: del args['pattern_options']['time'] args['pattern_options'] = dict_merge(get_datetime_options(request), args['pattern_options']) return args
def _base_args(self): args = super(RichTextWidget, self)._base_args() args['name'] = self.name value = self.value and self.value.raw or u'' value = self.request.get(self.name, value) args['value'] = value args.setdefault('pattern_options', {}) merged_options = dict_merge( get_tinymce_options( self.wrapped_context(), self.field, self.request, ), args['pattern_options'], ) args['pattern_options'] = merged_options return args
def rich_text_args(self): args = super(RichTextWidget, self)._base_args() args['name'] = self.name value = self.value and self.value.raw_encoded or '' args['value'] = (self.request.get(self.field.getName(), value)).decode('utf-8') args.setdefault('pattern_options', {}) # displays tinymce editor for anonymous users if api.user.is_anonymous(): add_resource_on_request(self.request, 'mockup-patterns-tinymce-logged-out') merged_options = dict_merge( get_tinymce_options(self.context, self.field, self.request), # noqa args['pattern_options']) args['pattern_options'] = merged_options return args
def _base_args(self): args = super(RichTextWidget, self)._base_args() args['name'] = self.name value = self.value and self.value.raw_encoded or '' args['value'] = (self.request.get( self.field.getName(), value)).decode('utf-8') args.setdefault('pattern_options', {}) merged_options = dict_merge( get_tinymce_options( self.context, self.field, self.request ), args['pattern_options'] ) args['pattern_options'] = merged_options return args
def _base_args(self, context, field, request): """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(DateWidget, self)._base_args(context, field, request) args['name'] = field.getName() args['value'] = (request.get(field.getName(), field.getAccessor(context)())) if args['value'] and isinstance(args['value'], DateTime): args['value'] = ('{year:}-{month:02}-{day:02}').format( year=args['value'].year(), month=args['value'].month(), day=args['value'].day(), ) elif args['value'] and isinstance(args['value'], datetime): args['value'] = ('{year:}-{month:02}-{day:02}').format( year=args['value'].year, month=args['value'].month, day=args['value'].day, ) args.setdefault('pattern_options', {}) args['pattern_options'] = dict_merge( get_date_options(request), args['pattern_options']) if 'date' in args['pattern_options'] and \ 'firstDay' in args['pattern_options']['date'] and \ callable(args['pattern_options']['date']['firstDay']): args['pattern_options']['date']['firstDay'] = \ args['pattern_options']['date']['firstDay']() return args
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", {}) 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 field is not None and field.vocabularyName: vocabulary_name = field.vocabularyName field_name = self.field and self.field.__name__ or None args["pattern_options"] = dict_merge( get_relateditems_options( self.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 = "%s/++widget++%s/@@getSource" % (form_url, self.name) args["pattern_options"]["vocabularyUrl"] = source_url return args
def _base_args(self, context, field, request): """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(DateWidget, self)._base_args(context, field, request) args['name'] = field.getName() args['value'] = (request.get(field.getName(), field.getAccessor(context)())) if args['value'] and isinstance(args['value'], DateTime): args['value'] = ('{year:}-{month:02}-{day:02}').format( year=args['value'].year(), month=args['value'].month(), day=args['value'].day(), ) elif args['value'] and isinstance(args['value'], datetime): args['value'] = ('{year:}-{month:02}-{day:02}').format( year=args['value'].year, month=args['value'].month, day=args['value'].day, ) args.setdefault('pattern_options', {}) args['pattern_options'] = dict_merge(get_date_options(request), args['pattern_options']) if 'date' in args['pattern_options'] and \ 'firstDay' in args['pattern_options']['date'] and \ callable(args['pattern_options']['date']['firstDay']): args['pattern_options']['date']['firstDay'] = \ args['pattern_options']['date']['firstDay']() return args
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(DateWidget, self)._base_args() args["name"] = self.name args["value"] = (self.request.get(self.name, self.value) or u"").strip() args.setdefault("pattern_options", {}) args["pattern_options"] = dict_merge(get_date_options(self.request), args["pattern_options"]) return args
def _base_args(self): args = { 'pattern': self.pattern, 'pattern_options': self.pattern_options.copy(), } context = aq_parent(self.wrapped_context()) args['name'] = self.name properties = getToolByName(context, 'portal_properties') charset = properties.site_properties.getProperty('default_charset', 'utf-8') value = self.value and self.value.raw_encoded or '' args['value'] = (self.request.get( self.field.getName(), value)).decode(charset) args.setdefault('pattern_options', {}) merged = dict_merge(get_tinymce_options(context, self.field, self.request), # noqa args['pattern_options']) args['pattern_options'] = merged return args
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(QueryStringWidget, self)._base_args() args['name'] = self.name args['value'] = self.value args.setdefault('pattern_options', {}) args['pattern_options'] = dict_merge( get_querystring_options(self.context, self.querystring_view), args['pattern_options']) return args
def _base_args(self, context, field, request): args = super(AjaxSelectWidget, self)._base_args(context, field, request) vocabulary_factory = getattr(field, "vocabulary_factory", None) if not self.vocabulary: self.vocabulary = vocabulary_factory args["name"] = field.getName() args["value"] = self.separator.join(request.get(field.getName(), field.getAccessor(context)())) args.setdefault("pattern_options", {}) args["pattern_options"] = dict_merge( get_ajaxselect_options( context, args["value"], self.separator, self.vocabulary, self.vocabulary_view, field.getName() ), args["pattern_options"], ) if self.orderable: args["pattern_options"]["orderable"] = True return args
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 # We need special handling for AddForms if IAddForm.providedBy(getattr(self, 'form')): context = self.form args['pattern_options'] = dict_merge( get_ajaxselect_options(context, args['value'], self.separator, self.vocabulary, self.vocabulary_view, field_name), args['pattern_options']) # ISequence represents an orderable collection if ISequence.providedBy(self.field) or self.orderable: args['pattern_options']['orderable'] = True return args
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(DatetimeWidget, self)._base_args() if args["value"] and len(args["value"].split(" ")) == 1: args["value"] += " 00:00" args.setdefault("pattern_options", {}) if "time" in args["pattern_options"]: del args["pattern_options"]["time"] args["pattern_options"] = dict_merge(get_datetime_options(self.request), args["pattern_options"]) return args
def _base_args(self, context, field, request): args = super(AjaxSelectWidget, self)._base_args(context, field, request) vocabulary_factory = getattr(field, 'vocabulary_factory', None) if not self.vocabulary: self.vocabulary = vocabulary_factory args['name'] = field.getName() args['value'] = self.separator.join( request.get(field.getName(), field.getAccessor(context)())) args.setdefault('pattern_options', {}) args['pattern_options'] = dict_merge( get_ajaxselect_options(context, args['value'], self.separator, self.vocabulary, self.vocabulary_view, field.getName()), args['pattern_options']) if self.orderable: args['pattern_options']['orderable'] = True return args
def _base_args(self, context, field, request): """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(DateWidget, self)._base_args(context, field, request) args["name"] = field.getName() args["value"] = request.get(field.getName(), field.getAccessor(context)()) if args["value"] and isinstance(args["value"], DateTime): args["value"] = ("{year:}-{month:02}-{day:02}").format( year=args["value"].year(), month=args["value"].month(), day=args["value"].day() ) elif args["value"] and isinstance(args["value"], datetime): args["value"] = ("{year:}-{month:02}-{day:02}").format( year=args["value"].year, month=args["value"].month, day=args["value"].day ) args.setdefault("pattern_options", {}) args["pattern_options"] = dict_merge(get_date_options(request), args["pattern_options"]) if ( "date" in args["pattern_options"] and "firstDay" in args["pattern_options"]["date"] and callable(args["pattern_options"]["date"]["firstDay"]) ): args["pattern_options"]["date"]["firstDay"] = args["pattern_options"]["date"]["firstDay"]() return args
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(LayoutWidget, self)._base_args() args['name'] = self.name args['value'] = self.value args.setdefault('pattern_options', {}) args['pattern_options'] = dict_merge(self.get_options(), args['pattern_options']) if not self.enabled: args['pattern'] = self.pattern + '-disabled' return args
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
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
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
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