orderby
This commit is contained in:
parent
d62ecb8573
commit
69dd26d412
4 changed files with 20 additions and 5 deletions
|
|
@ -28,3 +28,12 @@ def get_proper_elided_page_range(p, number, on_each_side=2, on_ends=2):
|
|||
@register.filter
|
||||
def get_item(dictionary, key):
|
||||
return dictionary.get(key)
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def get_filter_link(request, key, value):
|
||||
qs: str = request.GET.urlencode()
|
||||
qs_dict = request.GET.dict()
|
||||
qs_dict.update({key: value})
|
||||
return '&'.join(f'{k}={v}' for k, v in qs_dict.items())
|
||||
# return 'page={{ i }}{% for fil, fil_value in filter.data.items %}{% if fil != 'page' %}&{{fil}}={{fil_value}}{% endif %}{% endfor %}">{{ i }}</a></li>
|
||||
|
|
|
|||
|
|
@ -54,9 +54,13 @@ class ApplicationDetailView(DetailView):
|
|||
class ApplicationListView(FilterMixin, ListView):
|
||||
model = Application
|
||||
template_name = "gooyal_oauth2/application_list.html"
|
||||
paginate_by = 20
|
||||
paginate_by = 2
|
||||
filterset_class = ApplicationFilter
|
||||
|
||||
def get_ordering(self):
|
||||
ordering = self.request.GET.get('ordering', 'name')
|
||||
return ordering
|
||||
|
||||
def get_queryset(self):
|
||||
qs = super().get_queryset()
|
||||
return qs.filter(user=self.request.user)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
{% load static %}
|
||||
{% load jalali_tags %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% load tags %}
|
||||
|
||||
|
||||
{% block title %}Application: list{% endblock %}
|
||||
{% block page_title %}Application: list{% endblock %}
|
||||
|
|
@ -21,8 +23,8 @@
|
|||
{% block content %}
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>name</th>
|
||||
<th>client id</th>
|
||||
<th><a href="?{% get_filter_link request 'ordering' 'name' %}" >name{% if request.GET.ordering and 'name' in request.GET.ordering %}<i class="bi bi-arrow-down"></i>{% endif %}</a></th>
|
||||
<th><a href="?{% get_filter_link request 'ordering' 'client_id' %}" >client id{% if request.GET.ordering and 'client_id' in request.GET.ordering %}<i class="bi bi-arrow-down"></i>{% endif %}</a></th>
|
||||
<th>actions</th>
|
||||
</tr>
|
||||
{% for obj in object_list %}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
{% elif i == '…' %}
|
||||
<li class="page-item"><span class="page-link">{{ i }}</span></li>
|
||||
{% else %}
|
||||
<li class="page-item"><a class="page-link" href="?page={{ i }}{% for fil, fil_value in filter.data.items %}{% if fil != 'page' %}&{{fil}}={{fil_value}}{% endif %}{% endfor %}">{{ i }}</a></li>
|
||||
<li class="page-item"><a class="page-link" href="?{% get_filter_link request 'page' i %}">{{ i }}</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue