def __call__(self): """ This method gets called everytime the template needs to be rendered """ # This is needed so the actions bar will be shown. # the one with the actions, display, add item and workflow drop downs. portal_membership = getToolByName(self.context, 'portal_membership') if not portal_membership.isAnonymousUser(): alsoProvides(self, IViewView) form = self.request.form path = '/'.join(self.context.getPhysicalPath()) # Here we know if the user requested to export the organizations. export_organizations = form.get('form.button.export_org', False) # This is necessary in case this method gets called and no button was # pressed. In that case it will just render the template if export_organizations: # If the export action was requested we provide # a download dialog. The export will be done in csv format return exportOrganizations(self.context, self.request, path, format='csv') return self.pt()
def __call__(self): """ This method gets called everytime the template needs to be rendered """ # XXX: This should be reviewed and changed to use portal_form_controller form = self.request.form if self.context.meta_type == 'Group': # Means i'm exporting persons from inside a group. I should form # the path from my parent path = '/'.join(self.context.aq_inner.aq_parent.getPhysicalPath()) else: path = '/'.join(self.context.getPhysicalPath()) # Here we know if the user requested to export the users # the organizations or to send mails to them. mailto = form.get('form.button.mailto', False) export_persons = form.get('form.button.export_persons', False) export_organizations = form.get('form.button.export_org', False) mailto_group = form.get('form.button.mailto_group', False) advanced_persons = form.get('form.button.advanced_persons', False) advanced_organizations = form.get('form.button.advanced_organizations', False) # This is necessary in case this method gets called and no button was # pressed. In that case it will just render the template if mailto or export_persons or export_organizations: # In any case we ask for the user selection # Now the selections come in a list formed of the id's and the # emails, using a space as a separator, so we now separate them if not form.has_key('user_selection') and not form.has_key('no_mail'): aux = _(u'You need to select at least one person or ' 'organization') status = zope.i18n.translate(aux, context=self.request) url = self.context.absolute_url() + \ '/search_addressbook?error_message=%s' % (status,) return self.request.response.redirect(url) elif not form.has_key('user_selection') and mailto: aux = _(u'You need to select at least one person or ' 'organization that has an email') status = zope.i18n.translate(aux, context=self.request) url = self.context.absolute_url() + \ '/search_addressbook?error_message=%s' % (status,) return self.request.response.redirect(url) if form.has_key('user_selection'): ids = [i.split(' ')[0] for i in form['user_selection']] if form.has_key('no_mail'): if not isinstance(form['no_mail'], list): ids_nomail = [form['no_mail'].strip()] else: ids_nomail = [i.strip() for i in form['no_mail']] ids = ids + ids_nomail mails = [i.split(' ')[1] for i in form['user_selection']] else: if not isinstance(form['no_mail'], list): ids = [form['no_mail'].strip()] else: ids = [i.strip() for i in form['no_mail']] mails = [] self.request.string_emails = ', '.join(mails) if export_persons: # If the export action was requested we will be using the # users selections to first filter and then we provide # a download dialog. The export will be done in csv format return exportPersons(self.context, self.request, path, ids, 'csv') if export_organizations: # If the export action was requested we will be using the # users selections to first filter and then we provide # a download dialog. The export will be done in csv format return exportOrganizations(self.context, self.request, path, ids, 'csv') if mailto_group: if not form.has_key('user_selection'): aux = _(u'You need to select at least one group') status = zope.i18n.translate(aux, context=self.request) url = self.context.absolute_url() + \ '/search_addressbook?error_message=%s' % (status,) return self.request.response.redirect(url) resulting_mails = [] for i in form['user_selection']: addresses = i.split(',') for i in addresses: if i not in resulting_mails and i != '': resulting_mails.append(i) self.request.string_emails = ', '.join(resulting_mails) if self.request.string_emails == '': aux = _(u'There are no persons to send an email to') status = zope.i18n.translate(aux, context=self.request) url = self.context.absolute_url() + \ '/search_addressbook?error_message=%s' % (status,) return self.request.response.redirect(url) if advanced_persons: url = self.context.absolute_url() + '/personssearch_view' return self.request.response.redirect(url) if advanced_organizations: url = self.context.absolute_url() + '/organizationssearch_view' return self.request.response.redirect(url) return self.pt()