Пример #1
0
def jazzmin_paginator_number(change_list: ChangeList, i: int) -> SafeText:
    """
    Generate an individual page index link in a paginated list.
    """
    html_str = ""
    start = i == 1
    end = i == change_list.paginator.num_pages
    spacer = i in (".", "…")
    current_page = i == change_list.page_num

    if start:
        link = change_list.get_query_string(
            {PAGE_VAR: change_list.page_num -
             1}) if change_list.page_num > 1 else "#"
        html_str += """
        <li class="page-item previous {disabled}">
            <a class="page-link" href="{link}" data-dt-idx="0" tabindex="0">«</a>
        </li>
        """.format(link=link, disabled="disabled" if link == "#" else "")

    if current_page:
        html_str += """
        <li class="page-item active">
            <a class="page-link" href="javascript:void(0);" data-dt-idx="3" tabindex="0">{num}</a>
        </li>
        """.format(num=i)
    elif spacer:
        html_str += """
        <li class="page-item">
            <a class="page-link" href="javascript:void(0);" data-dt-idx="3" tabindex="0">… </a>
        </li>
        """
    else:
        query_string = change_list.get_query_string({PAGE_VAR: i})
        end = "end" if end else ""
        html_str += """
            <li class="page-item">
            <a href="{query_string}" class="page-link {end}" data-dt-idx="3" tabindex="0">{num}</a>
            </li>
        """.format(num=i, query_string=query_string, end=end)

    if end:
        link = change_list.get_query_string(
            {PAGE_VAR: change_list.page_num +
             1}) if change_list.page_num < i else "#"
        html_str += """
        <li class="page-item next {disabled}">
            <a class="page-link" href="{link}" data-dt-idx="7" tabindex="0">»</a>
        </li>
        """.format(link=link, disabled="disabled" if link == "#" else "")

    return format_html(html_str)
Пример #2
0
def jazzmin_paginator_number(cl: ChangeList, i: int) -> SafeText:
    """
    Generate an individual page index link in a paginated list.
    """
    if i == ".":
        html_str = """
            <li class="page-item">
            <a class="page-link" href="javascript:void(0);" data-dt-idx="3" tabindex="0">… </a>
            </li>
        """

    elif i == cl.page_num:
        html_str = """
            <li class="page-item active">
            <a class="page-link" href="javascript:void(0);" data-dt-idx="3" tabindex="0">{num}
            </a>
            </li>
        """.format(num=i + 1)

    else:
        query_string = cl.get_query_string({PAGE_VAR: i})
        end = mark_safe("end" if i == cl.paginator.num_pages - 1 else "")
        html_str = """
            <li class="page-item">
            <a href="{query_string}" class="page-link {end}" data-dt-idx="3" tabindex="0">{num}</a>
            </li>
        """.format(num=i + 1, query_string=query_string, end=end)

    return format_html(html_str)
Пример #3
0
 def choices(self, changelist: ChangeList) -> Generator:
     for lookup, title in self.lookup_choices:
         yield {
             "selected":
             self.value() == lookup,
             "query_string":
             changelist.get_query_string({self.parameter_name: lookup}, []),
             "display":
             title,
         }
Пример #4
0
    def changelist_view(self, request, extra_context=None):
        from django.contrib.admin.views.main import ChangeList, ERROR_FLAG
        try:
            cl = ChangeList(request, self.model, self.list_display,
                            self.list_display_links, self.list_filter,
                            self.date_hierarchy, self.search_fields,
                            self.list_select_related, self.list_per_page,
                            self.list_editable, self)
            cl.formset = None
        except IncorrectLookupParameters:
            if ERROR_FLAG in request.GET.keys():
                return render_to_response(
                    'admin/invalid_setup.html',
                    {'title': ugettext('Database error')})
            return HttpResponseRedirect(request.path + '?' + ERROR_FLAG + '=1')

        class_name = getattr(request, 'CLASS_NAME', None)
        cl.has_filters = True
        class_names = [{
            'name': ugettext('All'),
            'url': cl.get_query_string(remove='class_name')
        }]
        for i in BaseContent.objects.order_by('class_name').values(
                'class_name').distinct():
            class_names.append({
                'name':
                i['class_name'],
                'url':
                cl.get_query_string(new_params={'class_name': i['class_name']})
            })
        if class_name:
            cl.params.update({'class_name': class_name})

        context = {
            'cl': cl,
            'class_names': class_names,
        }
        context.update(extra_context or {})
        return super(PhotoAdmin, self).changelist_view(request, context)
Пример #5
0
 def choices(self, changelist: ChangeList):
     """
     Overridden to prevent the default "All".
     """
     value = self.value() or force_str(self.get_default_value())
     for lookup, title in self.lookup_choices:
         yield {
             'selected':
             value == force_str(lookup),
             'query_string':
             changelist.get_query_string({self.parameter_name: lookup}),
             'display':
             title,
         }
Пример #6
0
    def changelist_view(self, request, extra_context=None):
        from django.contrib.admin.views.main import ChangeList, ERROR_FLAG

        try:
            cl = ChangeList(
                request,
                self.model,
                self.list_display,
                self.list_display_links,
                self.list_filter,
                self.date_hierarchy,
                self.search_fields,
                self.list_select_related,
                self.list_per_page,
                self.list_editable,
                self,
            )
            cl.formset = None
        except IncorrectLookupParameters:
            if ERROR_FLAG in request.GET.keys():
                return render_to_response("admin/invalid_setup.html", {"title": ugettext("Database error")})
            return HttpResponseRedirect(request.path + "?" + ERROR_FLAG + "=1")

        class_name = getattr(request, "CLASS_NAME", None)
        cl.has_filters = True
        class_names = [{"name": ugettext("All"), "url": cl.get_query_string(remove="class_name")}]
        for i in BaseContent.objects.order_by("class_name").values("class_name").distinct():
            class_names.append(
                {"name": i["class_name"], "url": cl.get_query_string(new_params={"class_name": i["class_name"]})}
            )
        if class_name:
            cl.params.update({"class_name": class_name})

        context = {"cl": cl, "class_names": class_names}
        context.update(extra_context or {})
        return super(PhotoAdmin, self).changelist_view(request, context)
Пример #7
0
 def choices(
     self, changelist: ChangeList
 ) -> typing.Iterator[typing.Dict[str, typing.Any]]:
     for lookup, title in self.lookup_choices:
         yield {
             "selected":
             self.value() == lookup,
             "query_string":
             changelist.get_query_string(
                 {
                     self.parameter_name: lookup,
                 },
                 [],
             ),
             "display":
             title,
         }