How to use the cartoview.maps.models.Map function in cartoview

To help you get started, we’ve selected a few cartoview examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cartologic / cartoview / cartoview / maps / views.py View on Github external
def wagtail_edit_map(request, map_id):
    map_obj = get_object_or_404(Map, id=map_id)
    print(map_obj.id)
    return render(request, 'viewer/wagail_edit_map.html',
                  context={'mapId': map_obj.id})
github cartologic / cartoview / cartoview / connections / servers / geonode_handler.py View on Github external
def get_maps(self, url, filteredobjects):
        response = requests.get(self.url + "/api/maps")
        if response.status_code == requests.codes['ok']:
            maps = response.json()
            objects = maps.get('objects', [])
            for obj in objects:
                try:
                    if not Map.objects.filter(geonode_id=obj['id']).exists():
                        temp_map = Map(title=obj['title'], geonode_id=obj['id'])
                        temp_map.save()
                        filteredobjects.append(temp_map)
                except BaseException as e:
                    logger.error(str(e))
                    continue
        return filteredobjects
github cartologic / cartoview / cartoview / maps / views.py View on Github external
def map_view(request, map_id):
    map_obj = get_object_or_404(Map, id=map_id)
    return render(request, 'viewer/index.html', context={'mapId': map_obj.id})
github cartologic / cartoview / cartoview / api / views / maps.py View on Github external
from django.core.exceptions import ObjectDoesNotExist
from rest_framework import permissions, viewsets
from rest_framework.decorators import action
from rest_framework.exceptions import NotFound
from rest_framework.response import Response

from ..filters import MapFilter
from ..permissions import IsOwnerOrReadOnly
from ..serializers.layers import LayerSerializer
from ..serializers.maps import MapSerializer

logger = get_logger(__name__)


class MapViewSet(viewsets.ModelViewSet):
    queryset = Map.objects.all().prefetch_related('layers').distinct()
    serializer_class = MapSerializer
    permission_classes = [
        permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]
    filterset_class = MapFilter

    @action(detail=True, methods=['get'], url_name='map_config')
    def map_config(self, request, pk=None):
        try:
            map_obj = Map.objects.get(pk=pk)
        except ObjectDoesNotExist as e:
            raise NotFound(str(e))
        layers = [LayerSerializer(lyr,
                                  context={'request': request}).data
                  for lyr in map_obj.layers.all()]
        render_options = map_obj.render_options
        if 'ordering' in render_options.keys():
github cartologic / cartoview / cartoview / cms / db_models / map_catalog / MapCatalogKeywordIndex.py View on Github external
def get_context(self, request):
        # Filter by keyword
        keyword = request.GET.get('keyword')
        maps = Map.objects.filter(keywords__name=keyword)

        # Update template context
        context = super().get_context(request)
        paginator = Paginator(maps, 6)  # Show 6 resources per page
        page = request.GET.get('page')
        try:
            maps = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            maps = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            maps = paginator.page(paginator.num_pages)
        context['maps'] = maps
        return context
github cartologic / cartoview / cartoview / cms / models / map_catalog / MapCatalogKeywordIndex.py View on Github external
def get_context(self, request):
        # Filter by keyword
        keyword = request.GET.get('keyword')
        maps = Map.objects.filter(keywords__name=keyword)

        # Update template context
        context = super().get_context(request)
        paginator = Paginator(maps, 6)  # Show 6 resources per page
        page = request.GET.get('page')
        try:
            maps = paginator.page(page)
        except PageNotAnInteger:
            maps = paginator.page(1)  # If page is not an integer, deliver first page.
        except EmptyPage:
            maps = paginator.page(
                paginator.num_pages)  # If page is out of range (e.g. 9999), deliver last page of results.
        context['maps'] = maps
        return context
github cartologic / cartoview / cartoview / api / serializers / app_manager.py View on Github external
class Meta:
        model = App
        fields = '__all__'


class BookmarkSerializer(serializers.ModelSerializer):
    owner = serializers.StringRelatedField(many=False)

    class Meta:
        model = Bookmark
        fields = '__all__'


class AppInstanceSerializer(serializers.ModelSerializer):
    map_url = serializers.CharField(read_only=True)
    app_map = serializers.PrimaryKeyRelatedField(queryset=Map.objects.all())
    owner = serializers.StringRelatedField(many=False, read_only=False)
    bookmarks = BookmarkSerializer(many=True)

    def create(self, validated_data):
        user = None
        request = self.context.get("request")
        if request and hasattr(request, "user"):
            user = request.user
        bookmarks_data = validated_data.pop('bookmarks')
        appinstance = AppInstance.objects.create(**validated_data)
        for bookmark_data in bookmarks_data:
            bookmark = Bookmark.objects.create(owner=user, **bookmark_data)
            appinstance.bookmarks.add(bookmark)
        return appinstance

    class Meta:
github cartologic / cartoview / cartoview / connections / servers / geonode_handler.py View on Github external
def get_maps(self, url, filteredobjects):
        response = requests.get(self.url + "/api/maps")
        if response.status_code == requests.codes['ok']:
            maps = response.json()
            objects = maps.get('objects', [])
            for obj in objects:
                try:
                    if not Map.objects.filter(geonode_id=obj['id']).exists():
                        temp_map = Map(title=obj['title'], geonode_id=obj['id'])
                        temp_map.save()
                        filteredobjects.append(temp_map)
                except BaseException as e:
                    logger.error(str(e))
                    continue
        return filteredobjects
github cartologic / cartoview / cartoview / cms / db_models / blocks / Blocks.py View on Github external
def get_context(self, value, parent_context=None):
        context = super().get_context(value, parent_context=parent_context)
        keywords = Map.keywords.all()
        keywords = keywords.annotate(keywords_count=Count(Map.keywords.through.tag_relname()))
        context['keywords'] = keywords
        return context