class IAudio(form.Schema): """ Audio: only audio files are permitted """ fieldset('audio', label=_(u'Tab audio'), fields=['title', 'description', 'file'] ) dexteritytextindexer.searchable('title') title = schema.TextLine( title=_PMF(u'label_title', default=u'Title'), required=True ) dexteritytextindexer.searchable('description') description = schema.Text( title=_PMF(u'label_description', default=u'Summary'), description=_PMF( u'help_description', default=u'Used in item listings and search results.' ), required=False, missing_value=u'', ) file = NamedBlobFile( title=_(u"Please upload a media file"), description=_(u"Only audio files are permitted."), required=True, )
class IFile(form.Schema): """ File: Per adjuntar els fitxers públics i/o privats A la part pública només fitxers PDF """ fieldset('file', label=_(u'Tab file'), fields=['title', 'description', 'visiblefile', 'hiddenfile']) dexteritytextindexer.searchable('title') title = schema.TextLine(title=_PMF(u'label_title', default=u'Title'), required=True) dexteritytextindexer.searchable('description') description = schema.Text( title=_PMF(u'label_description', default=u'Summary'), description=_PMF(u'help_description', default=u'Used in item listings and search results.'), required=False, missing_value=u'', ) visiblefile = NamedBlobFile( title=_(u"Please upload a public file"), description=_(u"Published file description"), required=False, ) hiddenfile = NamedBlobFile( title=_(u"Please upload a reserved file"), description=_(u"Reserved file description"), required=False, )
class ISubpunt(form.Schema): """ Subpunt: Molt similar el PUNT """ fieldset( 'subpunt', label=_(u'Tab subpunt'), fields=['title', 'proposalPoint', 'defaultContent', 'estatsLlista']) dexteritytextindexer.searchable('title') title = schema.TextLine(title=_(u'Subpunt Title'), required=True) form.mode(proposalPoint='hidden') proposalPoint = schema.TextLine(title=_(u'Proposal point number'), required=False) directives.widget(defaultContent=WysiwygFieldWidget) dexteritytextindexer.searchable('defaultContent') defaultContent = schema.Text( title=_(u"Proposal description"), required=False, ) estatsLlista = schema.Choice( title=_(u"Agreement and document labels"), source=llistaEstats, required=True, )
def SubpuntsInside(self, data): """ Retorna les sessions i el seu contingut """ portal_catalog = api.portal.get_tool(name='portal_catalog') folder_path = '/'.join( self.context.getPhysicalPath()) + '/' + data['id'] values = portal_catalog.unrestrictedSearchResults( portal_type=['genweb.organs.subpunt', 'genweb.organs.acord'], sort_on='getObjPositionInParent', path={ 'query': folder_path, 'depth': 1 }) results = [] for obj in values: if self.Anonim(): item = obj._unrestrictedGetObject() if obj.portal_type == 'genweb.organs.acord': if item.agreement: agreement = _(u'[Acord ') + item.agreement + ']' else: agreement = _(u'[Acord sense numeracio]') else: agreement = False results.append( dict(title=obj.Title, absolute_url=item.absolute_url(), proposalPoint=item.proposalPoint, state=item.estatsLlista, portal_type=obj.portal_type, item_path=item.absolute_url_path(), agreement=agreement, id='/'.join( item.absolute_url_path().split('/')[-2:]))) else: item = obj.getObject() item = obj._unrestrictedGetObject() if obj.portal_type == 'genweb.organs.acord': if item.agreement: agreement = _(u'[Acord ') + item.agreement + ']' else: agreement = _(u'[Acord sense numeracio]') else: agreement = False results.append( dict(title=obj.Title, absolute_url=item.absolute_url(), proposalPoint=item.proposalPoint, state=item.estatsLlista, portal_type=obj.portal_type, item_path=item.absolute_url_path(), estats=self.estatsCanvi(obj), css=self.getColor(obj), agreement=agreement, id='/'.join( item.absolute_url_path().split('/')[-2:]))) return results
def action_send(self, action): """ Send the email to the configured mail address in properties and redirect to the front page, showing a status message to say the message was received. """ formData, errors = self.extractData() lang = self.context.language if 'recipients' not in formData or 'fromTitle' not in formData or 'message' not in formData: if lang == 'ca': message = "Falten camps obligatoris: " if lang == 'es': message = "Faltan campos obligatorios: " if lang == 'en': message = "Required fields missing: " IStatusMessage(self.request).addStatusMessage(message, type="error") return # replace hidden fields to maintain correct urls... body = formData['message'].replace('----@@----http:/', 'http://').replace('----@@----https:/', 'https://').encode('utf-8') root_url = api.portal.get().absolute_url() + "/" + lang body = body.replace('resolveuid/', root_url + "/resolveuid/") sender = self.context.aq_parent.fromMail try: self.context.MailHost.send( body, mto=formData['recipients'], mfrom=sender, subject=formData['fromTitle'], encode=None, immediate=False, charset='utf8', msg_type='text/html') api.content.transition(obj=self.context, transition='convocar') addEntryLog(self.context, None, _(u'Sending mail convocatoria'), formData['recipients']) self.context.plone_utils.addPortalMessage( _(u"Missatge enviat correctament"), 'info') except: addEntryLog(self.context, None, _(u'Missatge no enviat'), formData['recipients']) self.context.plone_utils.addPortalMessage( _(u"Missatge no enviat. Comprovi els destinataris del missatge"), 'error') session = self.context session.membresConvocats = formData['membresConvocats'] session.membresConvidats = formData['membresConvidats'] session.adrecaAfectatsLlista = formData['adrecaAfectatsLlista'] session.adrecaLlista = formData['recipients'] session.reindexObject() transaction.commit() return self.request.response.redirect(self.context.absolute_url())
def simulation(self): # Obtenim rol usuari que cal veure i fer la simulació role = str(self.getUserRole()) if role is 'False': return self.request.response.redirect(self.context.absolute_url()) elif role == 'Other': return _(u'Altres') elif role == 'Member': return _(u'Membre') elif role == 'Affected': return _(u'Afectat') else: return self.request.response.redirect(self.context.absolute_url())
class IEsmenar(form.Schema): """ Enviar missatge als membres /mail_message """ name = TextLine(title=_("Nom complet"), description=_("Escriu el teu nom complet"), required=True) email = TextLine(title=_(u"Adreça de correu electrònic"), required=True) comments = schema.Text( title=_(u"Comentaris"), required=True, )
class IExcusar(form.Schema): name = TextLine( title=_(u"Nom i cognoms"), required=False) email = TextLine( title=_(u"Correu electrònic"), required=False) comments = schema.Text( title=_(u"Comentaris"), description=_(u"Descriu el motiu pel qual no pots assistir a la sessió"), required=True, )
def SubPuntsInside(self): """ Retorna les sessions d'aquí dintre (sense tenir compte estat) """ portal_catalog = api.portal.get_tool(name='portal_catalog') folder_path = '/'.join(self.context.getPhysicalPath()) values = portal_catalog.searchResults( portal_type=['genweb.organs.subpunt', 'genweb.organs.acord'], sort_on='getObjPositionInParent', path={ 'query': folder_path, 'depth': 1 }) results = [] if values: for obj in values: item = obj.getObject() if item.portal_type == 'genweb.organs.acord': if item.agreement: agreement = item.agreement else: agreement = _(u"sense numeracio") else: agreement = '' results.append( dict(title=obj.Title, portal_type=obj.portal_type, absolute_url=item.absolute_url(), proposalPoint=item.proposalPoint, item_path=item.absolute_url_path(), state=item.estatsLlista, agreement=agreement, css=utils.getColor(obj))) return results
def __call__(self): # http://localhost:8080/Plone/ca/eetac/organ/session/changeTitle?pk=OLD_ID&name=&value=NEW_ID try: origin_path = '/'.join( self.context.getPhysicalPath()) + '/' + self.request.form['pk'] newvalue = self.request.form['value'] except: return None try: entry = api.content.find(path=origin_path, depth=0)[0] old_id = entry.id entryobj = entry.getObject() container = entryobj.aq_parent chooser = INameChooser(container) new_id = chooser.chooseName(newvalue, entryobj) change_str = entryobj.absolute_url( ) + ' - [' + entry.Title + ' → ' + newvalue + ']' with api.env.adopt_roles(['OG1-Secretari']): container.manage_renameObject(old_id, new_id) newObject = api.content.find(id=new_id, path='/'.join( origin_path.split('/')[:-1]))[0] newobj = newObject.getObject() newobj.title = newvalue newobj.reindexObject() # transaction ok, then write log addEntryLog(self.context, None, _(u"Changed Title"), change_str) # This line is only to bypass the CSRF WARNING # WARNING plone.protect error parsing dom, failure to add csrf token to response for url ... return "Changed Title" except: pass
def render(self): self.context.estatVotacio = 'close' self.context.horaFiVotacio = datetime.datetime.now().strftime( '%d/%m/%Y %H:%M') self.context.reindexObject() transaction.commit() addEntryLog(self.context.__parent__, None, _(u'Tancada votacio acord'), self.context.absolute_url())
def render(self): if self.context.estatVotacio == 'close': self.context.estatVotacio = 'open' self.context.reindexObject() transaction.commit() addEntryLog(self.context.__parent__.__parent__, None, _(u'Reoberta votacio esmena'), self.context.__parent__.absolute_url())
def Punts2Acta(self): """ Retorna els punt en format text per mostrar a l'ordre del dia de les actes """ portal_catalog = api.portal.get_tool(name='portal_catalog') folder_path = '/'.join(self.context.getPhysicalPath()) values = portal_catalog.searchResults( portal_type=['genweb.organs.punt', 'genweb.organs.acord'], sort_on='getObjPositionInParent', path={'query': folder_path, 'depth': 1}) results = [] results.append('<div class="num_acta">') for obj in values: # value = obj.getObject() value = obj._unrestrictedGetObject() if value.portal_type == 'genweb.organs.acord': if value.agreement: agreement = ' [Acord ' + str(value.agreement) + ']' else: agreement = _(u"[Acord sense numerar]") else: agreement = '' results.append('<p>' + str(value.proposalPoint) + '. ' + str(obj.Title) + ' ' + str(agreement) + '</p>') if len(value.objectIds()) > 0: valuesInside = portal_catalog.searchResults( portal_type=['genweb.organs.subpunt', 'genweb.organs.acord'], sort_on='getObjPositionInParent', path={'query': obj.getPath(), 'depth': 1}) for item in valuesInside: subpunt = item.getObject() if subpunt.portal_type == 'genweb.organs.acord': if subpunt.agreement: agreement = ' [Acord ' + str(subpunt.agreement) + ']' else: agreement = _("[Acord sense numerar]") else: agreement = '' results.append('<p style="padding-left: 30px;">' + str(subpunt.proposalPoint) + '. ' + str(item.Title) + ' ' + str(agreement) + '</p>') results.append('</div>') return ''.join(results)
class IPropostapunt(form.Schema): """ """ title = schema.TextLine( title=_(u'Title'), required=True ) description = schema.Text( title=_(u'label_description', default=u'Summary'), required=False, ) directives.widget(text=WysiwygFieldWidget) text = schema.Text( title=_(u"Text"), required=False) signsFile = NamedBlobFile( title=_(u"Please upload a public file"), description=_(u"Published file description"), required=False, ) anexFile = NamedBlobFile( title=_(u"Please upload a reserved file"), description=_(u"Reserved file description"), required=False, )
def render(self): self.context.estatVotacio = 'open' self.context.tipusVotacio = 'public' self.context.horaIniciVotacio = datetime.datetime.now().strftime( '%d/%m/%Y %H:%M') self.context.reindexObject() transaction.commit() addEntryLog(self.context.__parent__, None, _(u'Oberta votacio acord'), self.context.absolute_url())
def isPublic(self): role = _(u'Altres') if self.simulation() == role: review_state = api.content.get_state(self.context) if review_state in ['planificada', 'convocada', 'realitzada']: return False if review_state in ['tancada', 'en_correccio']: return True else: return False
def handleSave(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return self.fix_password_fields(data) self.applyChanges(data) IStatusMessage(self.request).addStatusMessage(_(u'Changes saved'), 'info') self.context.REQUEST.RESPONSE.redirect('@@organs-settings')
def sendVoteEmail(context, vote): context = aq_inner(context) user_email = api.user.get_current().getProperty('email') if user_email: mailhost = getToolByName(context, 'MailHost') portal = api.portal.get() email_charset = portal.getProperty('email_charset') organ = utils.get_organ(context) sender_email = organ.fromMail msg = MIMEMultipart() msg['From'] = sender_email msg['To'] = user_email msg['Subject'] = escape(safe_unicode(_(u'Votació Govern UPC'))) msg['charset'] = email_charset message = """En data {data}, hora {hora}, has votat {vot} l'esmena {esmena} de l'acord {acord} de la sessió {sessio} de l'òrgan {organ}. Missatge automàtic generat per https://govern.upc.edu/""" now = datetime.datetime.now() if context.aq_parent.aq_parent.portal_type == 'genweb.organs.sessio': data = { 'data': now.strftime("%d/%m/%Y"), 'hora': now.strftime("%H:%M"), 'vot': vote, 'esmena': context.title, 'acord': context.aq_parent.title, 'sessio': context.aq_parent.aq_parent.title, 'organ': context.aq_parent.aq_parent.aq_parent.title, } msg.attach(MIMEText(message.format(**data), 'plain', email_charset)) mailhost.send(msg) elif context.aq_parent.aq_parent.portal_type == 'genweb.organs.punt': data = { 'data': now.strftime("%d/%m/%Y"), 'hora': now.strftime("%H:%M"), 'vot': vote, 'esmena': context.title, 'acord': context.aq_parent.title, 'sessio': context.aq_parent.aq_parent.aq_parent.title, 'organ': context.aq_parent.aq_parent.aq_parent.aq_parent.title, } msg.attach(MIMEText(message.format(**data), 'plain', email_charset)) mailhost.send(msg)
def render(self): estatSessio = utils.session_wf_state(self) if estatSessio not in ['realitzada', 'tancada', 'en_correccio']: sendRemoveVoteEmail(self.context) parent = self.context.aq_parent parent.manage_delObjects([self.context.getId()]) transaction.commit() addEntryLog(self.context.__parent__.__parent__, None, _(u'Eliminada votacio esmena'), self.context.__parent__.absolute_url())
class OrgansSettingsEditForm(controlpanel.RegistryEditForm): schema = IOrgansSettings label = _(u'Paràmetres de configuració de Genweb Organs') def updateFields(self): super(OrgansSettingsEditForm, self).updateFields() def updateWidgets(self): super(OrgansSettingsEditForm, self).updateWidgets() def fix_password_fields(self, data): """ Keep the stored value for the password fields not updated in the current request, i.e. those containing a None value. This method is needed since the password fields are not filled with their stored value when the edit form is loaded. """ if not data['ws_key']: data['ws_key'] = self.getContent().ws_key @button.buttonAndHandler(_('Save'), name=None) def handleSave(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return self.fix_password_fields(data) self.applyChanges(data) IStatusMessage(self.request).addStatusMessage(_(u'Changes saved'), 'info') self.context.REQUEST.RESPONSE.redirect('@@organs-settings') @button.buttonAndHandler(_('Cancel'), name='cancel') def handleCancel(self, action): IStatusMessage(self.request).addStatusMessage(_(u'Edit cancelled'), 'info') self.request.response.redirect( '%s/%s' % (self.context.absolute_url(), self.control_panel_view))
class IOrgansSettings(model.Schema): model.fieldset( 'Indicadors', _(u'Indicadors'), fields=['service_id', 'ws_endpoint', 'ws_key'], ) service_id = schema.TextLine( title=_(u"Identificador al servei web d'Indicadors"), description=_(u"Identificador d'Òrgans de govern al servei web"), required=False, ) ws_endpoint = schema.TextLine( title=_(u"URL del servei web"), required=False, ) ws_key = schema.Password( title=_(u"API key del servei web"), required=False, )
def render(self): estatSessio = utils.session_wf_state(self) if estatSessio not in ['realitzada', 'tancada', 'en_correccio']: sendRemoveVoteEmail(self.context) self.context.estatVotacio = None self.context.tipusVotacio = None self.context.infoVotacio = '{}' self.context.horaIniciVotacio = None self.context.horaFiVotacio = None self.context.reindexObject() transaction.commit() addEntryLog(self.context.__parent__, None, _(u'Eliminada votacio acord'), self.context.absolute_url())
def PuntsInside(self): """ Retorna les sessions d'aquí dintre (sense tenir compte estat) """ portal_catalog = api.portal.get_tool(name='portal_catalog') folder_path = '/'.join(self.context.getPhysicalPath()) values = portal_catalog.searchResults(sort_on='getObjPositionInParent', path={ 'query': folder_path, 'depth': 1 }) results = [] for obj in values: if obj.portal_type == 'genweb.organs.acta' or obj.portal_type == 'genweb.organs.audio': # add actas to template for oredering but dont show item = obj.getObject() results.append( dict(id=obj.id, classe='hidden', show=False, agreement=None)) else: item = obj.getObject() if len(item.objectIds()) > 0: inside = True else: inside = False if item.portal_type == 'genweb.organs.acord': if item.agreement: agreement = item.agreement else: agreement = _(u"sense numeracio") else: agreement = '' results.append( dict(title=obj.Title, portal_type=obj.portal_type, absolute_url=item.absolute_url(), item_path=item.absolute_url_path(), proposalPoint=item.proposalPoint, agreement=agreement, state=item.estatsLlista, css=self.getColor(obj), estats=self.estatsCanvi(obj), id=obj.id, show=True, classe="ui-state-grey-impersonate", items_inside=inside)) return results
class IDocument(form.Schema): """ Document: Per marcar si són públics o privats """ fieldset( 'document', label=_(u'Tab document'), fields=['title', 'description', 'defaultContent', 'alternateContent']) dexteritytextindexer.searchable('title') title = schema.TextLine(title=_PMF(u'label_title', default=u'Title'), required=True) dexteritytextindexer.searchable('title') description = schema.Text( title=_PMF(u'label_description', default=u'Summary'), description=_PMF(u'help_description', default=u'Used in item listings and search results.'), required=False, missing_value=u'', ) directives.widget(defaultContent=WysiwygFieldWidget) dexteritytextindexer.searchable('defaultContent') defaultContent = schema.Text( title=_(u"Contingut public"), description=_(u"Default content shown in the document view"), required=False, ) directives.widget(alternateContent=WysiwygFieldWidget) dexteritytextindexer.searchable('alternateContent') alternateContent = schema.Text( title=_(u"Alternate description"), description=_(u"Content used to hide protected content"), required=False, )
def sessio_changed(session, event): """ If organs.session change WF to convoque, sends email and shows the info in the template """ # si passem estat a convocat cal enviar mail de convocatoria... try: # old = _GW(event.status['review_state']) new = _GW(event.transition.new_state_id) # message = (old) + ' →2 ' + (new) addEntryLog(session, None, _(u'Changed workflow state'), new) # add log except: addEntryLog(session, None, _(u'New session created'), session.Title()) # add log if event.transition is None: # Quan crees element també executa aquesta acció, i ID no existeix # Fem el bypass pass else: """ Previ a l'enviament del missatge et troves en un estat intermig, creat només per això, que es diu Convocant (no es veu enlloc) """ if event.transition.id == 'convocant': raise Redirect(session.absolute_url() + '/mail_convocar') if event.transition.id == 'tancar': member = api.user.get(username='******') user = member.getUser() session.changeOwnership(user, recursive=False) owners = session.users_with_local_role("Owner") session.manage_delLocalRoles(owners) if user.getId() == 'admin': session.manage_setLocalRoles(user.getId(), ["Owner"]) else: session.manage_setLocalRoles(user._id, ["Owner"]) session.reindexObjectSecurity() transaction.commit()
def render(self): if 'title' in self.request.form and self.request.form[ 'title'] and self.request.form['title'] != '': item = createContentInContainer(self.context, "genweb.organs.votacioacord", title=self.request.form['title']) item.estatVotacio = 'open' item.tipusVotacio = 'public' item.horaIniciVotacio = datetime.datetime.now().strftime( '%d/%m/%Y %H:%M') item.reindexObject() transaction.commit() addEntryLog(self.context.__parent__, None, _(u'Oberta votacio esmena'), self.context.absolute_url())
class IAcord(form.Schema): """ Acord """ fieldset('acord', label=_(u'Tab acord'), fields=[ 'title', 'proposalPoint', 'agreement', 'defaultContent', 'estatsLlista' ]) dexteritytextindexer.searchable('title') title = schema.TextLine(title=_(u'Acord Title'), required=True) form.mode(proposalPoint='hidden') proposalPoint = schema.TextLine( title=_(u'Proposal point number'), required=False, ) form.mode(agreement='hidden') dexteritytextindexer.searchable('agreement') agreement = schema.TextLine( title=_(u'Agreement number'), required=False, ) directives.widget(defaultContent=WysiwygFieldWidget) dexteritytextindexer.searchable('defaultContent') defaultContent = schema.Text( title=_(u"Proposal description"), required=False, ) estatsLlista = schema.Choice( title=_(u"Agreement and document label"), source=llistaEstats, required=True, ) directives.omitted('estatVotacio') estatVotacio = schema.Choice(title=u'', source=llistaEstatsVotacio, required=False) directives.omitted('tipusVotacio') tipusVotacio = schema.Choice(title=u'', source=llistaTipusVotacio, required=False) directives.omitted('horaIniciVotacio') horaIniciVotacio = schema.Text(title=u'', required=False) directives.omitted('horaFiVotacio') horaFiVotacio = schema.Text(title=u'', required=False) directives.omitted('infoVotacio') infoVotacio = schema.Text(title=u'', required=False, default=u'{}')
def update(self): super(Edit, self).update() try: if self.context.visiblefields: folder_title = self.context.aq_parent.aq_parent.title.lower() if folder_title in [ 'centres docents', 'departaments', 'instituts de recerca', 'escola de doctorat' ]: self.context.visiblefields = False self.context.reindexObject() transaction.commit() IStatusMessage(self.request).addStatusMessage( _(u'Visible fields disabled: In the calendar visible on the public cover, it only shows the planned sessions of certain public governing bodies of the UPC.' ), 'info') except: pass
def remove_subpunt(trans, obj=None, parent=None): portal_catalog = api.portal.get_tool(name='portal_catalog') items = portal_catalog.searchResults( portal_type=['genweb.organs.subpunt', 'genweb.organs.acord'], sort_on='getObjPositionInParent', path={ 'query': parent.absolute_url_path(), 'depth': 1 }) index = 1 # Assign proposalPoints to acord and subpunts if items: sufix = str(items[0].proposalPoint).split('.')[0] for item in items: newobjecte = item.getObject() newobjecte.proposalPoint = str(sufix) + str('.') + str(index) index = index + 1 addEntryLog(obj.aq_parent.aq_parent, None, _(u'Deleted subpunt'), str(obj.Title())) transaction.commit()
def action_send(self, action): """ Send the email to the configured mail address in properties and redirect to the front page, showing a status message to say the message was received. """ formData, errors = self.extractData() lang = self.context.language if 'comments' not in formData: if lang == 'ca': message = "Falten camps obligatoris: " if lang == 'es': message = "Faltan campos obligatorios: " if lang == 'en': message = "Required fields missing: " IStatusMessage(self.request).addStatusMessage(message, type="error") return addExcuse(self.context, self.widgets["name"].value or formData['name'], self.widgets["email"].value or formData['email'], self.widgets["comments"].value) self.context.plone_utils.addPortalMessage(_(u"Missatge enviat correctament"), 'info') return self.request.response.redirect(self.context.absolute_url())