Browse Source

Add pagination for dataset

pull/10/head
Hironsan 6 years ago
parent
commit
cc3322fe01
2 changed files with 31 additions and 3 deletions
  1. 24
      app/server/templates/admin/dataset.html
  2. 10
      app/server/views.py

24
app/server/templates/admin/dataset.html

@ -7,7 +7,7 @@
</tr>
</thead>
<tbody>
{% for doc in project.documents.all %}
{% for doc in documents %}
<tr>
<td>{{ doc.text|truncatechars:100 }}</td>
<td>label</td>
@ -15,4 +15,26 @@
{% endfor %}
</tbody>
</table>
{% if is_paginated %}
<ul class="pagination is-centered" role="navigation" aria-label="pagination">
{% if page_obj.has_previous %}
<li><a href="?page={{ page_obj.previous_page_number }}">&laquo;</a></li>
{% else %}
<li class="disabled"><span>&laquo;</span></li>
{% endif %}
{% for i in paginator.page_range %}
{% if page_obj.number == i %}
<li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
{% else %}
<li><a href="?page={{ i }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li><a href="?page={{ page_obj.next_page_number }}">&raquo;</a></li>
{% else %}
<li class="disabled"><span>&raquo;</span></li>
{% endif %}
</ul>
{% endif %}
{% endblock %}

10
app/server/views.py

@ -49,9 +49,15 @@ class ProjectsView(LoginRequiredMixin, ListView):
template_name = 'projects.html'
class DatasetView(LoginRequiredMixin, DetailView):
model = Project
class DatasetView(LoginRequiredMixin, ListView):
template_name = 'admin/dataset.html'
context_object_name = 'documents'
paginate_by = 5
def get_queryset(self):
project_id = self.kwargs['pk']
project = get_object_or_404(Project, pk=project_id)
return project.documents.all()
class DatasetUpload(LoginRequiredMixin, View):

Loading…
Cancel
Save