예제 #1
0
    class UserNodes(ListSerializerMixin, NodeList):
        """
        Retrieve list of nodes of the specified user

        Parameters:

         * `search=<word>`: search <word> in name of nodes of specified layer
         * `limit=<n>`: specify number of items per page (defaults to 40)
         * `limit=0`: turns off pagination
        """
        def get_queryset(self):
            try:
                self.user = Profile.objects.get(username=self.kwargs['username'])
            except Profile.DoesNotExist:
                raise Http404(_('User not found'))

            return super(UserNodes, self).get_queryset().filter(user_id=self.user.id)

        def get(self, request, *args, **kwargs):
            """ Retrieve list of nodes of the specified user """
            # ListSerializerMixin.list returns a serializer object
            nodes = self.list(request, *args, **kwargs)

            content = ProfileSerializer(self.user, context=self.get_serializer_context()).data
            content['nodes'] = nodes.data

            return Response(content)

        post = Hider()
예제 #2
0
class LayerNodeListMixin(object):
    layer = None

    def get_layer(self):
        """ retrieve layer from DB """
        if self.layer:
            return
        try:
            self.layer = Layer.objects.get(slug=self.kwargs['slug'])
        except Layer.DoesNotExist:
            raise Http404(_('Layer not found'))

    def get_queryset(self):
        """ extend parent class queryset by filtering nodes of the specified layer """
        self.get_layer()
        return super(LayerNodeListMixin,
                     self).get_queryset().filter(layer_id=self.layer.id)

    def get_nodes(self, request, *args, **kwargs):
        """ this method might be overridden by other modules (eg: nodeshot.interop.sync) """
        # ListSerializerMixin.list returns a serializer object
        return (self.list(request, *args, **kwargs)).data

    def get(self, request, *args, **kwargs):
        """ Retrieve list of nodes of the specified layer """
        self.get_layer()
        # get nodes of layer
        nodes = self.get_nodes(request, *args, **kwargs)
        return Response(nodes)

    post = Hider()
예제 #3
0
class LayerNodesList(ListSerializerMixin, NodeList):
    """
    Retrieve list of nodes of the specified layer

    Parameters:

     * `search=<word>`: search <word> in name of nodes of specified layer
     * `limit=<n>`: specify number of items per page (defaults to 40)
     * `limit=0`: turns off pagination
     * `layerinfo`: true shows layer description and other info, false doesn't (defaults to true)
    """
    layer = None
    layer_info_default = True  # show layer info by default

    def get_layer(self):
        """ retrieve layer from DB """
        if self.layer:
            return
        try:
            self.layer = Layer.objects.get(slug=self.kwargs['slug'])
        except Layer.DoesNotExist:
            raise Http404(_('Layer not found'))

    def get_queryset(self):
        """ extend parent class queryset by filtering nodes of the specified layer """
        self.get_layer()
        return super(LayerNodesList,
                     self).get_queryset().filter(layer_id=self.layer.id)

    def get_nodes(self, request, *args, **kwargs):
        """ this method might be overridden by other modules (eg: nodeshot.interop.sync) """
        # ListSerializerMixin.list returns a serializer object
        return (self.list(request, *args, **kwargs)).data

    def get(self, request, *args, **kwargs):
        """ Retrieve list of nodes of the specified layer """
        self.get_layer()

        # get nodes of layer
        nodes = self.get_nodes(request, *args, **kwargs)

        # determine if layer info should be shown
        layer_info_default = str(self.layer_info_default).lower(
        )  # convert boolean to string ("true" or "false")
        show_layer_info = (self.request.QUERY_PARAMS.get(
            'layerinfo', layer_info_default) == 'true'
                           )  # is the get param true? if not is false

        # if layerinfo GET param is true show info about layer
        if show_layer_info:
            content = LayerNodeListSerializer(
                self.layer, context=self.get_serializer_context()).data
            content['nodes'] = self.get_nodes(request, *args, **kwargs)
        # otherwise just output nodes in GeoJSON format
        else:
            content = nodes

        return Response(content)

    post = Hider()
예제 #4
0
파일: views.py 프로젝트: vipcs2378/nodeshot
class NodeGeoJSONList(NodeList):
    """
    Retrieve list of all published nodes in GeoJSON format.

    Parameters:

     * `search=<word>`: search <word> in name, slug, description and address of nodes
     * `limit=<n>`: specify number of items per page (defaults to 50)
     * `page=<n>`: show page n
    """
    pagination_serializer_class = PaginatedGeojsonNodeListSerializer
    paginate_by_param = 'limit'
    paginate_by = 50
    serializer_class = NodeGeoSerializer
    post = Hider()
예제 #5
0
class NodeGeoJsonList(NodeList):
    """
    Retrieve list of all published nodes in GeoJSON format.

    Parameters:

     * `search=<word>`: search <word> in name, slug, description and address of nodes
     * `layers=<layer1>,<layer2>`: retrieve nodes of specified layers
     * `limit=<n>`: specify number of items per page (show all by default)
     * `page=<n>`: show page n
    """
    pagination_class = GeoJsonPagination
    paginate_by_param = 'limit'
    paginate_by = 0
    serializer_class = NodeGeoJsonSerializer
    post = Hider()
예제 #6
0
    class UserNodes(NodeList):
        """
        Retrieve list of nodes of the specified user

        Parameters:

         * `search=<word>`: search <word> in name of nodes of specified layer
         * `limit=<n>`: specify number of items per page (defaults to 40)
         * `limit=0`: turns off pagination
        """
        def get_queryset(self):
            try:
                self.user = Profile.objects.get(
                    username=self.kwargs['username'])
            except Profile.DoesNotExist:
                raise Http404(_('User not found'))
            return super(UserNodes,
                         self).get_queryset().filter(user_id=self.user.id)

        # remove post method
        post = Hider()