Beispiel #1
0
    def main_view(self, request):
        easy_model = EasyModel(self.site, self.model)
        html_snippets = mark_safe(u'\n'.join([
            p.model_index_html(request, self.model, self.site)
            for p in self.plugins.values()
        ]))
        obj_list = easy_model.objects()
        numitems = request.GET.get('items')
        items_per_page = [25, 50, 100]
        if numitems and numitems.isdigit() and int(numitems) > 0:
            paginator = Paginator(obj_list, numitems)
        else:
            # fall back to default
            paginator = Paginator(obj_list, items_per_page[0])

        page = request.GET.get('page')
        try:
            obj_list_page = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            obj_list_page = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page.
            obj_list_page = paginator.page(paginator.num_pages)
        return render_to_response(
            'databrowse/model_detail.html', {
                'model': easy_model,
                'root_url': self.site.root_url,
                'plugin_html': html_snippets,
                'object_list': obj_list_page,
                'items_per_page': items_per_page,
            })
    def field_view(self, request, field, value=None):
        easy_model = EasyModel(self.site, self.model)
        easy_field = easy_model.field(field.name)
        if value is not None:
            obj_list = easy_model.objects(**{field.name: value})
        else:
            obj_list = \
                [v[field.name] for v in
                 self.model._default_manager.distinct().order_by(field.name).
                 values(field.name)]

        # add paging
        numitems = request.GET.get('items')
        items_per_page = [25, 50, 100]
        if numitems and numitems.isdigit() and int(numitems) > 0:
            paginator = Paginator(obj_list, numitems)
        else:
            # fall back to default
            paginator = Paginator(obj_list, items_per_page[0])

        page = request.GET.get('page')
        try:
            obj_list_page = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            obj_list_page = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page.
            obj_list_page = paginator.page(paginator.num_pages)

        if value is not None:
            return render(
                request,
                'databrowse/fieldchoice_detail.html',
                {
                    'root_url': self.site.root_url,
                    'model': easy_model,
                    'field': easy_field,
                    'value': value,
                    'object_list': obj_list_page,
                    'items_per_page': items_per_page,
                }
            )

        return render(
            request,
            'databrowse/fieldchoice_list.html',
            {
                'root_url': self.site.root_url,
                'model': easy_model,
                'field': easy_field,
                'object_list': obj_list_page,
                'items_per_page': items_per_page,
            }
        )
    def field_view(self, request, field, value=None):
        easy_model = EasyModel(self.site, self.model)
        easy_field = easy_model.field(field.name)
        if value is not None:
            obj_list = easy_model.objects(**{field.name: value})
        else:
            obj_list = [v[field.name] for v in \
            self.model._default_manager.distinct().order_by(field.name).\
            values(field.name)]

        # add paging
        numitems = request.GET.get('items')
        items_per_page = [25,50,100]
        if numitems and numitems.isdigit() and int(numitems)>0:
            paginator = Paginator(obj_list, numitems)
        else:
            # fall back to default
            paginator = Paginator(obj_list, items_per_page[0])
        
        page = request.GET.get('page')
        try:
            obj_list_page = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            obj_list_page = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page.
            obj_list_page = paginator.page(paginator.num_pages)
        
        if value is not None:
            return render_to_response(
                'databrowse/fieldchoice_detail.html',
                {
                    'root_url': self.site.root_url,
                    'model': easy_model,
                    'field': easy_field,
                    'value': value,
                    'object_list': obj_list_page,
                    'items_per_page': items_per_page,
                }
            )

        return render_to_response(
            'databrowse/fieldchoice_list.html',
            {
                'root_url': self.site.root_url,
                'model': easy_model,
                'field': easy_field,
                'object_list': obj_list_page,
                'items_per_page': items_per_page,
            }
        )
    def main_view(self, request):
        easy_model = EasyModel(self.site, self.model)
        html_snippets = mark_safe(
            u'\n'.join([p.model_index_html(
                request,
                self.model,
                self.site
            ) for p in self.plugins.values()])
        )
        obj_list = easy_model.objects()
        numitems = request.GET.get('items')
        items_per_page = [25, 50, 100]
        if numitems and numitems.isdigit() and int(numitems) > 0:
            paginator = Paginator(obj_list, numitems)
        else:
            # fall back to default
            paginator = Paginator(obj_list, items_per_page[0])

        page = request.GET.get('page')
        try:
            obj_list_page = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            obj_list_page = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page.
            obj_list_page = paginator.page(paginator.num_pages)

        return render_to_response(
            'databrowse/model_detail.html',
            {
                'model': easy_model,
                'root_url': self.site.root_url,
                'plugin_html': html_snippets,
                'object_list': obj_list_page,
                'items_per_page': items_per_page,
            }
        )
Beispiel #5
0
 def test_manager(self):
     em = EasyModel(django_databrowse.site, SomeModel)
     self.assertIsInstance(em.objects(), EasyQuerySet)