def set_libertic_event_supplier(self, value): uid = self.uid if value and uid: self.groups.addPrincipalToGroup( uid, i.groups['supplier-pending']['id']) # send an email to group moderators data = { 'user' : uid, } moderators = i.settings().group_moderators groupurl = '%s/@@usergroup-usermembership?userid=%s' % ( getToolByName(self.context, 'portal_url')(), uid, ) mailhost = getToolByName(self.context, 'MailHost') SMODERATEGROUP = _( '[LIBERTIC] A new user need to be added to the ' 'suppliers group: ${user}', mapping=data) T = self.context.translate msg = "\n".join( [ T(_('A new user has registered himself on OpenDataEvents website.')), T(_('You can move him to the suppliers group to validate its registration following the next link : ')), " - %s" % groupurl]) sub = self.context.translate(SMODERATEGROUP) utils.sendmail(self.context, moderators, sub, msg) else: self.groups.removePrincipalFromGroup( uid, i.groups['supplier']['id']) self.groups.removePrincipalFromGroup( uid, i.groups['supplier-pending']['id']) return self.context.setMemberProperties({'libertic_event_supplier': value})
def render(self): ret = register_collect_job(self.context) if ret : msg = _('Events will be grabbed, please refresh in a while') else: msg = _('Events are already planned to be fetched, ' 'please refresh in a while') IStatusMessage(self.request).addStatusMessage(msg) self.request.response.redirect( self.context.absolute_url() )
def __call__(self, context): terms = [] types = { 'csv': _('Csv'), 'xml': _('Xml'), 'ical': _('Ical'), 'json': _('json'), } if not self.export: del types['ical'] for term in types: terms.append(SimpleVocabulary.createTerm (term, term, types[term])) return SimpleVocabulary(terms)
def unique_SID_EID_check(context, sid, eid, request=None, form=None, *args, **kw): db = lei.IDatabaseGetter(context).database() event = db.get_event(sid=sid, eid=eid) if event is not None: raise ActionExecutionError( Invalid(_(u"The SID/EID combination is already in use, " "please adapt them.")))
def editable_SID_EID_check(context, sid, eid, request=None, form=None, *args, **kw): db = lei.IDatabaseGetter(context).database() events = [a for a in db.get_events(sid=sid, eid=eid)] uuids = [IUUID(a) for a in events] cuuid = IUUID(context) if (cuuid not in uuids) and bool(uuids): raise ActionExecutionError( Invalid(_(u"The SID/EID combination is already in use, " "please adapt them.")))
def is_latlon(value): try: value = value.split(';') x = float(value[0]) y = float(value[1]) return True except Exception, e: raise Invalid( _('This is not a lat long value, eg : -47.5;48.5') )
def validateDataLicense(self, data=None): if data is None: data = self for url, license in ( ('photos1_url', 'photos1_license'), ('photos2_url', 'photos2_license'), ('video_url', 'video_license'), ('audio_url', 'audio_license'), ): vurl = getattr(data, url, None) vlicense = getattr(data, license, None) if vurl and not vlicense: raise Invalid( _('Missing relative license for ${url}.', mapping = {'url':url,}))
def sideidchars_check(value): for c in ['|', '_', '/']: if c in value: raise Invalid(_('${name} is not allowed', mapping={"name": c})) return True
from Products.CMFCore.utils import getToolByName from plone.app.dexterity.behaviors.metadata import IDublinCore from plone.app.content.interfaces import INameFromTitle from plone.app.dexterity.behaviors.metadata import IPublication from plone.app.dexterity.behaviors.exclfromnav import IExcludeFromNavigation datefmt = '%Y%m%dT%H%M' rdatefmt = "%Y-%m-%d %H:%M:%S" SID_EID_SPLIT = '_/_' source_status = SimpleVocabulary([ SimpleVocabulary.createTerm(0, '0', _(u'FAILURE')), SimpleVocabulary.createTerm(1, '1', _(u'OK')), SimpleVocabulary.createTerm(2, '2', _(u'WARN')) ]) groups = { 'operator' : { 'id': 'libertic_event_operator', 'roles': ['LiberticOperator'], 'title':'Libertic event operator', 'description':'Libertic event operator', }, 'supplier': { 'id': 'libertic_event_supplier', 'roles': ['LiberticSupplier'], 'title':'Libertic event supplier',
def handleApply(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return ev_format = data['ev_format'] ev_fn = data['ev_file'].filename ev_data = data['ev_file'].data if not ev_format and ev_fn: if '.' in ev_fn: ext = ev_fn.split('.')[-1] if ext in ['xml', 'json', 'csv']: ev_format = '%sapi' % ext self.description = [] stats_msg, desc = '', '' __ = self.context.translate if not ev_format: self.status = __(_('Invalid File/Format')) else: results = lei.IEventApiUtil(self.context).mapply( ev_format, ev_data) statuses, nb = {}, 0 if results['status'] == 0: self.status = __( _('There were fatal errors during import')) else: self.status = __( _('Events import has run sucessfully, ' 'please check the following log')) links = OrderedDict() links['created'] = ['<ul>'] links['edited'] = ['<ul>'] links['failed'] = [] if results['status'] > 0: for item in results['results']: nb += 1 res = item.get('status', None) if res: if not res in statuses: statuses[res] = 0 statuses[res] += 1 if res in ['created', 'edited']: if item['url']: links[res].append( '<li>' '<a href="%(url)s">' '%(title)s' '</a>' '</li>' % item ) if res == 'failed': msg = '<ul class="failed-item">' msg += '\n'.join(['<li><pre>%s</pre></li>' % m for m in item['messages']]) msg += '</ul>' links[res].append(msg) links['created'].append('</ul>') links['edited'].append('</ul>') if nb: stats_msg += ( '<div class="lei-import-stats">' '<p>%s</p>' '<ul>') % ( __( _('${nb} Elements processed in the file', mapping={'nb': nb}))) for i in statuses: stats_msg += '<li>%s : %s</li>' % ( __(_(i)), statuses[i] ) stats_msg += '</ul></div>' desc += '<div class="detailed-import">' for i in links: llen = statuses.get(i, 0) if llen: desc += '<dl class="detailed-%s collapsible collapsedOnLoad">' % i desc += '<dt class="collapsibleHeader">%s %s %s</dt>' % ( llen, __(_(i)), __(_('Events'))) desc += '<dd class="collapsibleContent">' desc += '\n'.join(links[i]) desc += '</dd>' desc += '</dl>' desc += '</div>' self.description.append(stats_msg) self.description.append(desc) self.description = '\n'.join(self.description)
def update(self): __ = self.context.translate self.description = __(_( 'Choose the dates between which you want to export events')) super(advanced_export, self).update()
value = self.context.getProperty('ode_contact_telephone', '') return value def set_ode_contact_telephone(self, value): return self.context.setMemberProperties({'ode_contact_telephone': value}) ode_contact_telephone = property(get_ode_contact_telephone, set_ode_contact_telephone) class CustomizedUserDataPanel(UserDataPanel): """/personal-information (preferences personnelles""" def __init__(self, context, request): super(CustomizedUserDataPanel, self).__init__(context, request) self.form_fields = self.form_fields.omit('tgu') class CustomizedUserDataConfiglet(UserDataConfiglet): """/user-information (manage users""" def __init__(self, context, request): super(CustomizedUserDataConfiglet, self).__init__(context, request) self.form_fields = self.form_fields.omit('tgu') from five import grok class libertic_post_create(grok.View): grok.context(Interface) def render(self): """.""" return True _('A new user need to be added to the suppliers group') _('You can manage its groups here:') # vim:set et sts=4 ts=4 tw=80: