From 275741ab47aa374b4c2c91de8e691db71acea578 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Tue, 27 Oct 2020 11:00:58 +0100 Subject: [PATCH] added Email modell and form --- input/admin.py | 6 +- input/forms.py | 15 ++++- .../0027_businesscard_email_list.py | 64 +++++++++++++++++++ input/models.py | 30 +++++++++ input/views.py | 15 ++--- 5 files changed, 119 insertions(+), 11 deletions(-) create mode 100644 input/migrations/0027_businesscard_email_list.py diff --git a/input/admin.py b/input/admin.py index 937c427..d37ca7e 100644 --- a/input/admin.py +++ b/input/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin -from .models import Project, HonoraryCertificate, Library, IFG, Travel +from .models import Project, HonoraryCertificate, Library, IFG, Travel,\ + Email, BusinessCard, List @admin.register(Project) class ProjectAdmin(admin.ModelAdmin): @@ -11,4 +12,7 @@ admin.site.register([ Library, IFG, Travel, + Email, + BusinessCard, + List ]) diff --git a/input/forms.py b/input/forms.py index 84fc9d0..72e8791 100644 --- a/input/forms.py +++ b/input/forms.py @@ -3,8 +3,9 @@ from django.forms import ModelForm, DateField, ChoiceField, RadioSelect, Boolean from django.contrib.admin.widgets import AdminDateWidget from django.utils.html import format_html -from .models import Project, Volunteer, Extern, IFG, Library, TYPE_CHOICES, HonoraryCertificate, Travel -from .settings import DATAPROTECTION, FOERDERRICHTLINIEN +from .models import Project, Volunteer, Extern, IFG, Library, TYPE_CHOICES,\ + HonoraryCertificate, Travel, Email +from .settings import DATAPROTECTION, FOERDERRICHTLINIEN, NUTZUNGSBEDINGUNGEN class ProjectForm(ModelForm): @@ -63,3 +64,13 @@ class HonoraryCertificateForm(ModelForm): class Meta: model = HonoraryCertificate exclude = ('realname', 'email', 'username', 'granted', 'granted_date', 'survey_mail_send') + +class EmailForm(ModelForm): + # TODO: add some javascript to show/hide other-field + check = BooleanField(required=True, + label=format_html("Ich stimme den Nutzungsbedingungen zu", + NUTZUNGSBEDINGUNGEN)) + + class Meta: + model = Email + exclude = ('realname', 'email', 'username', 'granted', 'granted_date', 'survey_mail_send') diff --git a/input/migrations/0027_businesscard_email_list.py b/input/migrations/0027_businesscard_email_list.py new file mode 100644 index 0000000..0a20499 --- /dev/null +++ b/input/migrations/0027_businesscard_email_list.py @@ -0,0 +1,64 @@ +# Generated by Django 3.1.1 on 2020-10-27 09:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('input', '0026_auto_20201026_1214'), + ] + + operations = [ + migrations.CreateModel( + name='BusinessCard', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('realname', models.CharField(max_length=200, null=True)), + ('email', models.CharField(max_length=200, null=True)), + ('granted', models.BooleanField(null=True)), + ('granted_date', models.DateField(null=True)), + ('survey_mail_send', models.BooleanField(null=True)), + ('username', models.CharField(max_length=200, null=True)), + ('cost', models.CharField(max_length=10)), + ('notes', models.CharField(max_length=500)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Email', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('realname', models.CharField(max_length=200, null=True)), + ('email', models.CharField(max_length=200, null=True)), + ('granted', models.BooleanField(null=True)), + ('granted_date', models.DateField(null=True)), + ('survey_mail_send', models.BooleanField(null=True)), + ('username', models.CharField(max_length=200, null=True)), + ('domain', models.CharField(choices=[('PEDIA', '@wikipedia.de'), ('BOOKS', '@wikibooks.de'), ('QUOTE', '@wikiquote.de'), ('SOURCE', '@wikisource.de'), ('VERSITY', '@wikiversity.de')], default='PEDIA', max_length=10)), + ('adress', models.CharField(choices=[('REALNAME', 'Vorname.Nachname'), ('USERNAME', 'Username'), ('OTHER', 'Sonstiges:')], default='USERNAME', max_length=50)), + ('other', models.CharField(blank=True, max_length=50, null=True)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='List', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('realname', models.CharField(max_length=200, null=True)), + ('email', models.CharField(max_length=200, null=True)), + ('granted', models.BooleanField(null=True)), + ('granted_date', models.DateField(null=True)), + ('survey_mail_send', models.BooleanField(null=True)), + ('username', models.CharField(max_length=200, null=True)), + ('domain', models.CharField(choices=[('PEDIA', '@wikipedia.de'), ('BOOKS', '@wikibooks.de'), ('QUOTE', '@wikiquote.de'), ('SOURCE', '@wikisource.de'), ('VERSITY', '@wikiversity.de')], default='PEDIA', max_length=10)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/input/models.py b/input/models.py index 9cf0aac..b09d06d 100644 --- a/input/models.py +++ b/input/models.py @@ -116,3 +116,33 @@ class IFG(Grant): def __str__(self): return "IFG-Anfrage von " + self.realname + +DOMAIN_CHOICES = {'PEDIA': '@wikipedia.de', + 'BOOKS': '@wikibooks.de', + 'QUOTE': '@wikiquote.de', + 'SOURCE': '@wikisource.de', + 'VERSITY': '@wikiversity.de',} + +class Domain(Extern): + domain = models.CharField(max_length=10, + choices=DOMAIN_CHOICES.items(), + default='PEDIA') + + class Meta: + abstract = True + +MAIL_CHOICES = {'REALNAME': 'Vorname.Nachname', + 'USERNAME': 'Username', + 'OTHER': 'Sonstiges:'} + +class Email(Domain): + adress = models.CharField(max_length=50, + choices=MAIL_CHOICES.items(), + default='USERNAME') + other = models.CharField(max_length=50,blank=True,null=True) + +class List(Domain): + pass + +class BusinessCard(Grant): + pass diff --git a/input/views.py b/input/views.py index 31ede57..a4f26c4 100644 --- a/input/views.py +++ b/input/views.py @@ -10,7 +10,7 @@ from django.template.loader import get_template from django.template import Context from .forms import ProjectForm, ExternForm, LibraryForm, IFGForm,\ - HonoraryCertificateForm, InternForm, TravelForm + HonoraryCertificateForm, InternForm, TravelForm, EmailForm from .models import Project, TYPE_CHOICES, Library from .settings import URLPREFIX, IF_EMAIL @@ -58,17 +58,15 @@ class InternView(CookieWizardView): if step == '1': prev_data = self.get_cleaned_data_for_step('0') choice = prev_data.get('choice') + print(f'choice detection: {TYPE_CHOICES[choice]}') if choice == 'HON': - print ('Ehrenamtsbescheinigung detected!') form = HonoraryCertificateForm(data) elif choice == 'PRO': - print ('Projektsteckbrief erreicht!') form = ProjectForm(data) elif choice == 'TRAV': - print('Reisekosten erreicht') form = TravelForm(data) else: - raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice}') + raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice} in InternView') else: form = super().get_form(step, data, files) return form @@ -113,15 +111,16 @@ class ExternView(CookieWizardView): if step == '1': prev_data = self.get_cleaned_data_for_step('0') choice = prev_data.get('choice') + print(f'choice detection in ExternView: {TYPE_CHOICES[choice]}') if choice == 'IFG': - print ('IFG detected!') form = IFGForm(data) elif choice in ('BIB', 'SOFT', 'ELIT'): - print ('one of the famous three detected!') form = LibraryForm(data) form.fields['library'].label = TYPE_CHOICES[choice] + elif choice == 'MAIL': + form = EmailForm(data) else: - raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice}') + raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice} in ExternView') else: form = super().get_form(step, data, files) return form