Skip to content

Commit c15e818

Browse files
committed
Add load more button that loads by weeks
1 parent 19bafd5 commit c15e818

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

fragdenstaat_de/fds_paperless/paperless.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ def get_document_data(paperless_document_id):
3131
return meta_data, file_data
3232

3333

34-
def list_documents():
34+
def list_documents(week=1):
3535
client = get_paperless_client()
36-
last_week = timezone.now() - timedelta(days=7)
36+
older_than = timezone.now() - timedelta(days=7 * week)
37+
younger_than = older_than + timedelta(days=8)
3738
API_URL = (
3839
settings.PAPERLESS_API_URL
39-
+ "/documents/?added__date__gt={}&document_type__isnull=1".format(
40-
last_week.date()
40+
+ "/documents/?added__date__lt={}&added__date__gt={}&document_type__isnull=1".format(
41+
younger_than.date(), older_than.date()
4142
)
4243
)
4344

fragdenstaat_de/fds_paperless/templates/fds_paperless/list_documents.html

+2
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ <h1>{% trans "Choose documents to import" %}</h1>
3939
{% endfor %}
4040
</ul>
4141
</form>
42+
<a href="{% url "paperless_list" %}?week={{ week|add:"1" }}"
43+
class="btn btn-secondary">{% translate "Load week before" %}</a>
4244
{% endblock app_body %}

fragdenstaat_de/fds_paperless/views.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515

1616
@require_crew
1717
def list_view(request):
18-
paperless_docs = list_documents()
18+
try:
19+
week = max(int(request.GET.get("week", 1)), 1)
20+
except ValueError:
21+
week = 1
22+
paperless_docs = list_documents(week=week)
1923
return render(
2024
request,
2125
"fds_paperless/list_documents.html",
2226
{
2327
"documents": paperless_docs,
28+
"week": week,
2429
},
2530
)
2631

0 commit comments

Comments
 (0)