Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
def summarizeCountries(container, request, current_country=None, permission=None):
    from euphorie.content.country import ICountry

    result = {}
    for country in container.values():
        if not ICountry.providedBy(country):
            continue

        if permission and not checkPermission(country, permission):
            continue

        country_type = getattr(country, "country_type", "country")
        if country_type != "region":
            country_type = "country"
        countries = result.setdefault(country_type, [])
        countries.append(
            {
                "id": country.id,
                "title": getRegionTitle(request, country.id, country.title),
                "url": country.absolute_url(),
                "current": (current_country == country.id),
            }
        )
    for ct in result.values():
        ct.sort(key=lambda c: c["title"])

    return result
Ejemplo n.º 3
0
    def verify(self, container, context):
        if not checkPermission(container, "Delete objects"):
            raise zExceptions.Unauthorized

        flash = IStatusMessage(self.request).addStatusMessage
        sector = context
        country = container
        client = getPortal(container).client

        if country.id not in client:
            return True

        cl_country = client[country.id]
        if sector.id not in cl_country:
            return True

        # Look for any published surveys in the client sector, and prevent
        # deletion if any are found
        cl_sector = cl_country[sector.id]
        surveys = [s for s in cl_sector.values() if s.id != 'preview']
        if surveys:
            flash(
                _("message_not_delete_published_sector",
                default=u"You can not delete a sector that contains published "
                        u"OiRA Tools."), "error")
            self.request.response.redirect(context.absolute_url())
            return False
        return True
Ejemplo n.º 4
0
    def __call__(self):
        if not checkPermission(self.context,
                               "CMFEditions: Access previous versions"):
            return None

        self.update()
        return self.index()
Ejemplo n.º 5
0
def summarizeCountries(container,
                       request,
                       current_country=None,
                       permission=None):
    from euphorie.content.country import ICountry

    result = {}
    for country in container.values():
        if not ICountry.providedBy(country):
            continue

        if permission and not checkPermission(country, permission):
            continue

        country_type = getattr(country, "country_type", "country")
        if country_type != "region":
            country_type = "country"
        countries = result.setdefault(country_type, [])
        countries.append({
            "id":
            country.id,
            "title":
            getRegionTitle(request, country.id, country.title),
            "url":
            country.absolute_url(),
            "current": (current_country == country.id),
        })
    for ct in result.values():
        ct.sort(key=lambda c: c["title"])

    return result
Ejemplo n.º 6
0
    def verify(self, container, context):
        if not checkPermission(container, "Delete objects"):
            raise zExceptions.Unauthorized

        flash = IStatusMessage(self.request).addStatusMessage
        sector = context
        country = container
        client = getPortal(container).client

        if country.id not in client:
            return True

        cl_country = client[country.id]
        if sector.id not in cl_country:
            return True

        # Look for any published surveys in the client sector, and prevent
        # deletion if any are found
        cl_sector = cl_country[sector.id]
        surveys = [s for s in cl_sector.values() if s.id != 'preview']
        if surveys:
            flash(
                _("message_not_delete_published_sector",
                  default=u"You can not delete a sector that contains published "
                  u"OiRA Tools."), "error")
            self.request.response.redirect(context.absolute_url())
            return False
        return True
Ejemplo n.º 7
0
    def __call__(self):
        if not checkPermission(self.context,
                "CMFEditions: Access previous versions"):
            return None

        self.update()
        return self.index()
Ejemplo n.º 8
0
 def update(self):
     actions = getFactoriesInContext(self.context)
     if IModule.providedBy(self.context):
         for (i, action) in enumerate(actions):
             # To be able to determine what button label to display, we
             # explicitly set the action.id to the fake "euphorie.submodule"
             if action.id == "euphorie.module":
                 actions[i] = FactoryInfo("euphorie.submodule",
                         _(u"Submodule"), *action[2:])
                 break
     self.actions = sorted(actions, key=lambda x: x.title)
     self.can_edit = checkPermission(self.context, "Modify portal content")
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
 def update(self):
     actions = getFactoriesInContext(self.context)
     if IModule.providedBy(self.context):
         for (i, action) in enumerate(actions):
             # To be able to determine what button label to display, we
             # explicitly set the action.id to the fake "euphorie.submodule"
             if action.id == "euphorie.module":
                 actions[i] = FactoryInfo("euphorie.submodule",
                                          _("Submodule"), *action[2:])
                 break
     self.actions = sorted(actions, key=lambda x: x.title)
     self.can_edit = checkPermission(self.context, "Modify portal content")
     self.library_available = IQuestionContainer.providedBy(self.context)
Ejemplo n.º 11
0
    def verify(self, container, context):
        if not checkPermission(container, "Delete objects"):
            raise zExceptions.Unauthorized

        return True
Ejemplo n.º 12
0
    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()
Ejemplo n.º 13
0
    def verify(self, container, context):
        if not checkPermission(container, "Delete objects"):
            raise zExceptions.Unauthorized

        return True
Ejemplo n.º 14
0
    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()
Ejemplo n.º 15
0
 def checkPermission(self, permission):
     return utils.checkPermission(self.context, permission)
Ejemplo n.º 16
0
 def checkPermission(self, permission):
     return utils.checkPermission(self.context, permission)
