コード例 #1
0
ファイル: activities.py プロジェクト: CDE-UNIBE/lokp
    def read_many(self, public=False):
        """
        Return many :term:`Activities`.

        .. seealso::
            :ref:`read-many`

        For each :term:`Activity`, only one version is visible, always
        the latest visible version to the current user. This means that
        logged in users can see their own pending versions and
        moderators of the current profile can see pending versions as
        well. If you don't want to show pending versions, consider using
        :class:`lmkp.views.activities.ActivityView.read_many_public`
        instead.

        By default, the :term:`Activities` are ordered with the
        :term:`Activity` having the most recent change being on top.

        Args:
            ``public`` (bool): A boolean indicating whether to return
            only versions visible to the public (eg. pending) or not.

        Matchdict parameters:

            ``/activities/{output}``

            ``output`` (str): If the output format is not valid, a 404
            Response is returned.

            The following output formats are supported:

                ``json``: Return the :term:`Activities` as JSON.

                ``geojson``: Return the :term:`Activities` as GeoJSON.

                ``html``: Return the :term:`Activities` as HTML (eg. the
                `Grid View`)

                ``form``: Returns the form to create a new
                :term:`Activity`.

                ``download``: Returns the page to download
                :term:`Activities`.

        Request parameters:
            ``page`` (int): The page parameter is used to paginate
            :term:`Items`. In combination with ``pagesize`` it defines
            the offset.

            ``pagesize`` (int): The pagesize parameter defines how many
            :term:`Items` are displayed at once. It is used in
            combination with ``page`` to allow pagination.

            ``status`` (str): Use the status parameter to limit results
            to displaying only versions with a certain :term:`status`.

        Returns:
            ``HTTPResponse``. Either a HTML or a JSON response.
        """

        output_format = get_output_format(self.request)

        if output_format == "json":

            items = activity_protocol.read_many(self.request, public=public)

            return render_to_response("json", items, self.request)

        elif output_format == "geojson":

            items = activity_protocol.read_many_geojson(self.request, public=public)

            return render_to_response("json", items, self.request)

        elif output_format == "html":

            page, page_size = get_page_parameters(self.request)
            items = activity_protocol.read_many(
                self.request, public=public, limit=page_size, offset=page_size * page - page_size
            )

            spatial_filter = "profile" if get_bbox_parameters(self.request)[0] == "profile" else "map"
            status_filter = get_status_parameter(self.request)
            __, is_moderator = get_user_privileges(self.request)

            template_values = self.get_base_template_values()
            template_values.update(
                {
                    "data": items["data"] if "data" in items else [],
                    "total": items["total"] if "total" in items else 0,
                    "spatialfilter": spatial_filter,
                    "invfilter": None,
                    "statusfilter": status_filter,
                    "currentpage": page,
                    "pagesize": page_size,
                    "is_moderator": is_moderator,
                    "handle_query_string": handle_query_string,
                }
            )

            return render_to_response(
                get_customized_template_path(self.request, "activities/grid.mak"), template_values, self.request
            )

        elif output_format == "form":

            is_logged_in, __ = get_user_privileges(self.request)
            if not is_logged_in:
                raise HTTPForbidden()

            new_involvement = self.request.params.get("inv", None)
            template_values = renderForm(self.request, "activities", inv=new_involvement)

            if isinstance(template_values, Response):
                return template_values

            template_values.update(self.get_base_template_values())
            template_values.update({"uid": "-", "version": 0})

            return render_to_response(
                get_customized_template_path(self.request, "activities/form.mak"), template_values, self.request
            )

        elif output_format == "download":

            download_view = DownloadView(self.request)

            return download_view.download_customize("activities")

        else:
            raise HTTPNotFound()
