diff --git a/myproject/urls.py b/myproject/urls.py index c381d70..8e31b53 100644 --- a/myproject/urls.py +++ b/myproject/urls.py @@ -14,9 +14,8 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ -from django.contrib import admin -from django.urls import path +from django.urls import path, include urlpatterns = [ - path('admin/', admin.site.urls), + path('', include('waiting_room.urls')), ] diff --git a/waiting_room/consumers.py b/waiting_room/consumers.py index a847e58..2152192 100644 --- a/waiting_room/consumers.py +++ b/waiting_room/consumers.py @@ -9,15 +9,18 @@ class MyConsumer(WebsocketConsumer): self.room_group_name = self.scope["url_route"]["kwargs"]["room_name"] async_to_sync(self.channel_layer.group_add)(self.room_group_name, self.channel_name) self.accept() - calculate_min_distance(self.room_group_name) def disconnect(self, close_code): async_to_sync(self.channel_layer.group_discard)(self.room_group_name, self.channel_name) self.close() def receive(self, text_data): + json_data = json.loads(text_data) # Echo self.send(text_data=text_data) + # Run task + if json_data['task'] == 'calculate': + calculate_min_distance(self.room_group_name) def channel_message(self, event): message = event['message'] diff --git a/waiting_room/tasks.py b/waiting_room/tasks.py index 078e5a8..31411b8 100644 --- a/waiting_room/tasks.py +++ b/waiting_room/tasks.py @@ -13,7 +13,7 @@ def render_progress_bar(group_name, message): group_name, { 'type': 'channel_message', - 'message': message + 'message': f'
{message}
', } ) diff --git a/waiting_room/templates/about_us.html b/waiting_room/templates/about_us.html new file mode 100644 index 0000000..5147d0b --- /dev/null +++ b/waiting_room/templates/about_us.html @@ -0,0 +1,8 @@ +{% extends 'base.html' %} + +{% block title %}About us{% endblock %} + +{% block content %} +

About us

+ Go to index +{% endblock %} diff --git a/waiting_room/templates/base.html b/waiting_room/templates/base.html new file mode 100644 index 0000000..adf3b37 --- /dev/null +++ b/waiting_room/templates/base.html @@ -0,0 +1,16 @@ + + + + + + {% block title %}Waiting Room{% endblock %} + + + + +
+ {% include 'progress_bar.html' %} +
{% block content %}{% endblock %}
+
+ + diff --git a/waiting_room/templates/index.html b/waiting_room/templates/index.html new file mode 100644 index 0000000..7f924d4 --- /dev/null +++ b/waiting_room/templates/index.html @@ -0,0 +1,21 @@ +{% extends 'base.html' %} + +{% block title %}Run task{% endblock %} + +{% block content %} +

Index

+
+
+ +
+
+
+ {% if result %} +

The result is {{ result }}

+ {% endif %} +
+ Go to about us +{% endblock %} diff --git a/waiting_room/templates/progress_bar.html b/waiting_room/templates/progress_bar.html new file mode 100644 index 0000000..51ee509 --- /dev/null +++ b/waiting_room/templates/progress_bar.html @@ -0,0 +1,20 @@ +
+
+ +
diff --git a/waiting_room/urls.py b/waiting_room/urls.py new file mode 100644 index 0000000..4165d26 --- /dev/null +++ b/waiting_room/urls.py @@ -0,0 +1,9 @@ +from django.urls import path +from . import views + +app_name = 'waiting_room' + +urlpatterns = [ + path('', views.index, name='index'), + path('about_us/', views.about_us, name='about_us'), +] diff --git a/waiting_room/views.py b/waiting_room/views.py index 91ea44a..8f1fe42 100644 --- a/waiting_room/views.py +++ b/waiting_room/views.py @@ -1,3 +1,8 @@ from django.shortcuts import render -# Create your views here. +def index(request): + result = request.GET.get('result', None) + return render(request, 'index.html', {'result': result}) + +def about_us(request): + return render(request, 'about_us.html')