Ejemplo n.º 17
0
def getSurveys(context):
    """Return a list of all surveys for the current sector.

    The return value is a sorted list of dictionaries describing the
    surveygroups for the sector. Each dictionary has the following
    keys:

    * ``id``: surveygroup id
    * ``title`` surveygroup title
    * ``url``: URL for the surveygroup
    * ``published``: boolean indicating if this surveygroup is published
    * ``surveys``: list of surveys for the surveygroup. Each entry is a
      dictionary with the following keys:

      * ``id``: survey id
      * ``title``: survey title
      * ``url``: URL for the survey
      * ``published``: boolean indicating if this survey is the currently
        published version of the surveygroup
      * ``current``: boolean indicating if the *context* is inside this survey
      * ``versions``: list of published versions

    """
    current_version = None
    for sector in aq_chain(aq_inner(context)):
        if ISurvey.providedBy(sector):
            current_version = aq_base(sector)
        if ISector.providedBy(sector):
            break
    else:
        return []

    result = []
    groups = [group for group in sector.values() if ISurveyGroup.providedBy(group)]
    repository = getToolByName(context, "portal_repository")
    allow_history = checkPermission(context, AccessPreviousVersions)

    def morph(group, survey):
        published = survey.id == group.published
        info = {
            "id": survey.id,
            "title": survey.title,
            "url": survey.absolute_url(),
            "published": published,
            "publication_date": published and survey.published or None,
            "current": aq_base(survey) is current_version,
            "modified": isDirty(survey),
            "versions": [],
        }
        if not allow_history:
            return info

        history = repository.getHistoryMetadata(survey)
        if history:
            for id in range(history.getLength(countPurged=False) - 1, -1, -1):
                meta = history.retrieve(id, countPurged=False)["metadata"][
                    "sys_metadata"
                ]
                info["versions"].append(
                    {
                        "timestamp": datetime.datetime.fromtimestamp(meta["timestamp"]),
                        "history_id": meta["parent"]["history_id"],
                        "version_id": meta["parent"]["version_id"],
                        "location_id": meta["parent"]["location_id"],
                    }
                )
            info["versions"].sort(key=lambda x: x["timestamp"], reverse=True)
        return info

    for group in groups:
        info = {
            "id": group.id,
            "title": group.title,
            "url": group.absolute_url(),
            "published": bool(group.published),
        }
        info["surveys"] = [
            morph(group, survey)
            for survey in group.values()
            if ISurvey.providedBy(survey)
        ]
        info["surveys"].sort(key=lambda s: s["title"].lower())
        result.append(info)
    result.sort(key=lambda g: g["title"].lower())
    return result
Ejemplo n.º 18
0
def getSurveys(context):
    """Return a list of all surveys for the current sector.

    The return value is a sorted list of dictionaries describing the
    surveygroups for the sector. Each dictionary has the following
    keys:

    * ``id``: surveygroup id
    * ``title`` surveygroup title
    * ``url``: URL for the surveygroup
    * ``published``: boolean indicating if this surveygroup is published
    * ``surveys``: list of surveys for the surveygroup. Each entry is a
      dictionary with the following keys:

      * ``id``: survey id
      * ``title``: survey title
      * ``url``: URL for the survey
      * ``published``: boolean indicating if this survey is the currently
        published version of the surveygroup
      * ``current``: boolean indicating if the *context* is inside this survey
      * ``versions``: list of published versions

    """
    current_version = None
    for sector in aq_chain(aq_inner(context)):
        if ISurvey.providedBy(sector):
            current_version = aq_base(sector)
        if ISector.providedBy(sector):
            break
    else:
        return []

    result = []
    groups = [group for group in sector.values()
                if ISurveyGroup.providedBy(group)]
    repository = getToolByName(context, "portal_repository")
    allow_history = checkPermission(context, AccessPreviousVersions)

    def morph(group, survey):
        info = {'id': survey.id,
                'title': survey.title,
                'url': survey.absolute_url(),
                'published': survey.id == group.published,
                'current': aq_base(survey) is current_version,
                'modified': isDirty(survey),
                'versions': []}
        if not allow_history:
            return info

        history = repository.getHistoryMetadata(survey)
        if history:
            for id in range(history.getLength(countPurged=False) - 1, -1, -1):
                meta = history.retrieve(id,
                        countPurged=False)["metadata"]["sys_metadata"]
                info["versions"].append({
                    'timestamp': datetime.datetime.fromtimestamp(
                        meta["timestamp"]),
                    'history_id': meta["parent"]["history_id"],
                    'version_id': meta["parent"]["version_id"],
                    'location_id': meta["parent"]["location_id"]})
            info["versions"].sort(key=lambda x: x["timestamp"], reverse=True)
        return info

    for group in groups:
        info = {'id': group.id,
                'title': group.title,
                'url': group.absolute_url(),
                'published': bool(group.published)}
        info["surveys"] = [morph(group, survey)
                           for survey in group.values()
                           if ISurvey.providedBy(survey)]
        info["surveys"].sort(key=lambda s: s["title"].lower())
        result.append(info)
    result.sort(key=lambda g: g["title"].lower())
    return result