required=False, ) directives.omitted('creators', 'contributors', 'rights') directives.no_omit(IEditForm, 'creators', 'contributors', 'rights') directives.no_omit(IAddForm, 'creators', 'contributors', 'rights') # make sure the add form shows the default creator def creatorsDefault(data): user = getSecurityManager().getUser() # NB: CMF users are UTF-8 encoded bytes, decode them before inserting return user and (safe_unicode(user.getId()), ) CreatorsDefaultValue = ComputedWidgetAttribute(creatorsDefault, field=IOwnership['creators']) @provider(IFormFieldProvider) class IDublinCore(IOwnership, IPublication, ICategorization, IBasic): """ Metadata behavior providing all the DC fields """ directives.widget('subjects', AjaxSelectFieldWidget, separator=',', vocabulary='ploneintranet.network.vocabularies.Keywords') class Basic(MetadataBase): def _get_title(self):
_ = MessageFactory('bda.plone.productshop') @provider(IFormFieldProvider) class IProductExcludeFromNavigation(IExcludeFromNavigation): """Exclude from navigation behavior for products. Could not find a sane way of providing default values for general behavior attributes based on content interface which the behavior is bound to. Registering ComputedWidgetAttribute to context does not help because context is the container in case of add form instead of a content instance. """ provideAdapter(ComputedWidgetAttribute( lambda data: True, field=IProductExcludeFromNavigation['exclude_from_nav']), name='default') @provider(IFormFieldProvider) class IProductTilesViewSettingsBehavior(model.Schema): """Product tiles view settings behavior. This behavior is not applied to any content types by default. It can be used on folderish objects where product tiles view is enabled in order to configure product tiles view. """ model.fieldset('settings', fields=[ 'product_tiles_view_columns',
return widget @adapter(getSpecification(IEventBasic['end']), IPloneFormLayer) @implementer(IFieldWidget) def EndDateFieldWidget(field, request): widget = FieldWidget(field, DatetimeWidget(request)) widget.first_day = first_weekday_sun0 return widget def default_start(data): return default_start_dt(data.context) provideAdapter(ComputedWidgetAttribute(default_start, field=IEventBasic['start']), name='default') def default_end(data): return default_end_dt(data.context) provideAdapter(ComputedWidgetAttribute(default_end, field=IEventBasic['end']), name='default') def default_tz(data): return default_timezone()
class IRenameForm(Interface): new_id = schema.ASCIILine( title=_(u'label_new_short_name', default=u'New Short Name'), description=_(u'help_short_name_url', default= u'Short name is the part that shows up in the URL ' + u'of the item.'), constraint=valid_id, ) new_title = schema.TextLine( title=_(u'label_new_title', default=u'New Title'), ) default_new_id = ComputedWidgetAttribute( lambda form: form.context.getId(), field=IRenameForm['new_id']) default_new_title = ComputedWidgetAttribute( lambda form: form.context.Title(), field=IRenameForm['new_title']) class RenameForm(form.Form): fields = field.Fields(IRenameForm) template = ViewPageTemplateFile('templates/object_rename.pt') enableCSRFProtection = True ignoreContext = True label = _(u'heading_rename_item', default=u'Rename item') description = _(u'description_rename_item', default= u'Each item has a Short Name and a Title, which you can ' +
except: # in schema editor return False if parent_type == 'person': return False elif parent_type == 'organization' \ and not IOrganization.providedBy(adapter.context) \ and not IPosition.providedBy(adapter.context): return False else: return True DefaultUseParentAddress = ComputedWidgetAttribute( default_use_parent_address, field=IContactDetails['use_parent_address'], view=Interface) DefaultParentAddress = ComputedWidgetAttribute( get_parent_address, field=IContactDetails['parent_address'], view=Interface) def DateFieldWidget(field, request): """IFieldWidget factory for DatetimeWidget.""" widget = FieldWidget(field, DateWidget(request)) currentYear = datetime.date.today().year minimumYearRange = currentYear - 1900 # don't display dates before 1900 widget.years_range = (-minimumYearRange, 1) return widget
@provider(IFormFieldProvider) class IProductExcludeFromNavigation(IExcludeFromNavigation): """Exclude from navigation behavior for products. Could not find a sane way of providing default values for general behavior attributes based on content interface which the behavior is bound to. Registering ComputedWidgetAttribute to context does not help because context is the container in case of add form instead of a content instance. """ provideAdapter( ComputedWidgetAttribute( lambda data: True, field=IProductExcludeFromNavigation["exclude_from_nav"] ), name="default", ) @provider(IFormFieldProvider) class IProductTilesViewSettingsBehavior(model.Schema): """Product tiles view settings behavior. This behavior is not applied to any content types by default. It can be used on folderish objects where product tiles view is enabled in order to configure product tiles view. """ model.fieldset(
logger.warning('Missing layout {0:s}'.format(e)) return u'' def getDefaultContentLayoutContent(adapter): portal_type = getattr(getattr(adapter.view, '__parent__', adapter.view), 'portal_type', None) if portal_type is None: return u'' return getPortalTypeDefaultContentLayoutContent(portal_type) # XXX: It would be best to register this for IAddForm, but if the field # is moved into fieldset using plone.supermodel.directives.fieldset, its # form is actually IGroup, not IAddForm. default_layout_content = ComputedWidgetAttribute( getDefaultContentLayoutContent, view=IGroup, field=ILayoutField) @implementer(ILayoutFieldDefaultValue) @adapter(Interface, IMosaicLayer) def layoutFieldDefaultValue(context, request): if context and ILayoutAware(context, None): return getPortalTypeDefaultContentLayoutContent(context.portal_type) # XXX: Context cannot be used yet, because plone.dexterity does not # bound fields to support context aware default factories layout = absolute_path(CONTENT_LAYOUT_DEFAULT_LAYOUT) # XXX: This is a workaround for a subrequest bug, where parent_app # ends up being a view with publishTraverse returning always NotFound. try:
value = u'' _adapterValueAttributes = Widget._adapterValueAttributes + ('config', ) @adapter(IField, z3c.form.interfaces.IFormLayer) @implementer(z3c.form.interfaces.IFieldWidget) def CkeditorFieldWidget(field, request): """Editor widget bound to a field.""" return FieldWidget(field, CkeditorZ3CFormWidget(request)) # The default configuration for CkeditorZ3CFormWidget Ckeditor_config = ComputedWidgetAttribute( lambda a: CkeditorConfig(), request=IBrowserRequest, widget=ICkeditorWidget, ) # XXX: EditFormCkeditorConfig will now be applied to all add and edit forms. # This is wrong, but we do not have standard SchoolTool add/edit # z3c.forms yet, like we do with formlib; as a result, we do not have # standard interfaces (for example ISchooltoolAddForm) that we could # hook the config on. Ckeditor_addform_config = ComputedWidgetAttribute( lambda a: CkeditorConfig(306, 200), context=None, request=IBrowserRequest, view=z3c.form.interfaces.IAddForm, field=IHtmlFragmentField,