def __call__(self, context): countries = {} if ISectorContainer.providedBy(context): for country in context.values(): if not ICountry.providedBy(country): continue countries.update({ utils.getRegionTitle(context.REQUEST, country.id, country.title).encode('utf-8'): country.id }) elif ICountry.providedBy(context): countries.update({ utils.getRegionTitle( context.REQUEST, context.id, context.title).encode('utf-8'): context.id }) elif ISector.providedBy(context) or ISurveyGroup.providedBy(context): if ISector.providedBy(context): country = aq_parent(context) elif ISurveyGroup.providedBy(context): country = aq_parent(aq_parent(context)) if ICountry.providedBy(country): countries.update({ utils.getRegionTitle( context.REQUEST, country.id, country.title).encode('utf-8'): country.id }) return SimpleVocabulary.fromItems(sorted(countries.items()))
def __call__(self, context): countries = {} if ISectorContainer.providedBy(context): for country in context.values(): if not ICountry.providedBy(country): continue countries.update({ utils.getRegionTitle(context.REQUEST, country.id, country.title).encode('utf-8'): country.id }) elif ICountry.providedBy(context): countries.update({ utils.getRegionTitle(context.REQUEST, context.id, context.title).encode('utf-8'): context.id }) elif ISector.providedBy(context) or ISurveyGroup.providedBy(context): if ISector.providedBy(context): country = aq_parent(context) elif ISurveyGroup.providedBy(context): country = aq_parent(aq_parent(context)) if ICountry.providedBy(country): countries.update({ utils.getRegionTitle(context.REQUEST, country.id, country.title).encode('utf-8'): country.id }) return SimpleVocabulary.fromItems(sorted(countries.items()))
def organise(self): menu = super(Sitemenu, self).organise() if menu is not None: children = menu["children"] else: menu = {"title": nu_("menu_organise", default="Organise")} children = menu["children"] = [] context_url = aq_inner(self.context).absolute_url() if ISurvey.providedBy(self.context) and checkPermission( self.context, "View"): children.append({ "title": _("menu_export", default="XML export"), "url": "%s/@@export" % context_url, }) if ISector.providedBy(self.context) and checkPermission( self.context, "Euphorie: Add new RIE Content"): children.append({ "title": _("menu_import", default="Import OiRA Tool"), "url": "%s/@@upload" % context_url, }) if children: return menu else: return None
def getToolVersionsInCountry(self, country): tools = [] for sector in country.values(): if not ISector.providedBy(sector): continue tools += self.getToolVersionsInSector(sector) return tools
def sectors(self): sectors_list = [] for sector in self.country.values(): if not ISector.providedBy(sector): continue entry = { "id": sector.id, "login": sector.login, "password": sector.password, "title": sector.title, "url": sector.absolute_url(), "locked": sector.locked, "contact_email": sector.contact_email, } view = sector.restrictedTraverse("manage-ldap-users", None) if not view: entry["managers"] = [] else: entry["managers"] = [ userid for userid in view.local_roles_userids() if view.get_user(userid) ] sectors_list.append(entry) sectors_list.sort(key=lambda s: s["title"].lower()) return sectors_list
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 update(self): for sector in aq_chain(aq_inner(self.context)): if ISector.providedBy(sector): break else: sector = aq_inner(self.context) self.action_url = "%s/@@version-command" % sector.absolute_url() self.surveys = getSurveys(self.context)
def test_sector_statistics(self): sectors = self.portal['sectors'] for country in sectors.values(): if not ICountry.providedBy(country): continue for sector in country.values(): if not ISector.providedBy(country): continue self.__test(sector)
def update(self): super(View, self).update() names = self.request.locale.displayNames.territories self.title = names.get(self.context.id.upper(), self.context.title) self.sectors = [{'id': sector.id, 'title': sector.title, 'url': sector.absolute_url()} for sector in self.context.values() if ISector.providedBy(sector)] try: self.sectors.sort(key=lambda s: s["title"].lower()) except UnicodeDecodeError: self.sectors.sort(key=lambda s: s["title"].lower().decode('utf-8'))
def __call__(self, context): tools = [] if ISectorContainer.providedBy(context): for country in context.values(): if not ICountry.providedBy(country): continue tools += self.getToolsInCountry(country) elif ICountry.providedBy(context): tools += self.getToolsInCountry(context) elif ISector.providedBy(context): tools += self.getToolsInSector(context) elif ISurveyGroup.providedBy(context): tools += self.getToolsInSector(aq_parent(context)) return SimpleVocabulary.fromValues(tools)
def get_library(context): """Get a list of sectors, based on the the euphorie.library registry record :returns: A list of dicts with details for sectors :rtype: list """ record = api.portal.get_registry_record("euphorie.library", default="") if not record: return [] paths = [path.lstrip("/") for path in safe_nativestring(record).split()] if not paths: return [] site = getPortal(context) library = [] for path in paths: try: sector = site.restrictedTraverse(path) except (AttributeError, KeyError): log.warning("Invalid library path (not found): %s" % path) continue if not ISector.providedBy(sector): log.warning("Invalid library path (not a sector): %s", path) continue sector_library = [] survey_groups = [ sg for sg in sector.values() if ISurveyGroup.providedBy(sg) and not sg.obsolete ] for sg in survey_groups: surveys = [s for s in sg.values() if ISurvey.providedBy(s)] if len(surveys) != 1: log.warning( "Ignoring surveygroup due to multiple versions: %s", "/".join(sg.getPhysicalPath()), ) continue tree = build_survey_tree(aq_inner(context), surveys[0]) tree["title"] = sg.title sector_library.append(tree) if sector_library: sector_library.sort(key=lambda s: s["title"]) library.append({ "title": sector.title, "url": sector.absolute_url(), "path": "/".join(sector.getPhysicalPath()), "surveys": sector_library, }) library.sort(key=lambda s: s["title"]) return library
def update(self): super(View, self).update() names = self.request.locale.displayNames.territories # Hook in potential custom country names names.update(CUSTOM_COUNTRY_NAMES) self.title = names.get(self.context.id.upper(), self.context.title) self.sectors = [{ 'id': sector.id, 'title': sector.title, 'url': sector.absolute_url() } for sector in self.context.values() if ISector.providedBy(sector)] try: self.sectors.sort(key=lambda s: s["title"].lower()) except UnicodeDecodeError: self.sectors.sort(key=lambda s: s["title"].lower().decode('utf-8'))
def __init__(self, context, request): super(AccountCreatedNotification, self).__init__(context, request) user = api.portal.get_tool("acl_users").getUser(context.login) if ISector.providedBy(context): self.context_type = u"sector" self.context_title = context.Title() self.contact_name = context.contact_name else: self.context_type = u"country" self.context_title = aq_parent(context).Title() self.contact_name = context.Title() prt = api.portal.get_tool("portal_password_reset") reset = prt.requestReset(user.getId()) self.reset_url="%s/@@reset-password/%s" % ( api.portal.get().absolute_url(), reset["randomstring"] )
def get_library(context): """ Get a list of sectors, based on the configuration in euphorie.ini :returns: A list of dicts with details for sectors :rtype: list """ config = getUtility(IAppConfig).get('euphorie', {}) paths = [path.lstrip('/') for path in config.get('library', '').split()] if not paths: return [] site = getPortal(context) library = [] for path in paths: try: sector = site.restrictedTraverse(path) except (AttributeError, KeyError): log.warning('Invalid library path (not found): %s' % path) continue if not ISector.providedBy(sector): log.warning('Invalid library path (not a sector): %s', path) continue sector_library = [] survey_groups = [sg for sg in sector.values() if ISurveyGroup.providedBy(sg) and not sg.obsolete] for sg in survey_groups: surveys = [s for s in sg.values() if ISurvey.providedBy(s)] if len(surveys) != 1: log.warning('Ignoring surveygroup due to multiple versions: %s', '/'.join(sg.getPhysicalPath())) continue tree = build_survey_tree(aq_inner(context), surveys[0]) tree['title'] = sg.title sector_library.append(tree) if sector_library: sector_library.sort(key=lambda s: s['title']) library.append({'title': sector.title, 'url': sector.absolute_url(), 'path': '/'.join(sector.getPhysicalPath()), 'surveys': sector_library}) library.sort(key=lambda s: s['title']) return library
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 organise(self): menu = super(EuphorieSitemenu, self).organise() if menu is not None: children = menu["children"] else: menu = {"title": nu_("menu_organise", default=u"Organise")} children = menu["children"] = [] context_url = aq_inner(self.context).absolute_url() if ISurvey.providedBy(self.context) and \ checkPermission(self.context, "View"): children.append({"title": _("menu_export", default=u"XML export"), "url": "%s/@@export" % context_url}) if ISector.providedBy(self.context) and \ checkPermission(self.context, "Euphorie: Add new RIE Content"): children.append( {"title": _("menu_import", default=u"Import OiRA Tool"), "url": "%s/@@upload" % context_url}) if children: return menu else: return None
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 CopyToClient(survey, preview=False): """Copy the survey to the online client part of the site. :param survey: the survey to copy :param bool preview: indicates if this is a preview or a normal publication :rtype: :py:class:`euphorie.content.survey.Survey` The public area is hardcoded to be a container with id ``client`` within the site root. The ''id'' and ''title'' of the survey group will be used for the published survey. If another object with the same ''id'' already exists it will be removed first. Any missing country and sector folders are created if needed. If this is a preview (as indicated by the ``preview`` parameter) the id of the survey will be set to ``preview``, guaranteeing that an existing published survey will not be replaced. This also means only a sector can only have one preview online. This method assumes the current user has permissions to create content in the online client. This is normally done by using the :py:func:`PublishToClient` function which switches the current user for the copy operation. Returns the new public survey instance. """ # This is based on OFS.CopyContainer.manage_clone, modified to # use the sector id and title, skip security checks and remove # an existing object with the same id. client = getPortal(survey).client source = aq_inner(survey) surveygroup = aq_parent(source) sector = aq_parent(surveygroup) country = aq_parent(sector) from euphorie.content.sector import ISector assert ISector.providedBy(sector) if country.id not in client: client.invokeFactory("euphorie.clientcountry", country.id, title=country.title, country_type=country.country_type) cl_country = client[country.id] if sector.id not in cl_country: cl_country.invokeFactory("euphorie.clientsector", sector.id) target = cl_country[sector.id] target.title = sector.title target.logo = sector.logo # Clear any scaled logos AnnotationStorage(target).storage.clear() target.main_background_colour = getattr(sector, "main_colour", None) if target.main_background_colour: target.main_foreground_colour = utils.MatchColour( target.main_background_colour, 0.0, 0.6, 0.3) target.main_background_bright = \ utils.IsBright(target.main_background_colour) target.support_background_colour = getattr(sector, "support_colour", None) if target.support_background_colour: target.support_foreground_colour = \ utils.MatchColour(target.support_background_colour) target.support_background_bright = \ utils.IsBright(target.support_background_colour) copy = source._getCopy(target) if preview: copy.id = "preview" else: copy.id = surveygroup.id copy.title = surveygroup.title copy.obsolete = surveygroup.obsolete copy.evaluation_algorithm = surveygroup.evaluation_algorithm copy.version = source.id copy.published = datetime.datetime.now() copy.preview = preview if copy.id in target: # We must suppress events to prevent the can-not-delete-published- # content check from blocking us. # XXX: We need however the ObjectWillBeRemovedEvent event to be called # otherwise the removed objects are not uncatalogged. to_delete = target._getOb(copy.id) notify(ObjectWillBeRemovedEvent(to_delete, target, copy.id)) target._delObject(copy.id, suppress_events=True) target._setObject(copy.id, copy, suppress_events=True) copy = target[copy.id] copy._postCopy(target, op=0) notify(ObjectPublishedEvent(source)) return copy
def get_current_sector(self): for obj in self.context.aq_chain: if ISector.providedBy(obj): return obj