예제 #1
0
    def render(self):
        infos = {"host": env.request.parameters["host"]}

        for info in hookmanager.trigger("HOOK_HOST_INFO", env.request.parameters["host"]):
            infos.update(info)

        return response.PrewikkaDirectResponse(list(self._link_generator(infos)))
예제 #2
0
    def modify(self):
        self._object = user = usergroup.User(env.request.parameters.get("name", env.request.user.name))

        if not env.request.parameters["language"] in localization.getLanguagesIdentifiers():
            raise error.PrewikkaUserError(N_("Invalid Language"), N_("Specified language does not exist"), log_priority=log.WARNING)

        list(hookmanager.trigger("HOOK_USERMANAGEMENT_USER_MODIFY", user))
        if not env.request.parameters["timezone"] in localization.get_timezones():
            raise error.PrewikkaUserError(N_("Invalid Timezone"), N_("Specified timezone does not exist"), log_priority=log.WARNING)

        need_reload = False
        user.begin_properties_change()

        for param, reload in (("fullname", False), ("email", False), ("theme", True), ("language", True), ("timezone", False)):
            if user == env.request.user and reload and env.request.parameters.get(param) != user.get_property(param):
                need_reload = True

            user.set_property(param, env.request.parameters.get(param))

        if user == env.request.user:
            user.set_locale()

        user.commit_properties_change()

        # Make sure nothing is returned (reset the default dataset)
        env.request.dataset = None

        if need_reload:
            return response.PrewikkaDirectResponse({"type": "reload"})

        return response.PrewikkaRedirectResponse(url_for(".display"), 303)
예제 #3
0
파일: filter.py 프로젝트: gustavi/prewikka
    def save(self):
        fname = env.request.parameters.get("filter_name")
        if not fname:
            raise error.PrewikkaUserError(N_("Could not save filter"), N_("No name for this filter was provided"))

        criteria = dict(zip(
            env.request.parameters.getlist("filter_types"),
            (json.loads(c) for c in env.request.parameters.getlist("filter_criteria"))
        ))

        fltr = self._db.get_filter(env.request.user, fname)
        if fltr:
            if env.request.parameters.get("filter_id") != fname:
                raise error.PrewikkaUserError(N_("Could not save filter"), N_("The filter name is already used by another filter"))

            # Do not erase filter components if the dataprovider failed to load
            new_criteria = fltr.criteria
            new_criteria.update(criteria)
            criteria = new_criteria

        criteria = dict((k, v) for k, v in criteria.items() if v is not None)

        description = env.request.parameters.get("filter_description", "")
        self._db.upsert_filter(env.request.user, Filter(fname, description, criteria))

        return response.PrewikkaDirectResponse({"type": "ajax-reload"})
예제 #4
0
파일: main.py 프로젝트: gustavi/prewikka
    def _process_static(self, webreq):
        pathkey = webreq.path_elements[0]

        mapping = env.htdocs_mapping.get(pathkey, None)
        if not mapping:
            return

        path = os.path.abspath(
            os.path.join(mapping, webreq.path[len(pathkey) + 2:]))
        if not path.startswith(mapping):
            return response.PrewikkaDirectResponse(
                code=403, status_text="Request Forbidden")

        # If the path doesn't map to a regular file, let prewikka continue the processing
        if not os.path.isfile(path):
            return

        try:
            return response.PrewikkaFileResponse(path)
        except Exception as e:
            return response.PrewikkaDirectResponse(
                code=404, status_text="File not found")
예제 #5
0
    def enable(self):
        upsrt = []

        for catname, plugin in self._iter_plugin():
            enabled = plugin.plugin_mandatory or plugin.full_module_name in env.request.parameters[
                "enable_plugin"]
            upsrt.append((plugin.full_module_name, int(enabled)))

        if upsrt:
            env.db.upsert("Prewikka_Module_Registry", ["module", "enabled"],
                          upsrt,
                          pkey=["module"])
            env.db.trigger_plugin_change()

        return response.PrewikkaDirectResponse({"type": "reload"})