Compare commits
2 Commits
aa31aefb42
...
2f17d01780
Author | SHA1 | Date |
---|---|---|
Cayo Puigdefabregas | 2f17d01780 | |
Cayo Puigdefabregas | 2b4b469b0e |
|
@ -84,14 +84,18 @@ class InventaryMixin(DashboardView, TemplateView):
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
limit = self.request.GET.get("limit", 10)
|
limit = self.request.GET.get("limit")
|
||||||
page = self.request.GET.get("page", 1)
|
page = self.request.GET.get("page")
|
||||||
if limit:
|
try:
|
||||||
try:
|
limit = int(limit)
|
||||||
limit = int(limit)
|
page = int(page)
|
||||||
page = int(page)
|
if page < 1:
|
||||||
except:
|
page = 1
|
||||||
raise Http404
|
if limit < 1:
|
||||||
|
limit = 10
|
||||||
|
except:
|
||||||
|
limit = 10
|
||||||
|
page = 1
|
||||||
|
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
devices, count = self.get_devices(self.request.user, offset, limit)
|
devices, count = self.get_devices(self.request.user, offset, limit)
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
{% load i18n %}
|
||||||
|
{% load range %}
|
||||||
|
|
||||||
|
<ul class="pagination">
|
||||||
|
{% if page_number > 1 %}
|
||||||
|
<li class="previous">
|
||||||
|
<a type="button" class="btn btn-grey border border-dark" href="?page=1&limit={{ limit }}">
|
||||||
|
«
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="previous">
|
||||||
|
<a type="button" class="btn btn-grey border border-dark" href="?page={{ page_number|add:-1 }}&limit={{ limit }}">
|
||||||
|
{% trans 'Previous' %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if total_pages > 1 %}
|
||||||
|
|
||||||
|
{% for p in total_pages|range_filter:page_number %}
|
||||||
|
<li {% if p == page_number %}class="active"{% endif %}>
|
||||||
|
<a type="button" class="btn btn-grey{% if p == page_number %}-selected{% endif %}
|
||||||
|
border border-dark"
|
||||||
|
{% if p == page_number or p == "..." %}
|
||||||
|
href="#">
|
||||||
|
{% else %}
|
||||||
|
href="?page={{ p }}&limit={{ limit }}">
|
||||||
|
{% endif %}
|
||||||
|
{{ p }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if page_number < total_pages %}
|
||||||
|
<li class="previous">
|
||||||
|
<a type="button" class="btn btn-grey border border-dark" href="?page={{ page_number|add:+1 }}&limit={{ limit }}">
|
||||||
|
{% trans 'Next' %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="previous">
|
||||||
|
<a type="button" class="btn btn-grey border border-dark" href="?page={{ total_pages }}&limit={{ limit }}">
|
||||||
|
»
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
|
@ -54,12 +54,12 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
<button type="submit" value="{% url 'lot:del_devices' %}" name="url">Remove</button> <button type="submit" name="url" value="{% url 'lot:add_devices' %}">add</button>
|
<button class="btn btn-green-admin" type="submit" value="{% url 'lot:del_devices' %}" name="url">Remove</button> <button class="btn btn-green-admin" type="submit" name="url" value="{% url 'lot:add_devices' %}">add</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{% render_pagination page total_pages %}
|
{% render_pagination page total_pages limit %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django import template
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
@register.inclusion_tag('pagination.html')
|
@register.inclusion_tag('pagination.html')
|
||||||
def render_pagination(page_number, total_pages):
|
def render_pagination(page_number, total_pages, limit=10):
|
||||||
"""
|
"""
|
||||||
Template tag for render pagination
|
Template tag for render pagination
|
||||||
|
|
||||||
|
@ -16,4 +16,5 @@ def render_pagination(page_number, total_pages):
|
||||||
return {
|
return {
|
||||||
'page_number': page_number,
|
'page_number': page_number,
|
||||||
'total_pages': total_pages,
|
'total_pages': total_pages,
|
||||||
|
'limit': limit
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,4 +33,5 @@ class LotDashboardView(InventaryMixin, DetailsMixin):
|
||||||
|
|
||||||
def get_devices(self, user, offset, limit):
|
def get_devices(self, user, offset, limit):
|
||||||
chids = self.object.devicelot_set.all().values_list("device_id", flat=True).distinct()
|
chids = self.object.devicelot_set.all().values_list("device_id", flat=True).distinct()
|
||||||
return [Device(id=x) for x in chids], chids.count()
|
chids_page = chids[offset:offset+limit]
|
||||||
|
return [Device(id=x) for x in chids_page], chids.count()
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
<button type="submit">Save</button>
|
<button class="btn btn-green-admin" type="submit">Save</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue