From 7872e4f5b21a31c621320833bbd86caba272bfff Mon Sep 17 00:00:00 2001 From: Midgard Date: Tue, 21 Jul 2020 22:40:51 +0200 Subject: [PATCH 01/11] Add editorconfig --- .editorconfig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..912ad38 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +# https://editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = tab + +[*.py] +indent_style = space +indent_size = 4 + +# 2 spaces in YAML +[*.{yaml,yml}] +indent_style = space +indent_size = 2 From 7b7831d5020250bfec207dec0b92fff5e818dcf4 Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Wed, 22 Jul 2020 04:07:53 +0200 Subject: [PATCH 02/11] remove rabbitmq --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4036681..9d10939 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -amqp==2.6.0 asgiref==3.2.10 billiard==3.6.3.0 celery==4.4.6 From 313366413dbac4bd4a976599c605d04d27ae43ea Mon Sep 17 00:00:00 2001 From: Midgard Date: Wed, 22 Jul 2020 04:08:30 +0200 Subject: [PATCH 03/11] Start events frontend --- events/admin.py | 5 ++++- events/migrations/0001_initial.py | 7 ++++--- events/models.py | 26 +++++++++++++++++++++----- events/templates/events/detail.html | 10 ++++++++++ events/templates/events/index.html | 19 +++++++++++++++++++ events/urls.py | 4 +++- events/views.py | 24 ++++++++++++++++++++---- templates/base.html | 12 ++++++++++++ 8 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 events/templates/events/detail.html create mode 100644 events/templates/events/index.html create mode 100644 templates/base.html diff --git a/events/admin.py b/events/admin.py index 8c38f3f..a1d2300 100644 --- a/events/admin.py +++ b/events/admin.py @@ -1,3 +1,6 @@ from django.contrib import admin -# Register your models here. +from .models import Event, EventRegistration + +admin.site.register(Event) +admin.site.register(EventRegistration) diff --git a/events/migrations/0001_initial.py b/events/migrations/0001_initial.py index f50a5f5..af3db1d 100644 --- a/events/migrations/0001_initial.py +++ b/events/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.8 on 2020-07-21 21:36 +# Generated by Django 3.0.8 on 2020-07-22 01:36 from django.conf import settings from django.db import migrations, models @@ -18,7 +18,8 @@ class Migration(migrations.Migration): name='Event', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('date', models.DateTimeField()), + ('date', models.DateField()), + ('time', models.IntegerField(choices=[(0, 'Voormiddag'), (1, 'Namiddag'), (2, 'Avond')])), ('capacity', models.IntegerField()), ], ), @@ -26,7 +27,7 @@ class Migration(migrations.Migration): name='EventRegistration', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('shirt_size', models.CharField(choices=[('I', 'Interested'), ('A', 'Admitted'), ('D', 'Denied')], max_length=1)), + ('state', models.CharField(choices=[('I', 'Interested'), ('A', 'Admitted'), ('D', 'Denied')], max_length=1)), ('event_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Event')), ('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], diff --git a/events/models.py b/events/models.py index b030d7f..f5c353a 100644 --- a/events/models.py +++ b/events/models.py @@ -4,16 +4,32 @@ from users.models import CustomUser class Event(models.Model): - date = models.DateTimeField() - capacity = models.IntegerField() + MORNING, AFTERNOON, EVENING = range(3) + TIME_SLOTS = { + MORNING: "Voormiddag", + AFTERNOON: "Namiddag", + EVENING: "Avond", + } + date = models.DateField() + time = models.IntegerField(choices=TIME_SLOTS.items(), default=MORNING) + capacity = models.IntegerField(default=6) + + def __str__(self): + return f"{self.date} {self.TIME_SLOTS[self.time]}" class EventRegistration(models.Model): + INTERESTED = "I" + ADMITTED = "A" + DENIED = "D" REGISTRATION_STATE = ( - ('I', 'Interested'), - ('A', 'Admitted'), - ('D', 'Denied'), + (INTERESTED, "Interested"), + (ADMITTED, "Admitted"), + (DENIED, "Denied"), ) event_id = models.ForeignKey(Event, on_delete=models.CASCADE) user_id = models.ForeignKey(CustomUser, on_delete=models.CASCADE) state = models.CharField(max_length=1, choices=REGISTRATION_STATE) + + def __str__(self): + return f"[{self.state}] {self.user.username}" diff --git a/events/templates/events/detail.html b/events/templates/events/detail.html new file mode 100644 index 0000000..1a144a8 --- /dev/null +++ b/events/templates/events/detail.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% block content %} +

