def isGoodImportFile(data): # NOQA nfile = getattr(data, 'zip_file', None) if nfile is None: # let required validator handle this return None if not zipfile.is_zipfile(StringIO(data.zip_file.data)): raise Invalid( _(u"Error: The file submitted must be a zip archive."), )
class ZipImportForm(z3c.form.form.AddForm): label = _(u'Import Ambidexterity resources') description = _( u"You may import view and script resources by uploading a zip archive. " u"The zip archive should either be an Ambidexterity export archive, " u"or must be structured in exactly the same way.") fields = z3c.form.field.Fields(IZipImport) id = 'import-zip-form' def create(self, data): return ZipImport(**data) def add(self, zip_import): summary = utilities.importResourcesZip( StringIO(zip_import.zip_file.data)) audit.resynchronize_all() messages = IStatusMessage(self.request) messages.add(_(u"Import results:\n") + summary) def nextURL(self): url = self.context.absolute_url() + '/@@ambidexterityeditor' return url
class IZipImport(Interface): """ Fields for a zip import form """ zip_file = NamedFile( title=_(u'Ambidexterity archive file'), required=True, ) @invariant def isGoodImportFile(data): # NOQA nfile = getattr(data, 'zip_file', None) if nfile is None: # let required validator handle this return None if not zipfile.is_zipfile(StringIO(data.zip_file.data)): raise Invalid( _(u"Error: The file submitted must be a zip archive."), )
def add(self, zip_import): summary = utilities.importResourcesZip( StringIO(zip_import.zip_file.data)) audit.resynchronize_all() messages = IStatusMessage(self.request) messages.add(_(u"Import results:\n") + summary)
import models import pprint import utilities NO_VIEW_IN_FTI = 1 NO_DEFAULT_IN_FTI = 2 NO_VALIDATOR_IN_FTI = 3 NO_VOCABULARY_IN_FTI = 4 VIEW_TEMPLATE_MISSING = 5 DEFAULT_SCRIPT_MISSING = 6 VALIDATOR_SCRIPT_MISSING = 7 VOCABULARY_SCRIPT_MISSING = 8 WARNING_MESSAGES = { NO_VIEW_IN_FTI: _(u"View template found, but not referenced in FTI."), NO_DEFAULT_IN_FTI: _(u"Default script found, but not referenced in FTI."), NO_VALIDATOR_IN_FTI: _(u"Validator script found, but not referenced in FTI."), NO_VOCABULARY_IN_FTI: _(u"Vocabulary script found, but not referenced in FTI."), VIEW_TEMPLATE_MISSING: _(u"FTI uses ambidexterity view, but template is missing."), DEFAULT_SCRIPT_MISSING: _(u"FTI source model uses ambidexterity default, but script is missing."), VALIDATOR_SCRIPT_MISSING: _(u"FTI source model uses ambidexterity validator, but script is missing." ), VOCABULARY_SCRIPT_MISSING: _(u"FTI source model uses ambidexterity vocabulary, but script is missing."