Exemplo n.º 1
0
def EnableCustomRisks(survey):
    """In order to allow the user to add custom risks, we create a new special
    module (marked with ICustomRisksModule) in which they may be created.
    """
    appconfig = component.getUtility(IAppConfig)
    if not asBool(appconfig["euphorie"].get("allow_user_defined_risks")):
        return 0
    if "custom-risks" in survey.keys():
        # We don't want to create the custom risks module twice.
        return 0
    args = dict(
        container=survey,
        type="euphorie.module",
        id="custom-risks",
        title=_(u"title_other_risks", default=u"Added risks (by you)"),
        safe_id=False,
        description=_(
            u"description_other_risks", default=u"In case you have identified "
            u"risks not included in the tool, you are able to add them now:"),
        optional=True,
        question=_(
            u"question_other_risks", default=u"<p>Would you now like to add "
            u"your own defined risks to this tool?</p><p><strong>Important:"
            u"</strong> In order to avoid duplicating risks, we strongly "
            u"recommend you to go first through all the previous modules, if "
            u"you have not done it yet.</p><p>If you don't need to add risks, "
            u"please select 'No.'</p>"),
    )
    try:
        module = api.content.create(**args)
    except api.exc.InvalidParameterError:
        args['id'] = "custom-risks-"+str(random.randint(0, 99999999))
        module = api.content.create(**args)
    alsoProvides(module, ICustomRisksModule)
    return args['id']
Exemplo n.º 2
0
def checkTermsAndConditions():
    appconfig = getUtility(IAppConfig)
    try:
        return asBool(appconfig["euphorie"]["terms-and-conditions"])
    except KeyError:
        return True
    except ValueError:
        log.error("Invalid value for terms-and-conditions flag "
                  "in site configuration.")
        return False
Exemplo n.º 3
0
def checkTermsAndConditions():
    appconfig = getUtility(IAppConfig)
    try:
        return asBool(appconfig["euphorie"]["terms-and-conditions"])
    except KeyError:
        return True
    except ValueError:
        log.error("Invalid value for terms-and-conditions flag "
                  "in site configuration.")
        return False
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
def EnableCustomRisks(survey):
    """In order to allow the user to add custom risks, we create a new special
    module (marked with ICustomRisksModule) in which they may be created.
    """
    appconfig = component.getUtility(IAppConfig)
    if not asBool(appconfig["euphorie"].get("allow_user_defined_risks")):
        return 0
    if "custom-risks" in survey.keys():
        # We don't want to create the custom risks module twice.
        return 0
    args = dict(
        container=survey,
        type="euphorie.module",
        id="custom-risks",
        title=_(u"title_other_risks", default=u"Added risks (by you)"),
        safe_id=False,
        description=_(
            u"description_other_risks",
            default=u"In case you have identified "
            u"risks not included in the tool, you are able to add them now:"),
        optional=True,
        question=_(
            u"question_other_risks",
            default=u"<p>Would you now like to add "
            u"your own defined risks to this tool?</p><p><strong>Important:"
            u"</strong> In order to avoid duplicating risks, we strongly "
            u"recommend you to go first through all the previous modules, if "
            u"you have not done it yet.</p><p>If you don't need to add risks, "
            u"please select 'No.'</p>"),
    )
    try:
        module = api.content.create(**args)
    except api.exc.InvalidParameterError:
        args['id'] = "custom-risks-" + str(random.randint(0, 99999999))
        module = api.content.create(**args)
    alsoProvides(module, ICustomRisksModule)
    return args['id']