def update(self): super(SettingsEditForm, self).update() # !! groups are updated outside and after updateWidgets # we will display unconfigured fields filt_groups = { 'incomingmail': 'imail_fields', 'outgoingmail': 'omail_fields' } for grp in self.groups: if grp.__name__ not in filt_groups: continue wdg = grp.widgets[filt_groups[grp.__name__]] def_values = [row['field_name'] for row in wdg.value] voc_name = wdg.field.value_type.schema['field_name'].vocabularyName voc = getUtility(IVocabularyFactory, voc_name)(self.context) unconfigured = [ '"{}"'.format(t.title) for t in voc._terms if t.value not in def_values ] if unconfigured: wdg.field = copy.copy(wdg.field) wdg.field.description = u'{}<br />{}'.format( _tr(u'Configure this carefully. You can order with arrows.' ), _tr(u"<span class='unconfigured-fields'>Unconfigured fields are: ${list}</span>", mapping={'list': u', '.join(unconfigured)}))
def TreatingGroupsWithDeactivatedVocabulary__call__(self, context): active_orgs = get_organizations(only_selected=True) not_active_orgs = [ org for org in get_organizations(only_selected=False) if org not in active_orgs ] res_active = [] for active_org in active_orgs: org_uid = active_org.UID() res_active.append( SimpleTerm( org_uid, org_uid, safe_unicode(active_org.get_full_title(first_index=1)))) res = humansorted(res_active, key=attrgetter('title')) res_not_active = [] for not_active_org in not_active_orgs: org_uid = not_active_org.UID() res_not_active.append( SimpleTerm( org_uid, org_uid, _tr('${element_title} (Inactive)', mapping={ 'element_title': safe_unicode( not_active_org.get_full_title(first_index=1)) }))) res = res + humansorted(res_not_active, key=attrgetter('title')) return SimpleVocabulary(res)
def AssignedUsersWithDeactivatedVocabulary__call__(self, context): factory = getUtility(IVocabularyFactory, 'plone.principalsource.Users') vocab = factory(context) # terms as username, userid, fullname a_terms = [] d_terms = [] active_orgs = get_registry_organizations() functions = [dic['fct_id'] for dic in get_registry_functions()] for term in vocab: for group in api.group.get_groups(username=term.value): if group.id == 'AuthenticatedUsers': continue parts = group.id.split('_') if len(parts) != 1: group_suffix = '_'.join(parts[1:]) if group_suffix in functions and parts[ 0] not in active_orgs: # not an active org continue term.title = term.title.decode('utf8') a_terms.append(term) break else: term.title = _tr( '${element_title} (Inactive)', mapping={'element_title': safe_unicode(term.title)}) d_terms.append(term) return SimpleVocabulary( [SimpleTerm(EMPTY_STRING, EMPTY_STRING, _('Empty value'))] + humansorted(a_terms, key=attrgetter('title')) + humansorted(d_terms, key=attrgetter('title')))
def get_pt_fields_voc(pt, excluded): terms = [] for name, field in get_schema_fields(type_name=pt, prefix=True): if name in excluded: continue terms.append(SimpleTerm(name, title=_tr(field.title))) return SimpleVocabulary(humansorted(terms, key=attrgetter('title')))
def test_validate_settings(self): """ Check invariant """ invariants = validator.InvariantsValidator(None, None, None, IImioDmsMailConfig, None) # test omail_send_modes part data = { 'omail_send_modes': [{ 'dtitle': u'Lettre', 'active': True, 'value': u'email' }] } self.assertFalse(invariants.validate(data)) data = { 'omail_send_modes': [{ 'dtitle': u'Lettre', 'active': True, 'value': u'bad' }] } errors = invariants.validate(data) self.assertTrue(isinstance(errors[0], Invalid)) error_msg = _tr( msgid= u"Outgoingmail tab: send_modes field must have values starting with 'post' or 'email'" ) self.assertEqual(_tr(errors[0].message), error_msg) # test imail_group_encoder rec = 'imio.dms.mail.browser.settings.IImioDmsMailConfig.imail_group_encoder' api.portal.set_registry_record(rec, True) data = { 'omail_send_modes': [], 'imail_group_encoder': False } # needs omail_send_modes !! errors = invariants.validate(data) self.assertTrue(isinstance(errors[0], Invalid)) error_msg = u"Courrier entrant: décocher le paramètre 'Activation de plusieurs groupes d'indicatage' n'est " \ u"pas prévu !" self.assertEqual( _tr(errors[0].message, mapping={ 'tab': _tr('Incoming mail'), 'field': _tr('Activate group encoder') }), error_msg)
def __call__(self): result = [] query = self.request.get('term') if not query: return json.dumps(result) self.request.response.setHeader("Content-type", "application/json") query = parse_query(query) hp, org_bis = [], [] all_str = _tr('All under') portal_path = '/'.join(api.portal.get().getPhysicalPath()) # search held_positions in personnel-folder crit = { 'portal_type': 'held_position', 'path': '%s/contacts/personnel-folder' % portal_path, 'sort_on': 'sortable_title', 'sort_order': 'ascending' # 'sort_on': ['end', 'sortable_title'], 'sort_order': ['descending', 'ascending'] # solr error } crit.update(query) brains = self.context.portal_catalog(**crit) for brain in brains: hp.append({'id': brain.UID, 'text': brain.get_full_title}) # search organizations in plonegroup-organization folder crit = { 'portal_type': ('organization'), 'sort_on': 'sortable_title', 'path': '%s/contacts/plonegroup-organization' % portal_path } crit.update(query) brains = self.context.portal_catalog(**crit) make_bis = (len(hp) + len(brains)) > 1 and True or False for brain in brains: result.append({'id': brain.UID, 'text': brain.get_full_title}) if make_bis: org_bis.append({ 'id': 'l:%s' % brain.UID, 'text': '%s [%s]' % (brain.get_full_title, all_str) }) result += hp result += org_bis return json.dumps(result)
def __call__(self): result = [] query = self.request.get('term') if not query: return json.dumps(result) self.request.response.setHeader("Content-type", "application/json") query = parse_query(query) hp, org_bis = [], [] all_str = _tr('All under') # search held_positions crit = {'portal_type': 'held_position', 'sort_on': 'sortable_title'} crit.update(query) pc = self.context.portal_catalog brains = pc(**crit) for brain in brains: hp.append({'id': brain.UID, 'text': brain.get_full_title}) # search organizations crit = {'portal_type': ('organization'), 'sort_on': 'sortable_title'} crit.update(query) brains = pc(**crit) make_bis = (len(hp) + len(brains)) > 1 and True or False for brain in brains: result.append({'id': brain.UID, 'text': brain.get_full_title}) if make_bis: org_bis.append({ 'id': 'l:%s' % brain.UID, 'text': '%s [%s]' % (brain.get_full_title, all_str) }) result += hp # search persons crit = {'portal_type': ('person'), 'sort_on': 'sortable_title'} crit.update(query) brains = pc(**crit) for brain in brains: result.append({'id': brain.UID, 'text': brain.get_full_title}) # add organizations bis result += org_bis return json.dumps(result)
def update_site(self): # add documentation message if u'⏺' not in api.portal.get_registry_record( 'collective.contact.core.interfaces.IContactCoreParameters.' 'contact_source_metadata_content'): api.portal.set_registry_record( 'collective.contact.core.interfaces.IContactCoreParameters.' 'contact_source_metadata_content', u'{gft} ⏺ {number}, {street}, {zip_code}, {city} ⏺ {email}') api.portal.set_registry_record( 'collective.contact.core.interfaces.IContactCoreParameters.' 'display_below_content_title_on_views', True) if not api.portal.get_registry_record( 'imio.dms.mail.browser.settings.IImioDmsMailConfig.imail_fields_order' ): api.portal.set_registry_record( 'imio.dms.mail.browser.settings.IImioDmsMailConfig.imail_fields_order', [ 'IDublinCore.title', 'IDublinCore.description', 'sender', 'treating_groups', 'ITask.assigned_user', 'recipient_groups', 'reception_date', 'ITask.due_date', 'mail_type', 'reply_to', 'ITask.task_description', 'external_reference_no', 'original_mail_date', 'internal_reference_no' ]) if not api.portal.get_registry_record( 'imio.dms.mail.browser.settings.IImioDmsMailConfig.omail_fields_order' ): api.portal.set_registry_record( 'imio.dms.mail.browser.settings.IImioDmsMailConfig.omail_fields_order', [ 'IDublinCore.title', 'IDublinCore.description', 'recipients', 'treating_groups', 'ITask.assigned_user', 'sender', 'recipient_groups', 'mail_type', 'mail_date', 'reply_to', 'ITask.task_description', 'ITask.due_date', 'outgoing_date', 'external_reference_no', 'internal_reference_no' ]) # update front-page frontpage = self.portal['front-page'] if frontpage.Title() == 'Gestion du courrier 2.1': frontpage.setTitle(_tr("front_page_title")) frontpage.setDescription(_tr("front_page_descr")) frontpage.setText(_tr("front_page_text"), mimetype='text/html') # message if 'new-version' not in self.portal['messages-config']: add_message( 'new-version', 'Version 2.2', u'<p>Vous êtes passés à la version d\'iA.docs 2.2 !</p>' u'<p>La <a href="https://www.imio.be/support/documentation/topic/cp_app_ged" target="_blank">' u'documentation</a> a été mise à jour et comporte plusieurs nouvelles sections, dont ' u'<a href="https://www.imio.be/support/documentation/manual/gestion-de-courriers/' u'introduction/les-nouvelles-fonctionnalites-de-la-version-2.2" target="_blank">' u'une page sur les nouveautés</a>.</p>', msg_type='warning', can_hide=True, req_roles=['Authenticated'], activate=True) if ('indispo' in self.portal['messages-config'] and api.content.get_state( self.portal['messages-config']['indispo']) == 'activated'): api.content.transition(self.portal['messages-config']['indispo'], 'deactivate')
def getLinkContent(self, item): return u"""<img title="%s" src="%s" />""" % ( _tr(u"Mailing"), '%s/%s' % (self.table.portal_url, self.iconName))
def __call__(self): # 1 send email body = self.context.email_body msg = create_html_email(body.raw) for a_uid in self.context.email_attachments or []: a_obj = uuidToObject(a_uid, unrestricted=True) if a_obj: title = a_obj.title if a_obj.file.filename: title = a_obj.file.filename if PMH_ENABLED: title = unidecode(title) add_attachment(msg, title, content=a_obj.file.data) mailhost = get_mail_host(check=False) replyto_key = 'imio.dms.mail.browser.settings.IImioDmsMailConfig.omail_replyto_email_send' if mailhost.smtp_host == u'localhost' and not PMH_ENABLED: api.portal.show_message(_( 'Your email has not been sent: ${error}.', mapping={'error': _(u'Cannot use localhost as smtp')}), self.request, type='error') return elif api.portal.get_registry_record(replyto_key, default=False): ret, error = send_email(msg, self.context.email_subject, mailhost.smtp_uid, self.context.email_recipient, self.context.email_cc, replyto=self.context.email_sender) else: ret, error = send_email(msg, self.context.email_subject, self.context.email_sender, self.context.email_recipient, self.context.email_cc) if ret: api.portal.show_message(_('Your email has been sent.'), self.request) else: api.portal.show_message(_( 'Your email has not been sent: ${error}.', mapping={'error': error}), self.request, type='error') return # 2 Update status on omail now = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M') status = _tr(u'Email sent at ${date_hour}.', mapping={'date_hour': now}) if not self.context.email_status: self.context.email_status = status else: self.context.email_status += u' {}'.format(status) modified(self.context) # 3 Close if necessary close = api.portal.get_registry_record( 'imio.dms.mail.browser.settings.IImioDmsMailConfig.' 'omail_close_on_email_send') if close: trans = { 'created': [ 'mark_as_sent', 'propose_to_be_signed', 'set_validated', 'propose_to_n_plus_1' ], 'scanned': ['mark_as_sent'], 'proposed_to_n_plus_1': ['mark_as_sent', 'propose_to_be_signed', 'set_validated'], 'to_be_signed': ['mark_as_sent'], 'validated': ['propose_to_be_signed', 'mark_as_sent'] } state = api.content.get_state(self.context) i = 0 while state != 'sent' and i < 10: transitions(self.context, trans.get(state, [])) state = api.content.get_state(self.context) i += 1