{{ event.date }} (maximum {{ event.capacity }} mensen)

+
    + {% for regi in event.registration %} + {{ regi.user.username }}: {{regi.state}} + {% endfor %} +
+{% endblock %} diff --git a/events/templates/events/index.html b/events/templates/events/index.html new file mode 100644 index 0000000..2a03009 --- /dev/null +++ b/events/templates/events/index.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% block content %} +
    + {% for event in events %} +
  • {{ event.date }} {{ event.time }} (maximum {{ event.capacity }} mensen) +
      +
      + {% csrf_token %} + {% for regi in event.registration %} + {{ regi.user.username }}: {{regi.state}} + {% endfor %} +
    • +
      +
    +
  • + {% endfor %} +
+{% endblock %} diff --git a/events/urls.py b/events/urls.py index 88a9cac..030a579 100644 --- a/events/urls.py +++ b/events/urls.py @@ -2,6 +2,8 @@ from django.urls import path from . import views +app_name = "events" urlpatterns = [ - path('', views.index, name='index'), + path("", views.index, name="index"), + path("/", views.register, name="register"), ] diff --git a/events/views.py b/events/views.py index 769a8a0..89da8a9 100644 --- a/events/views.py +++ b/events/views.py @@ -1,8 +1,24 @@ -from django.shortcuts import render +from django.http import HttpResponseRedirect +from django.shortcuts import render, get_object_or_404 +from django.utils import timezone +from django.urls import reverse +import datetime -# Create your views here. -from django.http import HttpResponse +from .models import Event, EventRegistration, CustomUser def index(request): - return HttpResponse("Hello, world. You're at the polls index.") + events = Event.objects.filter(date__gte=timezone.now().date()).order_by("date")[:20] + return render(request, "events/index.html", {"events": events}) + + +def register(request, event_id): + if request.method == "POST": + event = get_object_or_404(Event, id=event_id) + + # registration = Event.entry_set.create( + # state=EventRegistration.INTERESTED, + # event=event, + # user=CustomUser.objects.get(), + # ) + return HttpResponseRedirect(reverse("events:index", args=(event.id,))) diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..1babc4b --- /dev/null +++ b/templates/base.html @@ -0,0 +1,12 @@ + + + + + + Zeus WPI Kelderregistratiesysteemâ„¢ + + +

Zeus WPI Kelderregistratiesysteemâ„¢

