def __call__(self): ret = "<html><body><h1>User Export</h1>" from euphorie.content.countrymanager import ICountryManager from euphorie.content.sector import ISector for id, country in aq_inner(self.context).objectItems(): if len(id) != 2: continue managers = [ item for item in country.values() if ICountryManager.providedBy(item) ] sectors = [ item for item in country.values() if ISector.providedBy(item) ] if len(managers) + len(sectors) == 0: continue ret += "<h2>{}</h2>".format(country.title) ret += "<h3>Country managers</h3><ul>" for manager in managers: ret += "<li>{}, {}</li>".format(manager.title, manager.contact_email) ret += "</ul>" ret += "<h3>Sector managers</h3><dl>" for sector in sectors: ret += "<dt><strong>Sector: {}</strong></dt><dd>{}, {}</dd>".format( sector.title, sector.contact_name, sector.contact_email) ret += "</dl>" ret += "</body></html>" return ret
def update(self): from euphorie.content.countrymanager import ICountryManager super(ManageUsers, self).update() names = self.request.locale.displayNames.territories country = aq_inner(self.context) self.title = names.get(country.id.upper(), country.title) self.sectors = [{ 'id': sector.id, 'login': sector.login, 'password': sector.password, 'title': sector.title, 'url': sector.absolute_url(), 'locked': sector.locked } for sector in country.values() if ISector.providedBy(sector)] self.sectors.sort(key=lambda s: s["title"].lower()) self.managers = [{ 'id': manager.id, 'login': manager.login, 'title': manager.title, 'url': manager.absolute_url(), 'locked': manager.locked } for manager in country.values() if ICountryManager.providedBy(manager)] self.managers.sort(key=lambda s: s["title"].lower())
def send_country_manager_notifications(self, outdated_tool_paths): country_paths = set() for path in outdated_tool_paths: country_path = '/'.join(path.split('/')[:4]) country_paths.add(country_path) for country_path in country_paths: country_tools = filter( lambda x: x.startswith(country_path), outdated_tool_paths) country = self.context.unrestrictedTraverse(country_path) managers = [ i for i in country.values() if ICountryManager.providedBy(i)] for manager in managers: contact_name = manager.Title() or '' contact_email = manager.contact_email if not contact_email: continue intro = u""" You are receiving this notification since you are the country manager for "{0}" """.format(safe_unicode(country.Title())) self.send_notification( to_name=contact_name, to_address=contact_email, tool_paths=country_tools, intro=intro, )
def send_country_manager_notifications(self, outdated_tool_paths): country_paths = set() for path in outdated_tool_paths: country_path = '/'.join(path.split('/')[:4]) country_paths.add(country_path) for country_path in country_paths: country_tools = filter( lambda x: x.startswith(country_path), outdated_tool_paths) country = self.context.unrestrictedTraverse(country_path) managers = [ i for i in country.values() if ICountryManager.providedBy(i)] for manager in managers: contact_name = manager.Title() or '' contact_email = manager.contact_email if not contact_email: continue intro = u""" You are receiving this notification since you are the country manager for "{0}". """.format(safe_unicode(country.Title())) self.send_notification( to_name=contact_name, to_address=contact_email, tool_paths=country_tools, intro=intro, )
def __call__(self): user = getSecurityManager().getUser() if IMembraneUser.providedBy(user): mt = getToolByName(self.context, "membrane_tool") obj = mt.getUserObject(user_id=user.getUserId()) if ICountryManager.providedBy(obj): return self.request.response.redirect(aq_parent(obj).absolute_url()) return self.request.response.redirect(obj.absolute_url()) portal = aq_inner(self.context) return self.request.response.redirect("%s/sectors/" % portal.absolute_url())
def managers(self): managers_list = [{ "id": manager.id, "login": manager.login, "title": manager.title, "url": manager.absolute_url(), "locked": manager.locked, "contact_email": manager.contact_email, } for manager in self.country.values() if ICountryManager.providedBy(manager)] managers_list.sort(key=lambda s: s["title"].lower()) return managers_list
def render(self): user = getSecurityManager().getUser() if IMembraneUser.providedBy(user): mt = getToolByName(self.context, "membrane_tool") obj = mt.getUserObject(user_id=user.getUserId()) if ICountryManager.providedBy(obj): self.request.response.redirect(aq_parent(obj).absolute_url()) else: self.request.response.redirect(obj.absolute_url()) else: portal = aq_inner(self.context) self.request.response.redirect( "%s/sectors/" % portal.absolute_url())
def __call__(self): from euphorie.content.countrymanager import ICountryManager from euphorie.content.sector import ISector fieldnames = ["fullname", "email"] buffer = StringIO() writer = csv.DictWriter(buffer, fieldnames=fieldnames, dialect="bilbomatica") writer.writerow(dict((fn, fn) for fn in fieldnames)) for id, country in aq_inner(self.context).objectItems(): if len(id) != 2: continue managers = [ item for item in country.values() if ICountryManager.providedBy(item) ] sectors = [ item for item in country.values() if ISector.providedBy(item) ] for manager in managers: data = dict( fullname=safe_unicode(manager.title).encode("utf-8"), email=safe_unicode(manager.contact_email).encode("utf-8"), ) writer.writerow(data) for sector in sectors: data = dict( fullname=safe_unicode(sector.contact_name).encode("utf-8"), email=safe_unicode(sector.contact_email).encode("utf-8"), ) writer.writerow(data) csv_data = buffer.getvalue() buffer.close() response = self.request.RESPONSE response.setHeader("Content-Disposition", "attachment; filename=oira_admin_users.csv") response.setHeader("Content-Type", "text/csv;charset=utf-8") return csv_data
def update(self): from euphorie.content.countrymanager import ICountryManager super(ManageUsers, self).update() names = self.request.locale.displayNames.territories country = aq_inner(self.context) self.title = names.get(country.id.upper(), country.title) self.sectors = [{'id': sector.id, 'login': sector.login, 'password': sector.password, 'title': sector.title, 'url': sector.absolute_url(), 'locked': sector.locked} for sector in country.values() if ISector.providedBy(sector)] self.sectors.sort(key=lambda s: s["title"].lower()) self.managers = [{'id': manager.id, 'login': manager.login, 'title': manager.title, 'url': manager.absolute_url(), 'locked': manager.locked} for manager in country.values() if ICountryManager.providedBy(manager)] self.managers.sort(key=lambda s: s["title"].lower())
def update(self): context = aq_inner(self.context) portal = getPortal(context) currentUrl = self.request.getURL()[len(portal.absolute_url()):] user = getSecurityManager().getUser() if IMembraneUser.providedBy(user): mt = getToolByName(self.context, "membrane_tool") user_object = mt.getUserObject(user_id=user.getUserId()) else: user_object = None for (test, id) in self.current_map: if test.match(currentUrl): current = id break else: current = None results = [{ "id": "sectors", "title": _("nav_surveys", default=u"OiRA Tools"), "url": portal.sectors.absolute_url(), "class": "current" if current == "sectors" else None }] if checkPermission(portal, "Manage portal"): for country in aq_chain(context): if ICountry.providedBy(country): url = "%s/@@manage-users" % country.absolute_url() break else: countries = sorted(portal.sectors.keys()) url = "%s/@@manage-users" % \ portal.sectors[countries[0]].absolute_url() results.append({ "id": "usermgmt", "title": _("nav_usermanagement", default=u"User management"), "url": url, "class": "current" if current == "usermgmt" else None }) results.append({ "id": "documents", "title": _("nav_documents", default=u"Documents"), "url": portal.documents.absolute_url(), "class": "current" if current == "documents" else None }) elif ICountryManager.providedBy(user_object): country = aq_parent(user_object) results.append({ "id": "usermgmt", "title": _("nav_usermanagement", default=u"User management"), "url": "%s/@@manage-users" % country.absolute_url(), "class": "current" if current == "usermgmt" else None }) if user_object is not None: country = aq_parent(user_object) results.append({ "id": "help", "title": _("nav_help", default=u"Help"), "url": "%s/help" % country.absolute_url(), "class": "current" if current == "help" else None }) self.tabs = results self.home_url = portal.absolute_url()
def update(self): context = aq_inner(self.context) portal = getPortal(context) currentUrl = self.request.getURL()[len(portal.absolute_url()):] user = getSecurityManager().getUser() if IMembraneUser.providedBy(user): mt = getToolByName(self.context, "membrane_tool") user_object = mt.getUserObject(user_id=user.getUserId()) else: user_object = None for (test, id) in self.current_map: if test.match(currentUrl): current = id break else: current = None results = [{"id": "sectors", "title": _("nav_surveys", default=u"OiRA Tools"), "url": portal.sectors.absolute_url(), "class": "current" if current == "sectors" else None}] if checkPermission(portal, "Manage portal"): for country in aq_chain(context): if ICountry.providedBy(country): url = "%s/@@manage-users" % country.absolute_url() break else: countries = sorted(portal.sectors.keys()) url = "%s/@@manage-users" % \ portal.sectors[countries[0]].absolute_url() results.append({"id": "usermgmt", "title": _("nav_usermanagement", default=u"User management"), "url": url, "class": "current" if current == "usermgmt" else None}) results.append({"id": "documents", "title": _("nav_documents", default=u"Documents"), "url": portal.documents.absolute_url(), "class": "current" if current == "documents" else None}) elif ICountryManager.providedBy(user_object): country = aq_parent(user_object) results.append({"id": "usermgmt", "title": _("nav_usermanagement", default=u"User management"), "url": "%s/@@manage-users" % country.absolute_url(), "class": "current" if current == "usermgmt" else None}) if user_object is not None: country = aq_parent(user_object) results.append({"id": "help", "title": _("nav_help", default=u"Help"), "url": "%s/help" % country.absolute_url(), "class": "current" if current == "help" else None}) self.tabs = results self.home_url = portal.absolute_url()