コード例 #2
0
ファイル: stakeholders.py プロジェクト: CDE-UNIBE/lokp
    def read_many(self, public=False):
        """
        Return many :term:`Stakeholders`.

        .. seealso::
            :ref:`read-many`

        For each :term:`Stakeholder`, only one version is visible,
        always the latest visible version to the current user. This
        means that logged in users can see their own pending versions
        and moderators of the current profile can see pending versions
        as well. If you don't want to show pending versions, consider
        using
        :class:`lmkp.views.stakeholders.StakeholderView.read_many_public`
        instead.

        By default, the :term:`Stakeholders` are ordered with the
        :term:`Stakeholder` having the most recent change being on top.

        Args:
            ``public`` (bool): A boolean indicating whether to return
            only versions visible to the public (eg. pending) or not.

        Matchdict parameters:

            ``/stakeholders/{output}``

            ``output`` (str): If the output format is not valid, a 404
            Response is returned.

            The following output formats are supported:

                ``json``: Return the :term:`Stakeholders` as JSON.

                ``html``: Return the :term:`Stakeholders` as HTML (eg.
                the `Grid View`)

                ``form``: Returns the form to create a new
                :term:`Stakeholder`.

                ``download``: Returns the page to download
                :term:`Stakeholders`.

        Request parameters:
            ``page`` (int): The page parameter is used to paginate
            :term:`Items`. In combination with ``pagesize`` it defines
            the offset.

            ``pagesize`` (int): The pagesize parameter defines how many
            :term:`Items` are displayed at once. It is used in
            combination with ``page`` to allow pagination.

            ``status`` (str): Use the status parameter to limit results
            to displaying only versions with a certain :term:`status`.

        Returns:
            ``HTTPResponse``. Either a HTML or a JSON response.
        """

        output_format = get_output_format(self.request)

        if output_format == 'json':

            items = stakeholder_protocol.read_many(self.request, public=False)

            return render_to_response('json', items, self.request)

        elif output_format == 'html':

            page, page_size = get_page_parameters(self.request)
            items = stakeholder_protocol.read_many(
                self.request, public=public, limit=page_size,
                offset=page_size * page - page_size)

            spatial_filter = None
            status_filter = get_status_parameter(self.request)
            __, is_moderator = get_user_privileges(self.request)

            template_values = self.get_base_template_values()
            template_values.update({
                'data': items['data'] if 'data' in items else [],
                'total': items['total'] if 'total' in items else 0,
                'spatialfilter': spatial_filter,
                'invfilter': None,
                'statusfilter': status_filter,
                'currentpage': page,
                'pagesize': page_size,
                'is_moderator': is_moderator,
                'handle_query_string': handle_query_string
            })

            return render_to_response(
                get_customized_template_path(
                    self.request, 'stakeholders/grid.mak'),
                template_values, self.request)

        elif output_format == 'form':

            is_logged_in, __ = get_user_privileges(self.request)
            if not is_logged_in:
                raise HTTPForbidden()

            new_involvement = self.request.params.get('inv', None)
            template_values = renderForm(
                self.request, 'stakeholders', inv=new_involvement)

            if isinstance(template_values, Response):
                return template_values

            template_values.update({
                'profile': get_current_profile(self.request),
                'locale': get_current_locale(self.request)
            })

            return render_to_response(
                get_customized_template_path(
                    self.request, 'stakeholders/form.mak'),
                template_values, self.request
            )

        elif output_format == 'download':

            download_view = DownloadView(self.request)

            return download_view.download_customize('stakeholders')

        else:
            raise HTTPNotFound()
コード例 #3
0
ファイル: activities.py プロジェクト: CDE-UNIBE/lokp
    def by_stakeholders(self, public=False):
        """
        Return many :term:`Activities` based on :term:`Stakeholders`.

        Based on the :term:`UIDs` of one or many :term:`Stakeholders`,
        all :term:`Activities` in which the :term:`Stakeholder` is
        involved are returned.

        .. seealso::
            :ref:`read-many`

        For each :term:`Activity`, only one version is visible, always
        the latest visible version to the current user. This means that
        logged in users can see their own pending versions and
        moderators of the current profile can see pending versions as
        well. If you don't want to show pending versions, consider using
        :class:`lmkp.views.activities.ActivityView.by_stakeholder_public`
        instead.

        By default, the :term:`Activities` are ordered with the
        :term:`Activity` having the most recent change being on top.

        Args:
            ``public`` (bool): A boolean indicating whether to return
            only versions visible to the public (eg. pending) or not.

        Matchdict parameters:

            ``/activities/bystakeholders/{output}/{uids}``

            ``output`` (str): If the output format is not valid, a 404
            Response is returned.

            The following output formats are supported:

                ``json``: Return the :term:`Activities` as JSON.

                ``html``: Return the :term:`Activities` as HTML (eg. the
                `Grid View`)

            ``uids`` (str): A comma-separated list of
            :term:`Stakeholder` :term:`UIDs`.

        Request parameters:
            ``page`` (int): The page parameter is used to paginate
            :term:`Items`. In combination with ``pagesize`` it defines
            the offset.

            ``pagesize`` (int): The pagesize parameter defines how many
            :term:`Items` are displayed at once. It is used in
            combination with ``page`` to allow pagination.

            ``status`` (str): Use the status parameter to limit results
            to displaying only versions with a certain :term:`status`.

        Returns:
            ``HTTPResponse``. Either a HTML or a JSON response.
        """
        output_format = get_output_format(self.request)

        uids = self.request.matchdict.get("uids", "").split(",")

        # Remove any invalid UIDs
        for uid in uids:
            if validate_uuid(uid) is not True:
                uids.remove(uid)

        if len(uids) == 0:
            raise HTTPNotFound()

        if output_format == "json":

            items = activity_protocol.read_many_by_stakeholders(self.request, uids=uids, public=public)

            return render_to_response("json", items, self.request)

        elif output_format == "html":

            page, page_size = get_page_parameters(self.request)

            items = activity_protocol.read_many_by_stakeholders(
                self.request, uids=uids, public=public, limit=page_size, offset=page_size * page - page_size
            )

            # No spatial filter is used if the Activities are filtered
            # by a Stakeholder
            spatial_filter = None
            status_filter = None

            template_values = self.get_base_template_values()
            template_values.update(
                {
                    "data": items["data"] if "data" in items else [],
                    "total": items["total"] if "total" in items else 0,
                    "spatialfilter": spatial_filter,
                    "invfilter": uids,
                    "statusfilter": status_filter,
                    "currentpage": page,
                    "pagesize": page_size,
                    "handle_query_string": handle_query_string,
                }
            )

            return render_to_response(
                get_customized_template_path(self.request, "activities/grid.mak"), template_values, self.request
            )

        else:
            raise HTTPNotFound()