+ {% block content %}{% endblock %} + + From 2c869e030ddabbc09337f59c912271eab1ce25e2 Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Wed, 22 Jul 2020 04:10:44 +0200 Subject: [PATCH 04/11] add requests lib --- requirements.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/requirements.txt b/requirements.txt index 9d10939..2ad0293 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,17 @@ asgiref==3.2.10 billiard==3.6.3.0 celery==4.4.6 +certifi==2020.6.20 +chardet==3.0.4 Django==3.0.8 future==0.18.2 +idna==2.10 kombu==4.6.11 mysqlclient==2.0.1 pytz==2020.1 PyYAML==5.3.1 redis==3.5.3 +requests==2.24.0 sqlparse==0.3.1 +urllib3==1.25.9 vine==1.3.0 From 29202a528ae5e9fd8ce7bfb1f7cb7ad5ae93f613 Mon Sep 17 00:00:00 2001 From: Midgard Date: Wed, 22 Jul 2020 04:18:57 +0200 Subject: [PATCH 05/11] I wanted to go party but migrations were fucked --- events/migrations/0001_initial.py | 32 +++++++++++++++++++ events/migrations/0002_auto_20200722_0101.py | 23 ------------- .../migrations/0002_eventregistration_user.py | 23 +++++++++++++ users/migrations/0001_initial.py | 4 +-- users/migrations/0002_auto_20200721_2249.py | 18 ----------- 5 files changed, 57 insertions(+), 43 deletions(-) create mode 100644 events/migrations/0001_initial.py delete mode 100644 events/migrations/0002_auto_20200722_0101.py create mode 100644 events/migrations/0002_eventregistration_user.py delete mode 100644 users/migrations/0002_auto_20200721_2249.py diff --git a/events/migrations/0001_initial.py b/events/migrations/0001_initial.py new file mode 100644 index 0000000..a1a14dd --- /dev/null +++ b/events/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 3.0.8 on 2020-07-22 02:18 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Event', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('date', models.DateField()), + ('time', models.IntegerField(choices=[(0, 'Voormiddag'), (1, 'Namiddag'), (2, 'Avond')], default=0)), + ('capacity', models.IntegerField(default=6)), + ], + ), + migrations.CreateModel( + name='EventRegistration', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('state', models.CharField(choices=[('I', 'Interested'), ('A', 'Admitted'), ('D', 'Denied')], max_length=1)), + ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Event')), + ], + ), + ] diff --git a/events/migrations/0002_auto_20200722_0101.py b/events/migrations/0002_auto_20200722_0101.py deleted file mode 100644 index ab3ddbc..0000000 --- a/events/migrations/0002_auto_20200722_0101.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 3.0.8 on 2020-07-22 01:01 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('events', '0001_initial'), - ] - - operations = [ - migrations.RenameField( - model_name='eventregistration', - old_name='event_id', - new_name='event', - ), - migrations.RenameField( - model_name='eventregistration', - old_name='user_id', - new_name='user', - ), - ] diff --git a/events/migrations/0002_eventregistration_user.py b/events/migrations/0002_eventregistration_user.py new file mode 100644 index 0000000..005ac0a --- /dev/null +++ b/events/migrations/0002_eventregistration_user.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.8 on 2020-07-22 02:18 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('events', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='eventregistration', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/users/migrations/0001_initial.py b/users/migrations/0001_initial.py index b68ad10..a5be237 100644 --- a/users/migrations/0001_initial.py +++ b/users/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.8 on 2020-07-21 22:48 +# Generated by Django 3.0.8 on 2020-07-22 02:18 from django.db import migrations, models import django.utils.timezone @@ -20,7 +20,7 @@ class Migration(migrations.Migration): ('password', models.CharField(max_length=128, verbose_name='password')), ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), - ('zeus_id', models.IntegerField()), + ('zeus_id', models.IntegerField(null=True, unique=True)), ('is_staff', models.BooleanField(default=False)), ('username', models.CharField(max_length=50, unique=True)), ('student_number', models.CharField(max_length=255)), diff --git a/users/migrations/0002_auto_20200721_2249.py b/users/migrations/0002_auto_20200721_2249.py deleted file mode 100644 index 2d53721..0000000 --- a/users/migrations/0002_auto_20200721_2249.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.0.8 on 2020-07-21 22:49 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('users', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='customuser', - name='zeus_id', - field=models.IntegerField(null=True, unique=True), - ), - ] From f20041d04ec8eb48b96e77f12c97c2a3b4a1197f Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Wed, 22 Jul 2020 04:21:29 +0200 Subject: [PATCH 06/11] re-add libs, add profile views --- KeRS/urls.py | 1 + oauth/urls.py | 9 +-------- requirements.txt | 1 + users/templates/profile.html | 10 ++++++++++ users/urls.py | 7 +++++++ users/views.py | 6 ++++++ 6 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 users/templates/profile.html create mode 100644 users/urls.py create mode 100644 users/views.py diff --git a/KeRS/urls.py b/KeRS/urls.py index 06c0f77..5407fb3 100644 --- a/KeRS/urls.py +++ b/KeRS/urls.py @@ -20,4 +20,5 @@ urlpatterns = [ path('', include('events.urls')), path('admin/', admin.site.urls), path('login/zeus/', include('oauth.urls')), + path('user/', include('users.urls')) ] diff --git a/oauth/urls.py b/oauth/urls.py index e36421a..5664e30 100644 --- a/oauth/urls.py +++ b/oauth/urls.py @@ -1,8 +1 @@ -from django.urls import path - -from . import views - -urlpatterns = [ - path('register', views.register), - path('authorized', views.register_callback), -] +git diff --git a/requirements.txt b/requirements.txt index 2ad0293..e5e565f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +amqp==2.6.0 asgiref==3.2.10 billiard==3.6.3.0 celery==4.4.6 diff --git a/users/templates/profile.html b/users/templates/profile.html new file mode 100644 index 0000000..3a9856c --- /dev/null +++ b/users/templates/profile.html @@ -0,0 +1,10 @@ + + + + + Profile + + + + + diff --git a/users/urls.py b/users/urls.py new file mode 100644 index 0000000..88d0fbc --- /dev/null +++ b/users/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('profile', views.profile), +] diff --git a/users/views.py b/users/views.py new file mode 100644 index 0000000..a1b0218 --- /dev/null +++ b/users/views.py @@ -0,0 +1,6 @@ +from django.http import HttpResponse +from django.shortcuts import render + + +def profile(request): + render(request, "profile.html", {"username": request.user.username}) From 1f5b1580ffb1323beb8f208c98162bf1ff665020 Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Wed, 22 Jul 2020 04:22:05 +0200 Subject: [PATCH 07/11] add django beat stuff --- requirements.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/requirements.txt b/requirements.txt index e5e565f..7c1fab0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,14 +5,19 @@ celery==4.4.6 certifi==2020.6.20 chardet==3.0.4 Django==3.0.8 +django-celery-beat==2.0.0 +django-timezone-field==4.0 future==0.18.2 idna==2.10 kombu==4.6.11 mysqlclient==2.0.1 +python-crontab==2.5.1 +python-dateutil==2.8.1 pytz==2020.1 PyYAML==5.3.1 redis==3.5.3 requests==2.24.0 +six==1.15.0 sqlparse==0.3.1 urllib3==1.25.9 vine==1.3.0 From 53a7e23b4f7dde16be6d777d4c62cc583ffb709b Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Wed, 22 Jul 2020 04:22:40 +0200 Subject: [PATCH 08/11] oops --- oauth/urls.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/oauth/urls.py b/oauth/urls.py index 5664e30..e36421a 100644 --- a/oauth/urls.py +++ b/oauth/urls.py @@ -1 +1,8 @@ -git +from django.urls import path + +from . import views + +urlpatterns = [ + path('register', views.register), + path('authorized', views.register_callback), +] From 32b443cc81509c6d0f51ca4de1304cf2634bfeed Mon Sep 17 00:00:00 2001 From: Midgard Date: Wed, 22 Jul 2020 04:24:01 +0200 Subject: [PATCH 09/11] Fix display of time of day --- events/models.py | 11 +++++++++++ events/templates/events/index.html | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/events/models.py b/events/models.py index 92c3b59..6dceccb 100644 --- a/events/models.py +++ b/events/models.py @@ -14,10 +14,16 @@ class Event(models.Model): time = models.IntegerField(choices=TIME_SLOTS.items(), default=MORNING) capacity = models.IntegerField(default=6) + def __str__(self): return f"{self.date} {self.TIME_SLOTS[self.time]}" + @property + def time_str(self): + return self.TIME_SLOTS[self.time] + + class EventRegistration(models.Model): INTERESTED = "I" ADMITTED = "A" @@ -33,3 +39,8 @@ class EventRegistration(models.Model): def __str__(self): return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]" + + + @property + def state_str(self): + return self.TIME_SLOTS[self.time] diff --git a/events/templates/events/index.html b/events/templates/events/index.html index 2a03009..850bc6c 100644 --- a/events/templates/events/index.html +++ b/events/templates/events/index.html @@ -3,12 +3,12 @@ {% block content %}
    {% for event in events %} -
  • {{ event.date }} {{ event.time }} (maximum {{ event.capacity }} mensen) +
  • {{ event.date }} {{ event.time_str }} (maximum {{ event.capacity }} mensen)
      {% csrf_token %} {% for regi in event.registration %} - {{ regi.user.username }}: {{regi.state}} + {{ regi.user.username }}: {{regi.state_str}} {% endfor %}
    • From 5d5dd4febd43d0a1a1fd984d0b258feb7b2083ef Mon Sep 17 00:00:00 2001 From: Midgard Date: Wed, 22 Jul 2020 04:27:18 +0200 Subject: [PATCH 10/11] Fix redirect to index --- events/templates/events/index.html | 2 +- events/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/events/templates/events/index.html b/events/templates/events/index.html index 850bc6c..c20db11 100644 --- a/events/templates/events/index.html +++ b/events/templates/events/index.html @@ -3,7 +3,7 @@ {% block content %}
        {% for event in events %} -
      • {{ event.date }} {{ event.time_str }} (maximum {{ event.capacity }} mensen) +
      • {{ event.date }} {{ event.time_str }} (maximum {{ event.capacity }} mensen)
          {% csrf_token %} diff --git a/events/views.py b/events/views.py index 049f6d9..23cb4e7 100644 --- a/events/views.py +++ b/events/views.py @@ -29,4 +29,4 @@ def register(request, event_id): # event=event, # user=CustomUser.objects.get(), # ) - return HttpResponseRedirect(reverse("events:index", args=(event.id,))) + return HttpResponseRedirect(reverse("events:index") + f"#{event.id}") From 87845eea66a0a8d2bfff09be88ccae47d6a97a1e Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Wed, 22 Jul 2020 04:28:01 +0200 Subject: [PATCH 11/11] Fix migrations or something --- events/migrations/0001_initial.py | 5 +++- .../migrations/0002_eventregistration_user.py | 23 ------------------- oauth/views.py | 2 +- users/migrations/0001_initial.py | 2 +- users/templates/profile.html | 7 +++++- users/views.py | 2 +- 6 files changed, 13 insertions(+), 28 deletions(-) delete mode 100644 events/migrations/0002_eventregistration_user.py diff --git a/events/migrations/0001_initial.py b/events/migrations/0001_initial.py index a1a14dd..7036031 100644 --- a/events/migrations/0001_initial.py +++ b/events/migrations/0001_initial.py @@ -1,5 +1,6 @@ -# Generated by Django 3.0.8 on 2020-07-22 02:18 +# Generated by Django 3.0.8 on 2020-07-22 02:25 +from django.conf import settings from django.db import migrations, models import django.db.models.deletion @@ -9,6 +10,7 @@ class Migration(migrations.Migration): initial = True dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ @@ -27,6 +29,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('state', models.CharField(choices=[('I', 'Interested'), ('A', 'Admitted'), ('D', 'Denied')], max_length=1)), ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Event')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], ), ] diff --git a/events/migrations/0002_eventregistration_user.py b/events/migrations/0002_eventregistration_user.py deleted file mode 100644 index 005ac0a..0000000 --- a/events/migrations/0002_eventregistration_user.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 3.0.8 on 2020-07-22 02:18 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('events', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='eventregistration', - name='user', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/oauth/views.py b/oauth/views.py index b380a03..bea9c68 100644 --- a/oauth/views.py +++ b/oauth/views.py @@ -43,7 +43,7 @@ def register_callback(req: HttpRequest): raise OAuthException(f'username and id are expected values: {user}') else: logger.debug(f'Succesfully authenticated user: {user["username"]} with id: {user["id"]}') - validated_user = validate_user(user['zeus_id'], user['username']) + validated_user = validate_user(user['id'], user['username']) login(req, validated_user) redirect('/') else: diff --git a/users/migrations/0001_initial.py b/users/migrations/0001_initial.py index a5be237..5a2c23c 100644 --- a/users/migrations/0001_initial.py +++ b/users/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.8 on 2020-07-22 02:18 +# Generated by Django 3.0.8 on 2020-07-22 02:25 from django.db import migrations, models import django.utils.timezone diff --git a/users/templates/profile.html b/users/templates/profile.html index 3a9856c..33ca143 100644 --- a/users/templates/profile.html +++ b/users/templates/profile.html @@ -5,6 +5,11 @@ Profile - +{% if user.is_authenticated %} +

          {{ username }}

          +{% else %} +

          Not logged in

          + Login + {% endif %} diff --git a/users/views.py b/users/views.py index a1b0218..693e1d4 100644 --- a/users/views.py +++ b/users/views.py @@ -3,4 +3,4 @@ from django.shortcuts import render def profile(request): - render(request, "profile.html", {"username": request.user.username}) + return render(request, "profile.html", {"username": request.user.username})