From 87845eea66a0a8d2bfff09be88ccae47d6a97a1e Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Wed, 22 Jul 2020 04:28:01 +0200 Subject: [PATCH] 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})