From 58d1e76a0c9edaed536a3a90108d8d32b146c812 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Sat, 28 Jan 2017 05:05:21 +0100 Subject: [PATCH] Registration includes regtime, opname and location --- TODO | 2 +- contest/forms.py | 12 +++-- contest/migrations/0017_auto_20170127_1833.py | 45 +++++++++++++++++++ contest/models.py | 8 ++++ contest/views.py | 13 ++++++ 5 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 contest/migrations/0017_auto_20170127_1833.py diff --git a/TODO b/TODO index 99b664d..1cce753 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ - calculate "claimed points" - listviews mit pagination evaluieren - - registered datum, name und "genauer standort" für benutzer und shadowbenutzer? (Partially) Done - bootstrap muss gelernt sein (sieht aber noch an vielen stellen crappy aus) @@ -26,6 +25,7 @@ - rearrange login index: contest content rüberziehen; exchange registration nach rechts in der nav - cbr parser zum hochladen - link/funktion um qsos erneut gegeneinander checken zu lassen + - registered datum, name und "genauer standort" für benutzer und shadowbenutzer? Glaube nich, dass ich das mache - call dupe validation könnte ins model wandern diff --git a/contest/forms.py b/contest/forms.py index 76a6132..818a2b2 100644 --- a/contest/forms.py +++ b/contest/forms.py @@ -17,8 +17,12 @@ class CustomUserCreationForm(UserCreationForm): username = forms.CharField(max_length=50, validators=[CallUsernameValidator()]) class UpdateRefForm(forms.Form): - existingRef = forms.ModelChoiceField(label="Existing Reference", queryset=Reference.objects.all(), help_text="If reference already exists, select it here.", required=False) - newRefName = forms.CharField(max_length=50, label="New Reference", help_text="Enter name of new ref, if we should create a new", required=False) + existingRef = forms.ModelChoiceField(label="Existing Exchange", queryset=Reference.objects.all(), help_text="If exchange already exists, select it here.", required=False) + newRefName = forms.CharField(max_length=50, label="New Exchange", help_text="Enter name of new exchange, if we should create a new", required=False) + + location = forms.CharField(max_length=128, label='Exact Location', help_text="E.g. MAR bei den Fahrstuehlen, TEL 15. OG", required=False) + opName = forms.CharField(max_length=128, label='Operators', help_text="Name of operator(s)", required=False) + regTime = forms.DateTimeField(label="Registration time", help_text="Time of Registration") def clean_newRefName(self): data = self.cleaned_data["newRefName"].strip().upper() @@ -34,9 +38,9 @@ class UpdateRefForm(forms.Form): newRefName = cleaned_data.get("newRefName") if existingRef and newRefName: - raise forms.ValidationError("Select an existing ref or create a new one, not both!") + raise forms.ValidationError("Select an existing exchange or create a new one, not both!") if not existingRef and not newRefName: - raise forms.ValidationError("Select either an existing ref or create a new one!") + raise forms.ValidationError("Select either an existing exchange or create a new one!") class UpdateCategoryForm(forms.Form): entry = forms.ModelChoiceField(label="Entry category", queryset=EntryCategory.objects.all()) diff --git a/contest/migrations/0017_auto_20170127_1833.py b/contest/migrations/0017_auto_20170127_1833.py new file mode 100644 index 0000000..2e61cb9 --- /dev/null +++ b/contest/migrations/0017_auto_20170127_1833.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-01-27 18:33 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('contest', '0016_auto_20170127_1154'), + ] + + operations = [ + migrations.AddField( + model_name='shadowcall', + name='location', + field=models.CharField(blank=True, default='', max_length=128), + ), + migrations.AddField( + model_name='shadowcall', + name='opName', + field=models.CharField(blank=True, default='', max_length=128), + ), + migrations.AddField( + model_name='shadowcall', + name='regTime', + field=models.DateTimeField(default=None, null=True), + ), + migrations.AddField( + model_name='user', + name='location', + field=models.CharField(blank=True, default='', max_length=128), + ), + migrations.AddField( + model_name='user', + name='opName', + field=models.CharField(blank=True, default='', max_length=128), + ), + migrations.AddField( + model_name='user', + name='regTime', + field=models.DateTimeField(default=None, null=True), + ), + ] diff --git a/contest/models.py b/contest/models.py index 43690bf..a279d9d 100644 --- a/contest/models.py +++ b/contest/models.py @@ -36,6 +36,10 @@ class ShadowCall(models.Model): username = models.CharField(max_length=20, unique=True, db_index=True, validators=[CallUsernameValidator()]) ref = models.ForeignKey(Reference, models.SET_NULL,null=True, blank=True) + location = models.CharField(max_length=128, default="", blank=True) + opName = models.CharField(max_length=128, default="", blank=True) + regTime = models.DateTimeField(null=True, default=None) + def __str__(self): return self.username @@ -43,6 +47,10 @@ class User(AbstractUser): ref = models.ForeignKey(Reference, models.SET_NULL, null=True, blank=True) cat = models.ForeignKey(EntryCategory, models.SET_NULL, null=True, blank=True) + location = models.CharField(max_length=128, default="", blank=True) + opName = models.CharField(max_length=128, default="", blank=True) + regTime = models.DateTimeField(null=True, default=None) + def __init__(self, *args, **kwargs): super(User, self).__init__(*args, **kwargs) self._meta.get_field("username").validators = [CallUsernameValidator()] diff --git a/contest/views.py b/contest/views.py index 00ea81b..3980b8b 100644 --- a/contest/views.py +++ b/contest/views.py @@ -9,6 +9,8 @@ from django.contrib import messages from django.urls import reverse from django.contrib.auth import login as auth_login from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.utils import timezone + import datetime @@ -184,6 +186,9 @@ def updateRef(request, shadow, uid): messages.info(request, "New Ref '%s' created" % ref) user.ref = ref + user.regTime = form.cleaned_data["regTime"] + user.location = form.cleaned_data["location"] + user.opName = form.cleaned_data["opName"] user.save() messages.success(request, "%s%s ref set to %s" % ("(shadow) " if shadow else "", user, ref)) return HttpResponseRedirect(reverse("contest:registerRefs")) @@ -191,6 +196,14 @@ def updateRef(request, shadow, uid): data = {} if user.ref: data["existingRef"] = user.ref + + if user.regTime: + data["regTime"] = user.regTime + else: + data["regTime"] = timezone.now() + data["opName"] = user.opName + data["location"] = user.location + form = UpdateRefForm(initial=data) return render(request, 'contest/updateRef.html', {'userobj': user, 'form': form, "shadow": shadow})