]> Johnzone git - Mannschaftsverwaltung.git/commitdiff
teamlist works master
authorJohn Janus <mail@johnzone.org>
Tue, 4 Dec 2018 23:53:08 +0000 (00:53 +0100)
committerJohn Janus <mail@johnzone.org>
Tue, 4 Dec 2018 23:53:08 +0000 (00:53 +0100)
15 files changed:
Mannschaftsverwaltung/urls.py
mannschaft/migrations/0001_initial.py
mannschaft/migrations/0002_auto_20181204_2246.py [new file with mode: 0644]
mannschaft/migrations/0002_player_user.py [deleted file]
mannschaft/migrations/0003_auto_20181103_0242.py [deleted file]
mannschaft/migrations/0003_remove_player_teams.py [new file with mode: 0644]
mannschaft/migrations/0004_auto_20181103_1501.py [deleted file]
mannschaft/migrations/0005_auto_20181103_1503.py [deleted file]
mannschaft/migrations/0006_auto_20181103_1505.py [deleted file]
mannschaft/models.py
mannschaft/templates/base.html [new file with mode: 0644]
mannschaft/templates/mannschaft/player_overview.html [new file with mode: 0644]
mannschaft/templates/registration/login.html [new file with mode: 0644]
mannschaft/urls.py
mannschaft/views.py

index 1f97b2d8661a27eaad053b22b887fb1268e56720..6a2b8efe60d13ef94a02d63c604b181aa4ac50fd 100644 (file)
@@ -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')),
 ]
index 5e4597946f078ec13f4ee6408ce402c719890b94..bfd1d4342f09a5910632a368d2e9718b16143cc0 100644 (file)
@@ -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 (file)
index 0000000..65c13aa
--- /dev/null
@@ -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 (file)
index 518dada..0000000
+++ /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 (file)
index 95808c6..0000000
+++ /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 (file)
index 0000000..b4eed53
--- /dev/null
@@ -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 (file)
index 5531388..0000000
+++ /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 (file)
index 8b3ca13..0000000
+++ /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 (file)
index 24af96f..0000000
+++ /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'),
-        ),
-    ]
index b66b02e7df9e5409d5da07e5c28a666ec438de74..524b4f1d1f12f5d3ba84afedfeade488723002be 100644 (file)
@@ -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 (file)
index 0000000..5d55e79
--- /dev/null
@@ -0,0 +1,3 @@
+{% block content %}
+<h1>Mannschaftsverwaltung</h1>
+{% endblock %}
diff --git a/mannschaft/templates/mannschaft/player_overview.html b/mannschaft/templates/mannschaft/player_overview.html
new file mode 100644 (file)
index 0000000..0f0781a
--- /dev/null
@@ -0,0 +1,15 @@
+{% if player %}
+    <p>Willkommen {{ player }}</p>
+    {% if teams %}
+        <ul>
+        {% for team in teams %}
+            <li><a href="/mannschaft/teams/{{ team.id }}/">{{ team.name }}</a></li>
+        {% endfor %}
+        </ul>
+    {% else %}
+        <p>Not registered for any team</p>
+    {% endif %}
+{% else %}
+    <p>register as player</p>
+{% endif %}
+
diff --git a/mannschaft/templates/registration/login.html b/mannschaft/templates/registration/login.html
new file mode 100644 (file)
index 0000000..dce5873
--- /dev/null
@@ -0,0 +1,38 @@
+{% extends "base.html" %}
+
+{% block content %}
+
+{% if form.errors %}
+<p>Your username and password didn't match. Please try again.</p>
+{% endif %}
+
+{% if next %}
+    {% if user.is_authenticated %}
+    <p>Your account doesn't have access to this page. To proceed,
+    please login with an account that has access.</p>
+    {% else %}
+    <p>Please login to see this page.</p>
+    {% endif %}
+{% endif %}
+
+<form method="post" action="{% url 'login' %}">
+{% csrf_token %}
+<table>
+<tr>
+    <td>{{ form.username.label_tag }}</td>
+    <td>{{ form.username }}</td>
+</tr>
+<tr>
+    <td>{{ form.password.label_tag }}</td>
+    <td>{{ form.password }}</td>
+</tr>
+</table>
+
+<input type="submit" value="login">
+<input type="hidden" name="next" value="{{ next }}">
+</form>
+
+{# Assumes you setup the password_reset view in your URLconf #}
+<p><a href="{% url 'password_reset' %}">Lost password?</a></p>
+
+{% endblock %}
index 88a9caca8cebb2a058d9dd370373eee8ec7a89cb..747352d891969f3153329541906ad799232162be 100644 (file)
@@ -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/<int:team_id>/', views.team_details, name='team_detail'),
 ]
index 68f28bd0b6a70ebec456d26ddf2615a018b92d35..d34f57dc1ffce0449c9ab632ec8832083ffbf0c6 100644 (file)
@@ -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)