This commit is contained in:
sahama 2024-08-05 13:30:00 +03:30
parent d62ecb8573
commit 69dd26d412
4 changed files with 20 additions and 5 deletions

View file

@ -27,4 +27,13 @@ def get_proper_elided_page_range(p, number, on_each_side=2, on_ends=2):
@register.filter @register.filter
def get_item(dictionary, key): def get_item(dictionary, key):
return dictionary.get(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>

View file

@ -54,9 +54,13 @@ class ApplicationDetailView(DetailView):
class ApplicationListView(FilterMixin, ListView): class ApplicationListView(FilterMixin, ListView):
model = Application model = Application
template_name = "gooyal_oauth2/application_list.html" template_name = "gooyal_oauth2/application_list.html"
paginate_by = 20 paginate_by = 2
filterset_class = ApplicationFilter filterset_class = ApplicationFilter
def get_ordering(self):
ordering = self.request.GET.get('ordering', 'name')
return ordering
def get_queryset(self): def get_queryset(self):
qs = super().get_queryset() qs = super().get_queryset()
return qs.filter(user=self.request.user) return qs.filter(user=self.request.user)

View file

@ -2,6 +2,8 @@
{% load static %} {% load static %}
{% load jalali_tags %} {% load jalali_tags %}
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% load tags %}
{% block title %}Application: list{% endblock %} {% block title %}Application: list{% endblock %}
{% block page_title %}Application: list{% endblock %} {% block page_title %}Application: list{% endblock %}
@ -21,8 +23,8 @@
{% block content %} {% block content %}
<table class="table"> <table class="table">
<tr> <tr>
<th>name</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>client id</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> <th>actions</th>
</tr> </tr>
{% for obj in object_list %} {% for obj in object_list %}

View file

@ -10,7 +10,7 @@
{% elif i == '…' %} {% elif i == '…' %}
<li class="page-item"><span class="page-link">{{ i }}</span></li> <li class="page-item"><span class="page-link">{{ i }}</span></li>
{% else %} {% 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 %} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}