class ImportContactForm(AutoExtensibleForm, Form): label = _("Import contacts") schema = IImportCSVFormSchema template = ViewPageTemplateFile("import.pt") ignoreContext = True @button.buttonAndHandler(_("Import"), name="import") def action_import(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return csv_file = data["csv_file"] if csv_file is NOT_CHANGED: # avoid traceback or double treatment return importer = ContactsImporter(csv_file.data) # validate contacts values errors = importer.validate() if errors: self.status = self.formErrorsMessage self.errors_details = errors else: # import contacts number = importer.create_contacts(self.context) self.status = _("Imported ${number} contacts successfully !", mapping={"number": number})
def add_ifind_folder(context, current_lang): i_find_folder = api.content.create( container=context, type="imio.smartweb.Folder", title=translate(_("I find"), target_language=current_lang), ) api.content.transition(i_find_folder, "publish") collection = api.content.create( container=i_find_folder, type="Collection", title=translate(_("Procedures and practical informations"), target_language=current_lang), ) collection.query = [{ "i": "portal_type", "o": "plone.app.querystring.operation.selection.any", "v": ["imio.smartweb.Procedure"], }] api.content.transition(collection, "publish") request = getRequest() request.form = { "cid": "page-category", "faceted.page-category.index": "taxonomy_procedure_category", "faceted.page-category.vocabulary": "collective.taxonomy.procedure_category", } handler = getMultiAdapter((collection, request), name="faceted_update_criterion") handler.edit(**request.form)
def __call__(self, context=None): """vcard spec : home, work""" values = [ ("home", _("Personal email")), ("work", _("Work email")), ] terms = [SimpleTerm(value=t[0], token=t[0], title=t[1]) for t in values] return SimpleVocabulary(terms)
def __call__(self, context=None): values = [ ("facebook", _("Facebook")), ("twitter", _("Twitter")), ("website", _("Website")), ] terms = [SimpleTerm(value=t[0], token=t[0], title=t[1]) for t in values] return SimpleVocabulary(terms)
class IUrlRowSchema(Interface): type = schema.Choice( title=_("Type"), source="imio.directory.vocabulary.SiteTypes", description=_(""), required=True, ) url = schema.URI(title=_("Url"), required=True)
def __call__(self, context=None): """vcard spec : cell, home, work, text, voice, fax, video, pager, textphone""" values = [ ("fax", _("Fax")), ("cell", _("Mobile")), ("home", _("Personal phone")), ("work", _("Work phone")), ] terms = [SimpleTerm(value=t[0], token=t[0], title=t[1]) for t in values] return SimpleVocabulary(terms)
class IPrivateContactInformations(model.Schema): model.fieldset( "private_contact_informations", label=_("Private contact informations"), fields=[ "private_phones", "private_mails", "private_urls", "private_note" ], ) private_phones = schema.List( title=_("Phones"), value_type=DictRow( title="Value", schema=IPhoneRowSchema, ), required=False, ) widget("private_phones", DataGridFieldFactory, allow_reorder=True) private_mails = schema.List( title=_("E-mails"), value_type=DictRow( title="Value", schema=IMailRowSchema, ), required=False, ) widget("private_mails", DataGridFieldFactory, allow_reorder=True) private_urls = schema.List( title=_("URLs"), value_type=DictRow( title="Value", schema=IUrlRowSchema, ), required=False, ) widget("private_urls", DataGridFieldFactory, allow_reorder=True) private_note = schema.Text(title=_("Internal note"), required=False) read_permission( private_phones="imio.directory.core.ViewContactPrivateInformations", private_mails="imio.directory.core.ViewContactPrivateInformations", private_urls="imio.directory.core.ViewContactPrivateInformations", private_note="imio.directory.core.ViewContactPrivateInformations", ) write_permission( private_phones="imio.directory.core.ModifyContactPrivateInformations", private_mails="imio.directory.core.ModifyContactPrivateInformations", private_urls="imio.directory.core.ModifyContactPrivateInformations", private_note="imio.directory.core.ModifyContactPrivateInformations", )
def validate_phone(value, value_type): errors = [] if re.match(PHONE_RE, value) is None: msg = _( "Bad phone format '${val}' (good format sample: +32444556677).", mapping={"val": value}, ) errors.append(msg) if not is_in_vocab("imio.directory.vocabulary.PhoneTypes", value_type): msg = _( "Chosen phone type '${val}' doesn't exist.", mapping={"val": value_type}, ) errors.append(msg) return errors
def validate_mail(value, value_type): errors = [] if re.match(EMAIL_RE, value) is None: msg = _( "Bad mail format '${val}' (good format sample: [email protected]).", mapping={"val": value}, ) errors.append(msg) if not is_in_vocab("imio.directory.vocabulary.MailTypes", value_type): msg = _( "Chosen mail type '${val}' doesn't exist.", mapping={"val": value_type}, ) errors.append(msg) return errors
def updateWidgets(self): super(ContactCustomEditForm, self).updateWidgets() if "IGeolocatable.geolocation" in self.widgets: self.widgets["IGeolocatable.geolocation"].description = _( "The geolocation is generated on the basis of the address during contact save. " "It is possible to change the pointer manually if it is not correctly positioned." )
def validate_url(value, value_type): errors = [] if re.match(URL_RE, value) is None: msg = _( "Bad URL format '${val}' (good format sample: https://www.imio.be).", mapping={"val": value}, ) errors.append(msg) if not is_in_vocab("imio.directory.vocabulary.SiteTypes", value_type): msg = _( "Chosen URL type '${val}' doesn't exist.", mapping={"val": value_type}, ) errors.append(msg) return errors
class IMailRowSchema(Interface): label = schema.TextLine( title=_("Label (Secretariat, Manager office, Sales,...)"), description=_(""), required=False, ) type = schema.Choice( title=_("Type"), source="imio.directory.vocabulary.MailTypes", description=_(""), required=True, ) mail_address = schema.Email(title=_("E-mail"), required=True)
def validate_country(value): if not value: return elif not is_in_vocab("imio.smartweb.vocabulary.Countries", value): return _( "Chosen country '${val}' doesn't exist (good format sample: be, fr).", mapping={"val": value}, )
def add_iam_folder(context, current_lang): i_am_folder = api.content.create( container=context, type="imio.smartweb.Folder", title=translate(_("I am"), target_language=current_lang), ) api.content.transition(i_am_folder, "publish") i_am_vocabulary = get_vocabulary("imio.smartweb.vocabulary.IAm") for term in i_am_vocabulary: link = api.content.create( container=i_am_folder, type="Link", title=translate(_(term.title), target_language=current_lang), ) link.remoteUrl = "{0}/@@search?iam={1}".format("${portal_url}", term.token) api.content.transition(link, "publish")
def __call__(self, context=None): values = [ ( "organization", _( "Organization (administrative service, business, professional, sports club, association, etc.)" ), ), ( "position", _( "Position (mayor, alderman, advisor, director, head of department, etc.)" ), ), ("mission", _("Mission (passports, reception, parking, etc.)")), ] terms = [SimpleTerm(value=t[0], token=t[0], title=t[1]) for t in values] return SimpleVocabulary(terms)
class IPhoneRowSchema(Interface): label = schema.TextLine( title=_("Label (direction, Main number,...)"), description=_(""), required=False, ) type = schema.Choice( title=_("Type"), source="imio.directory.vocabulary.PhoneTypes", description=_(""), required=True, ) number = schema.TextLine( title=_("Number (format: +32475010203)"), required=True, constraint=phone_constraint, )
class IContactInformations(model.Schema): model.fieldset( "contact_informations", label=_("Contact informations"), fields=["vat_number", "phones", "mails", "urls"], ) vat_number = schema.TextLine(title=_("VAT number"), required=False) phones = schema.List( title=_("Phones"), value_type=DictRow( title="Value", schema=IPhoneRowSchema, ), required=False, ) widget("phones", DataGridFieldFactory, allow_reorder=True) mails = schema.List( title=_("E-mails"), value_type=DictRow( title="Value", schema=IMailRowSchema, ), required=False, ) widget("mails", DataGridFieldFactory, allow_reorder=True) urls = schema.List( title=_("URLs"), value_type=DictRow( title="Value", schema=IUrlRowSchema, ), required=False, ) widget("urls", DataGridFieldFactory, allow_reorder=True)
def __call__(self, context=None): values = [ ("accessibility", _("Accessibility (PMR)")), ("defibrillator", _("Defibrillator")), ("drinking_water_point", _("Drinking water point")), ("useful_numbers", _("Useful numbers")), ("public_toilets", _("Public toilets")), ("free_wifi", _("Free WIFI")), ] terms = [SimpleTerm(value=t[0], token=t[0], title=t[1]) for t in values] return SimpleVocabulary(terms)
class IContact(IPrivateContactInformations, IContactInformations, IAddress): """ """ directives.order_before(type="IBasic.title") directives.widget(type=RadioFieldWidget) type = schema.Choice( title=_("Type"), source="imio.directory.vocabulary.ContactTypes", required=True, ) directives.order_after(subtitle="IBasic.title") subtitle = schema.TextLine(title=_("Subtitle"), required=False) logo = NamedBlobImage(title=_("Logo"), description=_(""), required=False) model.fieldset("categorization", fields=["selected_entities", "facilities"]) directives.widget(selected_entities=SelectFieldWidget) selected_entities = schema.List( title=_("Selected entities"), description= _("Select entities where this contact will be displayed. Current entity will always be selected." ), value_type=schema.Choice( vocabulary="imio.directory.vocabulary.EntitiesUIDs"), default=[], required=False, ) facilities = schema.List( title=_("Facilities"), description= _("Important! These categories make it possible to highlight and geolocate certain basic services" ), value_type=schema.Choice( vocabulary="imio.directory.vocabulary.Facilities"), required=False, ) directives.widget(facilities=SelectFieldWidget) read_permission(selected_entities="imio.directory.core.AddEntity") write_permission(selected_entities="imio.directory.core.AddEntity")
def validate(self): errors = [] if self.contact_type is None: errors.append(_("Contact type is missing.")) else: errors.append(validate_type(self.contact_type)) if self.title is None: errors.append(_("Contact title is missing.")) if self.zipcode is not None and not self.zipcode.isdigit(): errors.append( _("Zipcode '${val}' is not a number.", mapping={"val": self.zipcode})) errors.append(validate_country(self.country)) for phone in self.phones: errors += validate_phone(phone.get("number"), phone.get("type")) for mail in self.mails: errors += validate_mail(mail.get("mail_address"), mail.get("type")) for url in self.urls: errors += validate_url(url.get("url"), url.get("type")) for topic in self.topics: if not is_in_vocab("imio.smartweb.vocabulary.Topics", topic): errors.append( _("Chosen topic '${val}' doesn't exist.", mapping={"val": topic})) for facility in self.facilities: if not is_in_vocab("imio.directory.vocabulary.Facilities", facility): errors.append( _( "Chosen facility '${val}' doesn't exist.", mapping={"val": facility}, )) for iam in self.iam: if not is_in_vocab("imio.smartweb.vocabulary.IAm", iam): errors.append( _("Chosen i am term '${val}' doesn't exist.", mapping={"val": iam})) errors = [e for e in errors if e] return errors
def action_import(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return csv_file = data["csv_file"] if csv_file is NOT_CHANGED: # avoid traceback or double treatment return importer = ContactsImporter(csv_file.data) # validate contacts values errors = importer.validate() if errors: self.status = self.formErrorsMessage self.errors_details = errors else: # import contacts number = importer.create_contacts(self.context) self.status = _("Imported ${number} contacts successfully !", mapping={"number": number})
def phone_constraint(value): if re.match(r"\+\d{7,15}", value) is None: raise FormatterValidationError(_("Bad phone format"), value) return True
class IImportCSVFormSchema(Interface): csv_file = NamedFile(title=_("CSV file"))
def validate_type(value): if not value: return elif not is_in_vocab("imio.directory.vocabulary.ContactTypes", value): return _("Chosen contact type '${val}' doesn't exist.", mapping={"val": value})