コード例 #4
0
ファイル: stakeholders.py プロジェクト: CDE-UNIBE/lokp
    def by_activities(self, public=False):
        """
        Return many :term:`Stakeholders` based on :term:`Activities`.

        Based on the :term:`UIDs` of one or many :term:`Activities`,
        all :term:`Stakeholders` which are involved in the
        :term:`Activity` are returend.

        .. seealso::
            :ref:`read-many`

        For each :term:`Stakeholder`, only one version is visible,
        always the latest visible version to the current user. This
        means that logged in users can see their own pending versions
        and moderators of the current profile can see pending versions
        as well. If you don't want to show pending versions, consider
        using
        :class:`lmkp.views.stakeholders.StakeholderView.by_activities_public`
        instead.

        By default, the :term:`Stakeholders` are ordered with the
        :term:`Stakeholder` having the most recent change being on top.

        Args:
            ``public`` (bool): A boolean indicating whether to return
            only versions visible to the public (eg. pending) or not.

        Matchdict parameters:

            ``/stakeholders/byactivities/{output}`` or
            ``/stakeholders/byactivities/{output}/{uids}``

            ``output`` (str): If the output format is not valid, a 404
            Response is returned.

            The following output formats are supported:

                ``json``: Return the :term:`Stakeholders` as JSON.

                ``html``: Return the :term:`Stakeholders` as HTML (eg.
                the `Grid View`)

            ``uids`` (str): An optional comma-separated list of
            :term:`Activity` :term:`UIDs`.

        Request parameters:
            ``page`` (int): The page parameter is used to paginate
            :term:`Items`. In combination with ``pagesize`` it defines
            the offset.

            ``pagesize`` (int): The pagesize parameter defines how many
            :term:`Items` are displayed at once. It is used in
            combination with ``page`` to allow pagination.

            ``status`` (str): Use the status parameter to limit results
            to displaying only versions with a certain :term:`status`.

        Returns:
            ``HTTPResponse``. Either a HTML or a JSON response.
        """
        output_format = get_output_format(self.request)

        uids = self.request.matchdict.get('uids', '').split(',')

        # Remove any invalid UIDs
        for uid in uids:
            if validate_uuid(uid) is not True:
                uids.remove(uid)

        if output_format == 'json':

            items = stakeholder_protocol.read_many_by_activities(
                self.request, public=public, uids=uids)

            return render_to_response('json', items, self.request)

        elif output_format == 'html':

            page, page_size = get_page_parameters(self.request)

            items = stakeholder_protocol.read_many_by_activities(
                self.request, public=public, uids=uids, limit=page_size,
                offset=page_size * page - page_size)

            # Show a spatial filter only if there is no involvement
            # filter (no Activity UID set)
            spatial_filter = None
            if len(uids) == 0:
                spatial_filter = 'profile' if get_bbox_parameters(
                    self.request)[0] == 'profile' else 'map'
            status_filter = None

            __, is_moderator = get_user_privileges(self.request)

            template_values = self.get_base_template_values()
            template_values.update({
                'data': items['data'] if 'data' in items else [],
                'total': items['total'] if 'total' in items else 0,
                'spatialfilter': spatial_filter,
                'invfilter': uids,
                'statusfilter': status_filter,
                'currentpage': page,
                'pagesize': page_size,
                'is_moderator': is_moderator,
                'handle_query_string': handle_query_string
            })

            return render_to_response(
                get_customized_template_path(
                    self.request, 'stakeholders/grid.mak'),
                template_values, self.request)

        else:
            raise HTTPNotFound()