diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..20fc4fb Binary files /dev/null and b/db.sqlite3 differ diff --git a/waiting_room/tasks.py b/waiting_room/tasks.py index 31411b8..a7ccaa3 100644 --- a/waiting_room/tasks.py +++ b/waiting_room/tasks.py @@ -1,5 +1,6 @@ from huey.contrib.djhuey import task import operator +from django.template.loader import render_to_string from itertools import permutations from collections import Counter from functools import reduce @@ -7,13 +8,16 @@ from math import factorial from channels.layers import get_channel_layer from asgiref.sync import async_to_sync -def render_progress_bar(group_name, message): +def render_progress_bar(group_name, progress, result=None): channel_layer = get_channel_layer() async_to_sync(channel_layer.group_send)( group_name, { 'type': 'channel_message', - 'message': f'
{message}
', + 'message': render_to_string('components/tasks/update.html', { + 'progress': progress, + 'result': result, + }), } ) @@ -64,7 +68,7 @@ def calculate_min_distance(group_name): route_distance += distances[perm[-1]][perm[0]] # Back to the start city shortest_route = min(shortest_route, route_distance) - render_progress_bar(group_name, 100) + render_progress_bar(group_name, 100, shortest_route) return shortest_route return calculate_shortest_route(distances) diff --git a/waiting_room/templates/base.html b/waiting_room/templates/base.html index adf3b37..61d5b04 100644 --- a/waiting_room/templates/base.html +++ b/waiting_room/templates/base.html @@ -6,11 +6,16 @@ {% block title %}Waiting Room{% endblock %} +
- {% include 'progress_bar.html' %} -
{% block content %}{% endblock %}
+ {% include 'components/tasks/layout.html' %} + {% block content %}{% endblock %}
diff --git a/waiting_room/templates/components/tasks/layout.html b/waiting_room/templates/components/tasks/layout.html new file mode 100644 index 0000000..38d56f3 --- /dev/null +++ b/waiting_room/templates/components/tasks/layout.html @@ -0,0 +1,15 @@ +
+ {% include 'components/tasks/update.html' %} +
+ diff --git a/waiting_room/templates/components/tasks/update.html b/waiting_room/templates/components/tasks/update.html new file mode 100644 index 0000000..cbf1b57 --- /dev/null +++ b/waiting_room/templates/components/tasks/update.html @@ -0,0 +1,11 @@ +
+

Task

+ {% if result %} +

Done!

+ Go to result + {% elif progress %} + {{ progress }} + {% else %} +

Nothing

+ {% endif %} +
diff --git a/waiting_room/templates/index.html b/waiting_room/templates/index.html index 7f924d4..6c81b58 100644 --- a/waiting_room/templates/index.html +++ b/waiting_room/templates/index.html @@ -5,13 +5,16 @@ {% block content %}

Index

+
{% if result %}

The result is {{ result }}

diff --git a/waiting_room/templates/progress_bar.html b/waiting_room/templates/progress_bar.html deleted file mode 100644 index 51ee509..0000000 --- a/waiting_room/templates/progress_bar.html +++ /dev/null @@ -1,20 +0,0 @@ -
-
- -
diff --git a/waiting_room/views.py b/waiting_room/views.py index 8f1fe42..c3b6913 100644 --- a/waiting_room/views.py +++ b/waiting_room/views.py @@ -1,8 +1,17 @@ from django.shortcuts import render +import uuid + +def make_user_id(): + return str(uuid.uuid4()).replace('-', '') def index(request): result = request.GET.get('result', None) - return render(request, 'index.html', {'result': result}) + return render(request, 'index.html', { + 'result': result, + 'user_id': make_user_id(), + }) def about_us(request): - return render(request, 'about_us.html') + return render(request, 'about_us.html', { + 'user_id': make_user_id(), + })