class IndexerEditForm(silvaforms.SMIForm): """Edit form for an indexer. There is not that much to edit however. """ grok.context(IIndexer) grok.require('silva.ReadSilvaContent') grok.implements(IEditScreen) label = _("Update Silva Indexer") description = _( u"An index is not editable. " u"However, you can update the index to include recent added content.") actions = silvaforms.Actions(silvaforms.CancelEditAction()) def update_index_available(self): return checkPermission('silva.ChangeSilvaContent', self.context) @silvaforms.action( _(u"Update index"), accesskey=u"u", available=update_index_available, description=_(u"Update index to include recent added content")) def update_index(self): self.context.update() notify(ObjectModifiedEvent(self.context)) self.send_message(_(u"Index content have been successfully updated."), type="feedback")
class GhostAssetEditForm(silvaforms.SMISubForm): """ Edit form Ghost Folder """ grok.context(IGhostAsset) grok.view(AssetEditTab) grok.order(10) label = _(u'Edit ghost') ignoreContent = False dataManager = silvaforms.SilvaDataManager dataValidators = [TargetValidator('haunted', IAsset, adding=False)] fields = silvaforms.Fields(IGhostAssetSchema).omit('id') actions = silvaforms.Actions(silvaforms.CancelEditAction(), silvaforms.EditAction())
class CSVSourceEditForm(silvaforms.SMISubForm): """CSVSource Edit Form. """ grok.view(AssetEditTab) grok.order(10) label = _('Edit file content') ignoreContent = False dataManager = silvaforms.SilvaDataManager fields = silvaforms.Fields(ICSVSourceFields).omit('id') fields['file'].fileSetLabel = _( "Click the Upload button to replace the current CSV with a new one.") actions = silvaforms.Actions(silvaforms.CancelEditAction(), silvaforms.EditAction())
class ImageEditForm(silvaforms.SMISubForm): """ Edit image attributes """ grok.context(IImage) grok.view(AssetEditTab) grok.order(10) label = _('Edit') ignoreContent = False dataManager = silvaforms.SilvaDataManager fields = silvaforms.Fields(IImageAddFields).omit('id') fields['image'].fileSetLabel = _( "Click the Upload button to replace the current image with a new image." ) actions = silvaforms.Actions(silvaforms.CancelEditAction(), silvaforms.EditAction())
class FileEditForm(silvaforms.SMISubForm): """Edit file. """ grok.context(IFile) grok.view(AssetEditTab) grok.order(10) label = _('Edit file content') ignoreContent = False dataManager = silvaforms.SilvaDataManager fields = silvaforms.Fields(IFileAddFields).omit('id') fields['title'].required = False fields['file'].fileSetLabel = _( "Click the Upload button to replace the current file with a new file.") actions = silvaforms.Actions(silvaforms.CancelEditAction(), silvaforms.EditAction())
class SourceAssetEditForm(silvaforms.SMIEditForm): grok.context(ISourceAsset) actions = silvaforms.Actions(silvaforms.CancelEditAction()) readOnly = False def update(self): editable = self.context.get_editable() if editable is not None: self.controller = editable.get_controller(self.request) else: self.controller = self.context.get_viewable().get_controller( self.request) self.readOnly = True def updateWidgets(self): super(SourceAssetEditForm, self).updateWidgets() if self.controller is not None: self.fieldWidgets.extend( self.controller.fieldWidgets(ignoreRequest=self.readOnly, ignoreContent=False, display=self.readOnly)) @property def formErrors(self): if self.controller is not None: return self.controller.formErrors return [] def isEditable(self): return (self.controller is not None and not self.readOnly and self.controller.mode != silvaforms.DISPLAY) @silvaforms.action(_("Save"), available=isEditable, implements=silvaforms.IDefaultAction, accesskey='ctrl+s') def save(self): status = self.controller.save() if status is silvaforms.SUCCESS: self.send_message(_("Changes saved."), type="feedback") return status
class FileTextEditForm(silvaforms.SMISubForm): """Edit content as a text file. """ grok.context(IFile) grok.view(AssetEditTab) grok.order(20) label = _(u'Edit text content') ignoreContent = False dataManager = silvaforms.SilvaDataManager fields = silvaforms.Fields(IFileTextFields) actions = silvaforms.Actions(silvaforms.CancelEditAction(), silvaforms.EditAction()) def available(self): if self.context.is_text_editable(): try: unicode(self.context.get_text()) return True except (UnicodeDecodeError, TypeError): return False return False
class ImageFormatAndScalingForm(silvaforms.SMISubForm): """ form to resize / change format of image. """ grok.context(IImage) grok.view(AssetEditTab) grok.order(20) ignoreContent = False dataManager = silvaforms.SilvaDataManager label = _('Format and scaling') actions = silvaforms.Actions(silvaforms.CancelEditAction()) fields = silvaforms.Fields(IFormatAndScalingFields) fields['web_format'].mode = 'radio' fields['web_scale'].defaultValue = '100%' @silvaforms.action( title=_('Change'), description=_('Scale and/or crop the image with the new settings'), implements=silvaforms.IDefaultAction) def set_properties(self): data, errors = self.extractData() if errors: return silvaforms.FAILURE try: self.context.set_web_presentation_properties( data.getWithDefault('web_format'), data.getWithDefault('web_scale'), data.getWithDefault('web_crop')) except ValueError as e: self.send_message(e.args[0], type='error') return silvaforms.FAILURE notify(ObjectModifiedEvent(self.context)) self.send_message(_('Scaling and/or format changed.'), type='feedback') return silvaforms.SUCCESS