Ejemplo n.º 1
0
Archivo: views.py Proyecto: eads/panda
def index(request):
    """
    Page shell for the client-side application.

    Bootstraps read-once data onto the page.
    """
    serializer = Serializer()
    cr = CategoryResource()

    categories = list(Category.objects.annotate(dataset_count=Count('datasets')))

    bundles = [cr.build_bundle(obj=c) for c in categories]
    categories_bootstrap = [cr.full_dehydrate(b) for b in bundles]

    uncategorized = Category(
        id=settings.PANDA_UNCATEGORIZED_ID,
        slug=settings.PANDA_UNCATEGORIZED_SLUG,
        name=settings.PANDA_UNCATEGORIZED_NAME)
    uncategorized.__dict__['dataset_count'] = Dataset.objects.filter(categories=None).count() 
    uncategorized_bundle = cr.full_dehydrate(cr.build_bundle(obj=uncategorized))

    categories_bootstrap.append(uncategorized_bundle)

    return render_to_response('index.html', {
        'settings': settings,
        'demo_mode': int(config_value('MISC', 'DEMO_MODE')),
        'bootstrap_data': serializer.to_json({
            'categories': categories_bootstrap
        })
    })
Ejemplo n.º 2
0
    def get_list(self, request, **kwargs):
        """
        Overriden from underlying implementation in order to insert a fake category
        for "Uncategorized" datasets.
        """
        # TODO: Uncached for now. Invalidation that works for everyone may be
        #       impossible.
        objects = self.obj_get_list(request=request, **self.remove_api_resource_names(kwargs))
        sorted_objects = self.apply_sorting(objects, options=request.GET)

        paginator = self._meta.paginator_class(request.GET, sorted_objects, resource_uri=self.get_resource_list_uri(), limit=self._meta.limit)
        to_be_serialized = paginator.page()

        # Dehydrate the bundles in preparation for serialization.
        bundles = [self.build_bundle(obj=obj, request=request) for obj in to_be_serialized['objects']]
        to_be_serialized['objects'] = [self.full_dehydrate(bundle) for bundle in bundles]

        # Insert fake category
        uncategorized = Category(
            id=settings.PANDA_UNCATEGORIZED_ID,
            slug=settings.PANDA_UNCATEGORIZED_SLUG,
            name=settings.PANDA_UNCATEGORIZED_NAME)
        uncategorized.__dict__['dataset_count'] = Dataset.objects.filter(categories=None).count() 
        uncategorized_bundle = self.full_dehydrate(self.build_bundle(obj=uncategorized))

        to_be_serialized['objects'].append(uncategorized_bundle)

        to_be_serialized = self.alter_list_data_to_serialize(request, to_be_serialized)

        return self.create_response(request, to_be_serialized)
Ejemplo n.º 3
0
def index(request):
    """
    Page shell for the client-side application.

    Bootstraps read-once data onto the page.
    """
    serializer = Serializer()
    cr = CategoryResource()

    categories = list(Category.objects.annotate(dataset_count=Count('datasets')))

    bundles = [cr.build_bundle(obj=c) for c in categories]
    categories_bootstrap = [cr.full_dehydrate(b) for b in bundles]

    uncategorized = Category(
        id=settings.PANDA_UNCATEGORIZED_ID,
        slug=settings.PANDA_UNCATEGORIZED_SLUG,
        name=settings.PANDA_UNCATEGORIZED_NAME)
    uncategorized.__dict__['dataset_count'] = Dataset.objects.filter(categories=None).count() 
    uncategorized_bundle = cr.full_dehydrate(cr.build_bundle(obj=uncategorized))

    categories_bootstrap.append(uncategorized_bundle)

    return render_to_response('index.html', {
        'settings': settings,
        'max_upload_size': int(config_value('MISC', 'MAX_UPLOAD_SIZE')),
        'email_enabled': int(config_value('EMAIL', 'EMAIL_ENABLED')),
        'demo_mode_enabled': int(config_value('MISC', 'DEMO_MODE_ENABLED')),
        'bootstrap_data': serializer.to_json({
            'categories': categories_bootstrap
        }),
        'moment_lang_code': settings.MOMENT_LANGUAGE_MAPPING.get(settings.LANGUAGE_CODE, None),
    })
Ejemplo n.º 4
0
def index(request):
    """
    Page shell for the client-side application.

    Bootstraps read-once data onto the page.
    """
    serializer = Serializer()
    cr = CategoryResource()

    categories = list(
        Category.objects.annotate(dataset_count=Count('datasets')))

    bundles = [cr.build_bundle(obj=c) for c in categories]
    categories_bootstrap = [cr.full_dehydrate(b) for b in bundles]

    uncategorized = Category(id=settings.PANDA_UNCATEGORIZED_ID,
                             slug=settings.PANDA_UNCATEGORIZED_SLUG,
                             name=settings.PANDA_UNCATEGORIZED_NAME)
    uncategorized.__dict__['dataset_count'] = Dataset.objects.filter(
        categories=None).count()
    uncategorized_bundle = cr.full_dehydrate(
        cr.build_bundle(obj=uncategorized))

    categories_bootstrap.append(uncategorized_bundle)

    return render_to_response(
        'index.html', {
            'settings':
            settings,
            'warn_upload_size':
            int(config_value('MISC', 'WARN_UPLOAD_SIZE')),
            'max_upload_size':
            int(config_value('MISC', 'MAX_UPLOAD_SIZE')),
            'email_enabled':
            int(config_value('EMAIL', 'EMAIL_ENABLED')),
            'demo_mode_enabled':
            int(config_value('MISC', 'DEMO_MODE_ENABLED')),
            'bootstrap_data':
            serializer.to_json({'categories': categories_bootstrap}),
            'moment_lang_code':
            settings.MOMENT_LANGUAGE_MAPPING.get(settings.LANGUAGE_CODE, None),
        })
Ejemplo n.º 5
0
    def get_list(self, request, **kwargs):
        """
        Overriden from underlying implementation in order to insert a fake category
        for "Uncategorized" datasets.
        """
        # TODO: Uncached for now. Invalidation that works for everyone may be
        #       impossible.
        objects = self.obj_get_list(request=request,
                                    **self.remove_api_resource_names(kwargs))
        sorted_objects = self.apply_sorting(objects, options=request.GET)

        paginator = self._meta.paginator_class(
            request.GET,
            sorted_objects,
            resource_uri=self.get_resource_list_uri(),
            limit=self._meta.limit)
        to_be_serialized = paginator.page()

        # Dehydrate the bundles in preparation for serialization.
        bundles = [
            self.build_bundle(obj=obj, request=request)
            for obj in to_be_serialized['objects']
        ]
        to_be_serialized['objects'] = [
            self.full_dehydrate(bundle) for bundle in bundles
        ]

        # Insert fake category
        uncategorized = Category(id=settings.PANDA_UNCATEGORIZED_ID,
                                 slug=settings.PANDA_UNCATEGORIZED_SLUG,
                                 name=settings.PANDA_UNCATEGORIZED_NAME)
        uncategorized.__dict__['dataset_count'] = Dataset.objects.filter(
            categories=None).count()
        uncategorized_bundle = self.full_dehydrate(
            self.build_bundle(obj=uncategorized))

        to_be_serialized['objects'].append(uncategorized_bundle)

        to_be_serialized = self.alter_list_data_to_serialize(
            request, to_be_serialized)

        return self.create_response(request, to_be_serialized)