From: John Janus Date: Tue, 4 Dec 2018 23:53:08 +0000 (+0100) Subject: teamlist works X-Git-Url: https://git.johnzone.org/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=Mannschaftsverwaltung.git teamlist works --- diff --git a/Mannschaftsverwaltung/urls.py b/Mannschaftsverwaltung/urls.py index 1f97b2d..6a2b8ef 100644 --- a/Mannschaftsverwaltung/urls.py +++ b/Mannschaftsverwaltung/urls.py @@ -13,10 +13,11 @@ 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.contrib import admin, auth from django.urls import include, path urlpatterns = [ path('mannschaft/', include('mannschaft.urls')), path('admin/', admin.site.urls), + path('accounts/', include('django.contrib.auth.urls')), ] diff --git a/mannschaft/migrations/0001_initial.py b/mannschaft/migrations/0001_initial.py index 5e45979..bfd1d43 100644 --- a/mannschaft/migrations/0001_initial.py +++ b/mannschaft/migrations/0001_initial.py @@ -1,5 +1,6 @@ -# Generated by Django 2.1.3 on 2018-11-03 01:05 +# Generated by Django 2.1.4 on 2018-12-04 21:30 +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 = [ @@ -18,7 +20,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('begin', models.DateTimeField()), ('end', models.DateTimeField()), - ('optional', models.TextField()), + ('optional', models.TextField(blank=True, null=True)), ], ), migrations.CreateModel( @@ -26,28 +28,26 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=50)), - ('street', models.CharField(max_length=100)), - ('zip', models.IntegerField()), - ('city', models.CharField(max_length=100)), - ('additional', models.CharField(max_length=100)), + ('street', models.CharField(blank=True, max_length=100, null=True)), + ('zip', models.IntegerField(blank=True, null=True)), + ('city', models.CharField(blank=True, max_length=100, null=True)), + ('additional', models.CharField(blank=True, max_length=100, null=True)), ], ), migrations.CreateModel( name='Player', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=50)), - ('firstname', models.CharField(max_length=50)), - ('birthdate', models.DateField()), - ('dsvid', models.IntegerField()), + ('birthdate', models.DateField(blank=True, null=True)), + ('dsvid', models.IntegerField(blank=True, null=True)), ], ), migrations.CreateModel( name='PlayerState', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('state', models.CharField(max_length=1)), - ('reason', models.CharField(max_length=180)), + ('state', models.CharField(choices=[('y', 'Ja'), ('n', 'Nein'), ('p', 'Vielleicht')], max_length=1)), + ('reason', models.CharField(blank=True, max_length=180, null=True)), ], ), migrations.CreateModel( @@ -62,9 +62,10 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=50)), - ('min_age', models.IntegerField(default=0)), - ('max_age', models.IntegerField(default=999)), - ('players', models.ManyToManyField(to='mannschaft.Player')), + ('min_age', models.IntegerField(blank=True, default=0, null=True)), + ('max_age', models.IntegerField(blank=True, default=999, null=True)), + ('players', models.ManyToManyField(blank=True, to='mannschaft.Player')), + ('trainers', models.ManyToManyField(blank=True, related_name='trainers', to='mannschaft.Player')), ], ), migrations.CreateModel( @@ -73,8 +74,8 @@ class Migration(migrations.Migration): ('event_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='mannschaft.Event')), ('home', models.BooleanField()), ('opponent', models.CharField(max_length=50)), - ('score_team', models.IntegerField()), - ('score_opponent', models.IntegerField()), + ('score_team', models.IntegerField(blank=True, null=True)), + ('score_opponent', models.IntegerField(blank=True, null=True)), ], bases=('mannschaft.event',), ), @@ -97,7 +98,7 @@ class Migration(migrations.Migration): ), migrations.AddField( model_name='playerstate', - name='game', + name='event', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Event'), ), migrations.AddField( @@ -105,15 +106,30 @@ class Migration(migrations.Migration): name='player', field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Player'), ), + migrations.AddField( + model_name='player', + name='teams', + field=models.ManyToManyField(blank=True, to='mannschaft.Team'), + ), + migrations.AddField( + model_name='player', + name='user', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), migrations.AddField( model_name='event', name='location', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Location'), + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Location'), + ), + migrations.AddField( + model_name='event', + name='state', + field=models.ManyToManyField(blank=True, related_name='event_player_state', through='mannschaft.PlayerState', to='mannschaft.Player'), ), migrations.AddField( model_name='event', name='tasks', - field=models.ManyToManyField(through='mannschaft.Task', to='mannschaft.Player'), + field=models.ManyToManyField(blank=True, through='mannschaft.Task', to='mannschaft.Player'), ), migrations.AddField( model_name='event', diff --git a/mannschaft/migrations/0002_auto_20181204_2246.py b/mannschaft/migrations/0002_auto_20181204_2246.py new file mode 100644 index 0000000..65c13aa --- /dev/null +++ b/mannschaft/migrations/0002_auto_20181204_2246.py @@ -0,0 +1,36 @@ +# Generated by Django 2.1.4 on 2018-12-04 21:46 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('mannschaft', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Merch', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('item', models.CharField(blank=True, max_length=50, null=True)), + ('costs', models.FloatField()), + ], + ), + migrations.CreateModel( + name='Order', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('quantity', models.IntegerField(default=1)), + ('merch', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Merch')), + ('player', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Player')), + ], + ), + migrations.AddField( + model_name='merch', + name='orders', + field=models.ManyToManyField(blank=True, through='mannschaft.Order', to='mannschaft.Player'), + ), + ] diff --git a/mannschaft/migrations/0002_player_user.py b/mannschaft/migrations/0002_player_user.py deleted file mode 100644 index 518dada..0000000 --- a/mannschaft/migrations/0002_player_user.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 2.1.3 on 2018-11-03 01:17 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('mannschaft', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='player', - name='user', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/mannschaft/migrations/0003_auto_20181103_0242.py b/mannschaft/migrations/0003_auto_20181103_0242.py deleted file mode 100644 index 95808c6..0000000 --- a/mannschaft/migrations/0003_auto_20181103_0242.py +++ /dev/null @@ -1,40 +0,0 @@ -# Generated by Django 2.1.3 on 2018-11-03 01:42 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('mannschaft', '0002_player_user'), - ] - - operations = [ - migrations.RenameField( - model_name='playerstate', - old_name='game', - new_name='event', - ), - migrations.AddField( - model_name='event', - name='state', - field=models.ManyToManyField(related_name='event_player_state', through='mannschaft.PlayerState', to='mannschaft.Player'), - ), - migrations.AddField( - model_name='team', - name='trainers', - field=models.ManyToManyField(related_name='trainers', to='mannschaft.Player'), - ), - migrations.AlterField( - model_name='player', - name='user', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), - ), - migrations.AlterField( - model_name='playerstate', - name='state', - field=models.CharField(choices=[('y', 'Ja'), ('n', 'Nein'), ('p', 'Vielleicht')], max_length=1), - ), - ] diff --git a/mannschaft/migrations/0003_remove_player_teams.py b/mannschaft/migrations/0003_remove_player_teams.py new file mode 100644 index 0000000..b4eed53 --- /dev/null +++ b/mannschaft/migrations/0003_remove_player_teams.py @@ -0,0 +1,17 @@ +# Generated by Django 2.1.4 on 2018-12-04 22:48 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('mannschaft', '0002_auto_20181204_2246'), + ] + + operations = [ + migrations.RemoveField( + model_name='player', + name='teams', + ), + ] diff --git a/mannschaft/migrations/0004_auto_20181103_1501.py b/mannschaft/migrations/0004_auto_20181103_1501.py deleted file mode 100644 index 5531388..0000000 --- a/mannschaft/migrations/0004_auto_20181103_1501.py +++ /dev/null @@ -1,89 +0,0 @@ -# Generated by Django 2.1.3 on 2018-11-03 14:01 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('mannschaft', '0003_auto_20181103_0242'), - ] - - operations = [ - migrations.AlterField( - model_name='event', - name='location', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='mannschaft.Location'), - ), - migrations.AlterField( - model_name='event', - name='optional', - field=models.TextField(blank=True, null=True), - ), - migrations.AlterField( - model_name='event', - name='state', - field=models.ManyToManyField(blank=True, null=True, related_name='event_player_state', through='mannschaft.PlayerState', to='mannschaft.Player'), - ), - migrations.AlterField( - model_name='event', - name='tasks', - field=models.ManyToManyField(blank=True, null=True, through='mannschaft.Task', to='mannschaft.Player'), - ), - migrations.AlterField( - model_name='game', - name='score_opponent', - field=models.IntegerField(blank=True, null=True), - ), - migrations.AlterField( - model_name='game', - name='score_team', - field=models.IntegerField(blank=True, null=True), - ), - migrations.AlterField( - model_name='location', - name='additional', - field=models.CharField(blank=True, max_length=100, null=True), - ), - migrations.AlterField( - model_name='location', - name='city', - field=models.CharField(blank=True, max_length=100, null=True), - ), - migrations.AlterField( - model_name='location', - name='street', - field=models.CharField(blank=True, max_length=100, null=True), - ), - migrations.AlterField( - model_name='location', - name='zip', - field=models.IntegerField(blank=True, null=True), - ), - migrations.AlterField( - model_name='player', - name='birthdate', - field=models.DateField(blank=True, null=True), - ), - migrations.AlterField( - model_name='player', - name='dsvid', - field=models.IntegerField(blank=True, null=True), - ), - migrations.AlterField( - model_name='playerstate', - name='reason', - field=models.CharField(blank=True, max_length=180, null=True), - ), - migrations.AlterField( - model_name='team', - name='max_age', - field=models.IntegerField(blank=True, default=999, null=True), - ), - migrations.AlterField( - model_name='team', - name='min_age', - field=models.IntegerField(blank=True, default=0, null=True), - ), - ] diff --git a/mannschaft/migrations/0005_auto_20181103_1503.py b/mannschaft/migrations/0005_auto_20181103_1503.py deleted file mode 100644 index 8b3ca13..0000000 --- a/mannschaft/migrations/0005_auto_20181103_1503.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 2.1.3 on 2018-11-03 14:03 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('mannschaft', '0004_auto_20181103_1501'), - ] - - operations = [ - migrations.AlterField( - model_name='event', - name='state', - field=models.ManyToManyField(blank=True, related_name='event_player_state', through='mannschaft.PlayerState', to='mannschaft.Player'), - ), - migrations.AlterField( - model_name='event', - name='tasks', - field=models.ManyToManyField(blank=True, through='mannschaft.Task', to='mannschaft.Player'), - ), - ] diff --git a/mannschaft/migrations/0006_auto_20181103_1505.py b/mannschaft/migrations/0006_auto_20181103_1505.py deleted file mode 100644 index 24af96f..0000000 --- a/mannschaft/migrations/0006_auto_20181103_1505.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 2.1.3 on 2018-11-03 14:05 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('mannschaft', '0005_auto_20181103_1503'), - ] - - operations = [ - migrations.AlterField( - model_name='team', - name='players', - field=models.ManyToManyField(blank=True, to='mannschaft.Player'), - ), - migrations.AlterField( - model_name='team', - name='trainers', - field=models.ManyToManyField(blank=True, related_name='trainers', to='mannschaft.Player'), - ), - ] diff --git a/mannschaft/models.py b/mannschaft/models.py index b66b02e..524b4f1 100644 --- a/mannschaft/models.py +++ b/mannschaft/models.py @@ -1,19 +1,31 @@ from django.db import models from django.contrib.auth.models import User +from django.db.models.signals import post_save +from django.dispatch import receiver # Create your models here. class Player(models.Model): - name = models.CharField(max_length=50) - firstname = models.CharField(max_length=50) birthdate = models.DateField(blank=True, null=True) dsvid = models.IntegerField(blank=True, null=True) - user = models.OneToOneField(User, null=True, on_delete=models.SET_NULL) + user = models.OneToOneField(User, on_delete=models.CASCADE) def __str__(self): - return self.name + ', ' + self.firstname - # ForeignKey(User, null=True, on_delete=models.SET_NULL) + if not self.user.first_name and not self.user.last_name: + return self.user.username + return self.user.first_name + ', ' + self.user.last_name + + +@receiver(post_save, sender=User) +def create_player(sender, instance, created, **kwargs): + if created: + Player.objects.create(user=instance) + + +@receiver(post_save, sender=User) +def save_player(sender, instance, **kwargs): + instance.player.save() class Team(models.Model): @@ -86,3 +98,15 @@ class PlayerState(models.Model): event = models.ForeignKey(Event, on_delete=models.CASCADE) state = models.CharField(max_length=1, choices=ANSWERS) reason = models.CharField(max_length=180, blank=True, null=True) + + +class Merch(models.Model): + item = models.CharField(max_length=50, blank=True, null=True) + costs = models.FloatField() + orders = models.ManyToManyField(Player, through='Order', blank=True) + + +class Order(models.Model): + player = models.ForeignKey(Player, on_delete=models.CASCADE) + merch = models.ForeignKey(Merch, on_delete=models.CASCADE) + quantity = models.IntegerField(default=1) diff --git a/mannschaft/templates/base.html b/mannschaft/templates/base.html new file mode 100644 index 0000000..5d55e79 --- /dev/null +++ b/mannschaft/templates/base.html @@ -0,0 +1,3 @@ +{% block content %} +

