How to use the cartoview.app_manager.models.AppInstance.objects 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 / cartoview_api / rest.py View on Github external
def get_object_list(self, request):
        __inactive_apps = [
            app.id for app in App.objects.all() if not app.config.active]
        __inactive_apps_instances = [instance.id for instance in
                                     AppInstance.objects.filter(
                                         app__id__in=__inactive_apps)]
        active_app_instances = super(ExtendedResourceBaseResource, self) \
            .get_object_list(
            request).exclude(
            id__in=__inactive_apps_instances)

        return active_app_instances
github cartologic / cartoview / cartoview / templatetags / cartoview_tags.py View on Github external
documents = Document.objects.filter(title__icontains=title_filter)

        if settings.RESOURCE_PUBLISHING:
            documents = documents.filter(is_published=True)

        if not settings.SKIP_PERMS_FILTER:
            documents = documents.filter(id__in=authorized)

        counts = documents.values('doc_type').annotate(count=Count('doc_type'))
        facets = dict([(count['doc_type'], count['count'])
                       for count in counts])

        return facets

    elif facet_type == 'appinstances':
        appinstances = AppInstance.objects.filter(
            title__icontains=title_filter)
        if settings.RESOURCE_PUBLISHING:
            appinstances = appinstances.filter(is_published=True)

        if not settings.SKIP_PERMS_FILTER:
            appinstances = appinstances.filter(id__in=authorized)

        counts = appinstances.values('app__title').annotate(
            count=Count('app__name'))
        facets = dict([(count['app__title'], count['count'])
                       for count in counts])
        return facets

    else:

        layers = Layer.objects.filter(title__icontains=title_filter)
github cartologic / cartoview / cartoview / app_manager / rest.py View on Github external
def get_object_list(self, request):
        __inactive_apps = [
            app.id for app in App.objects.all()
            if app.config and not app.config.active
        ]
        __inactive_apps_instances = [
            instance.id for instance in AppInstance.objects.filter(
                app__id__in=__inactive_apps)
        ]
        active_app_instances = super(AppInstanceResource, self) \
            .get_object_list(
            request).exclude(
            id__in=__inactive_apps_instances)

        return active_app_instances
github cartologic / cartoview / cartoview / app_manager / views.py View on Github external
except Http404:
        return render(request, '404.html', context={}, status=404)

    except PermissionDenied:
        return render(request, '401.html', context={
            'error_message':
                _("You are not allowed to view this document.")
        }, status=403)

    if appinstance is None:
        return HttpResponse(
            'An unknown error has occured.', mimetype="text/plain", status=401)

    else:
        if request.user != appinstance.owner and not request.user.is_superuser:
            AppInstance.objects.filter(id=appinstance.id).update(
                popular_count=F('popular_count') + 1)
        set_thumbnail_link = appinstance.link_set.filter(
            link_type='appinstance_thumbnail')
        context_dict = {
            'perms_list':
                get_perms(request.user, appinstance.get_self_resource()),
            'permissions_json':
                _perms_info_json(appinstance),
            'resource':
                appinstance,
            # 'appinstance_links': appinstance_links,
            'set_thumbnail_link':
                set_thumbnail_link
            # 'imgtypes': IMGTYPES,
            # 'related': related
        }
github cartologic / cartoview / cartoview / app_manager / context_processors.py View on Github external
def cartoview_processor(request):
    permitted = get_objects_for_user(request.user,
                                     'base.view_resourcebase')
    cartoview_counters = {
        "apps": App.objects.count(),
        "app_instances": AppInstance.objects.filter(id__in=permitted).count(),
        "maps": Map.objects.filter(id__in=permitted).count(),
        "layers": Layer.objects.filter(id__in=permitted).count(),
        "users": Profile.objects.exclude(username="AnonymousUser").count(),
        "groups": Group.objects.exclude(name="anonymous").count()
    }

    defaults = {
        'apps': App.objects.all().order_by('order'),
        'CARTOVIEW_VERSION': get_version(__version__),
        'APPS_MENU': settings.APPS_MENU,
        'apps_instance_count': AppInstance.objects.all().count(),
        "cartoview_counters": cartoview_counters,
        'instances': AppInstance.objects.all().order_by('app__order')[:5]
    }
    return defaults
github cartologic / cartoview / cartoview / app_manager / views.py View on Github external
def save_instance(self, instance_id, owner, title, config, abstract,
                      map_id):
        if instance_id is None:
            instance_obj = AppInstance()
            instance_obj.app = App.objects.get(name=self.app_name)
            instance_obj.owner = owner
        else:
            instance_obj = AppInstance.objects.get(pk=instance_id)

        instance_obj.title = title
        instance_obj.config = config
        instance_obj.abstract = abstract
        instance_obj.map_id = map_id
        instance_obj.save()
        return instance_obj
github cartologic / cartoview / cartoview / app_manager / context_processors.py View on Github external
cartoview_counters = {
        "apps": App.objects.count(),
        "app_instances": AppInstance.objects.filter(id__in=permitted).count(),
        "maps": Map.objects.filter(id__in=permitted).count(),
        "layers": Layer.objects.filter(id__in=permitted).count(),
        "users": Profile.objects.exclude(username="AnonymousUser").count(),
        "groups": Group.objects.exclude(name="anonymous").count()
    }

    defaults = {
        'apps': App.objects.all().order_by('order'),
        'CARTOVIEW_VERSION': get_version(__version__),
        'APPS_MENU': settings.APPS_MENU,
        'apps_instance_count': AppInstance.objects.all().count(),
        "cartoview_counters": cartoview_counters,
        'instances': AppInstance.objects.all().order_by('app__order')[:5]
    }
    return defaults
github cartologic / cartoview / cartoview / api / serializers / app_manager.py View on Github external
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
github cartologic / cartoview / cartoview / workspace / views.py View on Github external
def workspace(request):
    owner = request.user
    apps = AppInstance.objects.filter(owner=owner)
    created_apps = AppInstance.objects.all()
    layers = Layer.objects.filter(owner=owner)
    maps = Map.objects.filter(owner=owner)
    maps_count = Map.objects.all().count()
    layers_count = Layer.objects.all().count()
    documents = Document.objects.filter(owner=owner)
    documents_count = Document.objects.all().count()
    groups = owner.group_list_all()
    groups_count = GroupProfile.objects.all().count()
    return render(
        request,
        template_name='workspace/workspace.html',
        context={
            'my_apps': apps,
            'my_layers': layers,
            'created_apps': created_apps,
            'my_maps': maps,
github cartologic / cartoview / cartoview / api / views / app_manager.py View on Github external
class AppStoreViewSet(viewsets.ModelViewSet):
    queryset = AppStore.objects.all().distinct()
    serializer_class = AppStoreSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)


class AppTypeViewSet(viewsets.ModelViewSet):
    queryset = AppType.objects.all().distinct()
    serializer_class = AppTypeSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)


class AppInstanceViewSet(viewsets.ModelViewSet):
    queryset = AppInstance.objects.all().prefetch_related("app_map").distinct()
    serializer_class = AppInstanceSerializer
    filterset_class = AppInstanceFilter
    permission_classes = (IsOwnerOrReadOnly,)

    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)


class BookmarkViewSet(viewsets.ModelViewSet):
    queryset = Bookmark.objects.all().distinct()
    serializer_class = BookmarkSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)

    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)