From c2c045215024a4cda185e4acfd20629f359e3ca2 Mon Sep 17 00:00:00 2001 From: Cezary Czaplewski Date: Wed, 25 Jul 2018 13:09:26 +0200 Subject: [PATCH] limit for number of saved jobs --- django_simple/todo/templates/index.html | 14 ++++++++++++++ django_simple/todo/views.py | 7 +++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/django_simple/todo/templates/index.html b/django_simple/todo/templates/index.html index 33bbd55..d122d6b 100644 --- a/django_simple/todo/templates/index.html +++ b/django_simple/todo/templates/index.html @@ -16,10 +16,18 @@
{{ variable }}
+
{% if not user|is_lazy_user %} + {% if tasks_count > 123 %} +
  • +
    + Too many jobs saved. Delete some before adding a new job. +
    +
  • + {% else %}
  • {% csrf_token %} @@ -35,8 +43,14 @@
  • + {% endif %} {% endif %}
  • +
    + Total jobs saved {{tasks_count }}. Maximum is 123. +
    +
  • +
  • done
    diff --git a/django_simple/todo/views.py b/django_simple/todo/views.py index cd552cc..1157bfa 100644 --- a/django_simple/todo/views.py +++ b/django_simple/todo/views.py @@ -161,8 +161,9 @@ def index(request): user = request.user tasks = Task.objects.filter(owner=user).order_by('-created_date') variable = '' + tasks_count = Task.objects.filter(owner=user).count() return render(request, "index.html", { - 'tasks': tasks, 'alldone': 0 + 'tasks': tasks, 'alldone': 0, 'tasks_count':tasks_count }) @login_required @@ -991,6 +992,7 @@ def refresh_done1(request, task_id): def refresh_done(request): user = request.user tasks = Task.objects.filter(owner=user).order_by('-created_date') + tasks_count = Task.objects.filter(owner=user).count() alldone = 1 for task in tasks: refresh_done0(task) @@ -1014,7 +1016,8 @@ def refresh_done(request): return render(request, "index.html", { 'tasks': tasks , 'variable' : variable, - 'alldone': alldone + 'alldone': alldone, + 'tasks_count':tasks_count }) -- 1.7.9.5