def country(self): from euphorie.client.country import IClientCountry for obj in aq_chain(aq_inner(self.context)): if IClientCountry.providedBy(obj): return obj.id else: return None
def enable_custom_risks_on_all_modules(context): """ """ if not api.portal.get_registry_record("euphorie.allow_user_defined_risks"): log.warning( "Custom risks are not enabled. Set 'allow_user_defined_risks' to " "true in euphorie.ini for enabling them." ) return portal = api.portal.get() client = portal.client count = 0 for country in client.objectValues(): if IClientCountry.providedBy(country): for sector in country.objectValues(): if IClientSector.providedBy(sector): for survey in sector.objectValues(): try: is_new = EnableCustomRisks(survey) count += 1 custom = getattr(survey, "custom-risks", None) if custom: custom.title = _( "title_other_risks", default="Added risks (by you)", ) custom.description = _( "description_other_risks", default="In case you have identified risks not included in " # noqa: E501 "the tool, you are able to add them now:", ) custom.question = _( "question_other_risks", default="<p>Would you now like to add your own defined risks " # noqa: E501 "to this tool?</p><p><strong>Important:</strong> In " # noqa: E501 "order to avoid duplicating risks, we strongly recommend you " # noqa: E501 "to go first through all the previous modules, if you have not " # noqa: E501 "done it yet.</p><p>If you don't need to add risks, please select 'No.'</p>", # noqa: E501 ) if is_new: survey.published = ( survey.id, survey.title, datetime.datetime.now(), ) except Exception as e: log.error( "Could not enable custom risks for module. %s" % e ) log.info("All %d published surveys can now have custom risks." % count) session = Session() if TableExists(session, "tree"): session.execute( "UPDATE tree SET title = 'title_other_risks' WHERE zodb_path ='custom-risks'" # noqa: E501 ) model.metadata.create_all(session.bind, checkfirst=True) datamanager.mark_changed(session) transaction.get().commit() log.info("Set correct title on all exisiting sessions for custom risks module.")
def update(self): """ The frontpage has been disbanded. We redirect to the country that is defined as the default, or pick a random country. """ target = None language = self.request.form.get("language") url_param = language and "?language=%s" % language or "" if self.default_country: if getattr(aq_base(self.context), self.default_country, None): found = getattr(self.context, self.default_country) if IClientCountry.providedBy(found): target = found while not target: for id, found in self.context.objectItems(): if IClientCountry.providedBy(found): target = found self.request.RESPONSE.redirect("{}{}".format( target.absolute_url(), url_param))
def countries(self): return sorted( [{ "id": country.getId(), "Title": getRegionTitle(self.request, country.getId()), } for country in self.request.client.values() if (IClientCountry.providedBy(country) and len(country.objectIds())) ], key=lambda co: "0" if co["id"] == "eu" else co["Title"], )
def country_url(self): """Return the absolute URL for country page.""" sector = self.sector if sector is not None: return aq_parent(sector).absolute_url() for parent in aq_chain(aq_inner(self.context)): if IClientCountry.providedBy(parent): return parent.absolute_url() return None
def __call__(self): """The frontpage has been disbanded. We redirect to the country that is defined as the default, or pick a random country. """ target = None language = self.request.form.get("language") url_param = language and "?language=%s" % language or "" if self.default_country: if getattr(aq_base(self.context), self.default_country, None): found = getattr(self.context, self.default_country) if IClientCountry.providedBy(found): target = found if not target: for id, found in self.context.objectItems(): if IClientCountry.providedBy(found): target = found break if not target: return "No country was identified" self.request.RESPONSE.redirect("{}{}".format(target.absolute_url(), url_param))
def country_url(self): """Return the absolute URL for country page.""" sector = self.sector if sector is not None: return aq_parent(sector).absolute_url() from euphorie.client.country import IClientCountry for parent in aq_chain(aq_inner(self.context)): if IClientCountry.providedBy(parent): return parent.absolute_url() return None
def enable_custom_risks_on_all_modules(context): """ """ appconfig = zope.component.getUtility(IAppConfig) if not asBool(appconfig["euphorie"].get("allow_user_defined_risks")): log.warning( "Custom risks are not enabled. Set 'allow_user_defined_risks' to " "true in euphorie.ini for enabling them.") return portal = api.portal.get() client = portal.client count = 0 for country in client.objectValues(): if IClientCountry.providedBy(country): for sector in country.objectValues(): if IClientSector.providedBy(sector): for survey in sector.objectValues(): try: is_new = EnableCustomRisks(survey) count += 1 custom = getattr(survey, 'custom-risks', None) if custom: custom.title = _( u'title_other_risks', default=u"Added risks (by you)") custom.description = _( u"description_other_risks", default= u"In case you have identified risks not included in " u"the tool, you are able to add them now:") custom.question = _( u"question_other_risks", default= u"<p>Would you now like to add your own defined risks " u"to this tool?</p><p><strong>Important:</strong> In " u"order to avoid duplicating risks, we strongly recommend you " u"to go first through all the previous modules, if you have not " u"done it yet.</p><p>If you don't need to add risks, please select 'No.'</p>" ) if is_new: survey.published = (survey.id, survey.title, datetime.datetime.now()) except Exception, e: log.error( "Could not enable custom risks for module. %s" % e)
def publishTraverse(self, request, name): request.survey = self.context utils.setLanguage(request, self.context, self.context.language) if name not in ["view", "index_html"] and \ not self.hasValidSession(request): request.response.redirect( aq_parent(aq_parent(self.context)).absolute_url(), lock=True) return self.context if name not in self.phases: return super(SurveyPublishTraverser, self)\ .publishTraverse(request, name) # Decorate the request with the right skin layer and add to the aq path # Some countries need to be marked specially. Check if this needs to be # done, and decorate the reques accordingly if yes. special = False for obj in aq_chain(aq_inner(self.context)): if IClientCountry.providedBy(obj): if obj.id in self.countries: special = True directlyProvides( request, self.countries[obj.id][name], *directlyProvidedBy(request)) break if not special: directlyProvides(request, self.phases[name], *directlyProvidedBy(request)) self.context = PathGhost(name).__of__(self.context) session = SessionManager.session tree_id = find_sql_context(session.id, request['TraversalRequestNameStack']) if tree_id is not None: return build_tree_aq_chain(self.context, tree_id) # No SQL based traversal possible, return the existing context with the # new skin layer applied return self.context
def publishTraverse(self, request, name): request.survey = self.context utils.setLanguage(request, self.context, self.context.language) if name not in ["view", "index_html"] and \ not self.hasValidSession(request): request.response.redirect(aq_parent(aq_parent( self.context)).absolute_url(), lock=True) return self.context if name not in self.phases: return super(SurveyPublishTraverser, self)\ .publishTraverse(request, name) # Decorate the request with the right skin layer and add to the aq path # Some countries need to be marked specially. Check if this needs to be # done, and decorate the reques accordingly if yes. special = False for obj in aq_chain(aq_inner(self.context)): if IClientCountry.providedBy(obj): if obj.id in self.countries: special = True directlyProvides(request, self.countries[obj.id][name], *directlyProvidedBy(request)) break if not special: directlyProvides(request, self.phases[name], *directlyProvidedBy(request)) self.context = PathGhost(name).__of__(self.context) session = SessionManager.session tree_id = find_sql_context(session.id, request['TraversalRequestNameStack']) if tree_id is not None: return build_tree_aq_chain(self.context, tree_id) # No SQL based traversal possible, return the existing context with the # new skin layer applied return self.context
def enable_custom_risks_on_all_modules(context): """ """ appconfig = zope.component.getUtility(IAppConfig) if not asBool(appconfig["euphorie"].get("allow_user_defined_risks")): log.warning( "Custom risks are not enabled. Set 'allow_user_defined_risks' to " "true in euphorie.ini for enabling them.") return portal = api.portal.get() client = portal.client count = 0 for country in client.objectValues(): if IClientCountry.providedBy(country): for sector in country.objectValues(): if IClientSector.providedBy(sector): for survey in sector.objectValues(): try: is_new = EnableCustomRisks(survey) count += 1 custom = getattr(survey, 'custom-risks', None) if custom: custom.title = _(u'title_other_risks', default=u"Added risks (by you)") custom.description = _( u"description_other_risks", default=u"In case you have identified risks not included in " u"the tool, you are able to add them now:") custom.question = _( u"question_other_risks", default=u"<p>Would you now like to add your own defined risks " u"to this tool?</p><p><strong>Important:</strong> In " u"order to avoid duplicating risks, we strongly recommend you " u"to go first through all the previous modules, if you have not " u"done it yet.</p><p>If you don't need to add risks, please select 'No.'</p>") if is_new: survey.published = ( survey.id, survey.title, datetime.datetime.now()) except Exception, e: log.error("Could not enable custom risks for module. %s" % e)
def __init__(self, context, request): from euphorie.client.session import SessionManager from euphorie.client.country import IClientCountry super(WebHelpers, self).__init__(context, request) for obj in aq_chain(aq_inner(context)): if IClientSector.providedBy(obj): self.sector = obj break self.debug_mode = Globals.DevelopmentMode user = getSecurityManager().getUser() self.anonymous = isAnonymous(user) account = getattr(user, 'account_type', None) self.is_guest_account = account == config.GUEST_ACCOUNT self.guest_session_id = self.is_guest_account and \ SessionManager.session and SessionManager.session.id or None came_from = self.request.form.get("came_from") if came_from: if isinstance(came_from, list): # If came_from is both in the querystring and the form data self.came_from = came_from[0] self.came_from = came_from else: self.came_from = aq_parent(context).absolute_url() self.country_name = '' self.sector_name = '' self.tool_name = '' for obj in aq_chain(aq_inner(self.context)): if ISurvey.providedBy(obj): self.tool_name = obj.Title() if self.anonymous: setattr(self.request, 'survey', obj) if IClientSector.providedBy(obj): self.sector_name = obj.Title() if IClientCountry.providedBy(obj): self.country_name = obj.Title() break
def update_custom_risks_module_texts(context): """ """ if not api.portal.get_registry_record("euphorie.allow_user_defined_risks"): log.warning( "Custom risks are not enabled. Set 'allow_user_defined_risks' to " "true in euphorie.ini for enabling them.") return portal = api.portal.get() client = portal.client count = 0 for country in client.objectValues(): if IClientCountry.providedBy(country): for sector in country.objectValues(): if IClientSector.providedBy(sector): for survey in sector.objectValues(): is_new = EnableCustomRisks(survey) count += 1 custom = getattr(survey, "custom-risks", None) if custom: custom.question = _( "question_other_risks", default= ("<p><strong>Important:</strong> In " "order to avoid duplicating risks, " "we strongly recommend you " "to go first through all the previous modules, " "if you have not done it yet.</p>" "<p>If you don't need to add risks, " "please continue.</p>"), ) if is_new: survey.published = ( survey.id, survey.title, datetime.datetime.now(), )
def show_high_risks(self): for obj in aq_chain(aq_inner(self.context)): if IClientCountry.providedBy(obj): if obj.id in self.COUNTRIES_WITHOUT_HIGH_RISKS: return False return True
def my_context(self): if IClientCountry.providedBy(self.context): return "country" elif ISurvey.providedBy(self.context): return "survey"
def county_obj_via_parents(self): for obj in self.request.PARENTS: if IClientCountry.providedBy(obj): return obj
def country_obj(self): for obj in aq_chain(aq_inner(self.context)): if IClientCountry.providedBy(obj): return obj