Mannschaftsverwaltung

+{% endblock %} diff --git a/mannschaft/templates/mannschaft/player_overview.html b/mannschaft/templates/mannschaft/player_overview.html new file mode 100644 index 0000000..0f0781a --- /dev/null +++ b/mannschaft/templates/mannschaft/player_overview.html @@ -0,0 +1,15 @@ +{% if player %} +

Willkommen {{ player }}

+ {% if teams %} + + {% else %} +

Not registered for any team

+ {% endif %} +{% else %} +

register as player

+{% endif %} + diff --git a/mannschaft/templates/registration/login.html b/mannschaft/templates/registration/login.html new file mode 100644 index 0000000..dce5873 --- /dev/null +++ b/mannschaft/templates/registration/login.html @@ -0,0 +1,38 @@ +{% extends "base.html" %} + +{% block content %} + +{% if form.errors %} +

Your username and password didn't match. Please try again.

+{% endif %} + +{% if next %} + {% if user.is_authenticated %} +

Your account doesn't have access to this page. To proceed, + please login with an account that has access.

+ {% else %} +

Please login to see this page.

+ {% endif %} +{% endif %} + +
+{% csrf_token %} + + + + + + + + + +
{{ form.username.label_tag }}{{ form.username }}
{{ form.password.label_tag }}{{ form.password }}
+ + + +
+ +{# Assumes you setup the password_reset view in your URLconf #} +

Lost password?

+ +{% endblock %} diff --git a/mannschaft/urls.py b/mannschaft/urls.py index 88a9cac..747352d 100644 --- a/mannschaft/urls.py +++ b/mannschaft/urls.py @@ -3,5 +3,7 @@ from django.urls import path from . import views urlpatterns = [ - path('', views.index, name='index'), + path('', views.player_overview, name='player_overview'), + path('teams/', views.teams, name='teams'), + path('teams//', views.team_details, name='team_detail'), ] diff --git a/mannschaft/views.py b/mannschaft/views.py index 68f28bd..d34f57d 100644 --- a/mannschaft/views.py +++ b/mannschaft/views.py @@ -1,5 +1,30 @@ from django.shortcuts import render from django.http import HttpResponse +from django.contrib.auth.models import User +from django.contrib.auth.decorators import login_required +from .models import Player, Team -def index(request): - return HttpResponse("Mannschaftsverwaltung") + +@login_required() +def player_overview(request): + # template = loader.get_template('mannschaft/index.html') + # show = "Mannschaftsverwaltung für %s" % request.user + context = {'teams': request.user.player.team_set.all(), + 'player': request.user.player} + #for p in Player: + #if p.user == request.user: + #context['player'] = p + #break + + return render(request, 'mannschaft/player_overview.html', context) + # return HttpResponse(show) + + +@login_required() +def teams(request): + return HttpResponse("Teams Overview") + + +@login_required() +def team_details(request, team_id): + return HttpResponse("Team details for %s" % team_id)