added Email modell and form

This commit is contained in:
Benni Bärmann 2020-10-27 11:00:58 +01:00
parent b0e268df75
commit 275741ab47
5 changed files with 119 additions and 11 deletions

View File

@ -1,6 +1,7 @@
from django.contrib import admin 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) @admin.register(Project)
class ProjectAdmin(admin.ModelAdmin): class ProjectAdmin(admin.ModelAdmin):
@ -11,4 +12,7 @@ admin.site.register([
Library, Library,
IFG, IFG,
Travel, Travel,
Email,
BusinessCard,
List
]) ])

View File

@ -3,8 +3,9 @@ from django.forms import ModelForm, DateField, ChoiceField, RadioSelect, Boolean
from django.contrib.admin.widgets import AdminDateWidget from django.contrib.admin.widgets import AdminDateWidget
from django.utils.html import format_html from django.utils.html import format_html
from .models import Project, Volunteer, Extern, IFG, Library, TYPE_CHOICES, HonoraryCertificate, Travel from .models import Project, Volunteer, Extern, IFG, Library, TYPE_CHOICES,\
from .settings import DATAPROTECTION, FOERDERRICHTLINIEN HonoraryCertificate, Travel, Email
from .settings import DATAPROTECTION, FOERDERRICHTLINIEN, NUTZUNGSBEDINGUNGEN
class ProjectForm(ModelForm): class ProjectForm(ModelForm):
@ -63,3 +64,13 @@ class HonoraryCertificateForm(ModelForm):
class Meta: class Meta:
model = HonoraryCertificate model = HonoraryCertificate
exclude = ('realname', 'email', 'username', 'granted', 'granted_date', 'survey_mail_send') 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 <a href='{}'>Nutzungsbedingungen</a> zu",
NUTZUNGSBEDINGUNGEN))
class Meta:
model = Email
exclude = ('realname', 'email', 'username', 'granted', 'granted_date', 'survey_mail_send')

View File

@ -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,
},
),
]

View File

@ -116,3 +116,33 @@ class IFG(Grant):
def __str__(self): def __str__(self):
return "IFG-Anfrage von " + self.realname 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

View File

@ -10,7 +10,7 @@ from django.template.loader import get_template
from django.template import Context from django.template import Context
from .forms import ProjectForm, ExternForm, LibraryForm, IFGForm,\ from .forms import ProjectForm, ExternForm, LibraryForm, IFGForm,\
HonoraryCertificateForm, InternForm, TravelForm HonoraryCertificateForm, InternForm, TravelForm, EmailForm
from .models import Project, TYPE_CHOICES, Library from .models import Project, TYPE_CHOICES, Library
from .settings import URLPREFIX, IF_EMAIL from .settings import URLPREFIX, IF_EMAIL
@ -58,17 +58,15 @@ class InternView(CookieWizardView):
if step == '1': if step == '1':
prev_data = self.get_cleaned_data_for_step('0') prev_data = self.get_cleaned_data_for_step('0')
choice = prev_data.get('choice') choice = prev_data.get('choice')
print(f'choice detection: {TYPE_CHOICES[choice]}')
if choice == 'HON': if choice == 'HON':
print ('Ehrenamtsbescheinigung detected!')
form = HonoraryCertificateForm(data) form = HonoraryCertificateForm(data)
elif choice == 'PRO': elif choice == 'PRO':
print ('Projektsteckbrief erreicht!')
form = ProjectForm(data) form = ProjectForm(data)
elif choice == 'TRAV': elif choice == 'TRAV':
print('Reisekosten erreicht')
form = TravelForm(data) form = TravelForm(data)
else: else:
raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice}') raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice} in InternView')
else: else:
form = super().get_form(step, data, files) form = super().get_form(step, data, files)
return form return form
@ -113,15 +111,16 @@ class ExternView(CookieWizardView):
if step == '1': if step == '1':
prev_data = self.get_cleaned_data_for_step('0') prev_data = self.get_cleaned_data_for_step('0')
choice = prev_data.get('choice') choice = prev_data.get('choice')
print(f'choice detection in ExternView: {TYPE_CHOICES[choice]}')
if choice == 'IFG': if choice == 'IFG':
print ('IFG detected!')
form = IFGForm(data) form = IFGForm(data)
elif choice in ('BIB', 'SOFT', 'ELIT'): elif choice in ('BIB', 'SOFT', 'ELIT'):
print ('one of the famous three detected!')
form = LibraryForm(data) form = LibraryForm(data)
form.fields['library'].label = TYPE_CHOICES[choice] form.fields['library'].label = TYPE_CHOICES[choice]
elif choice == 'MAIL':
form = EmailForm(data)
else: else:
raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice}') raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice} in ExternView')
else: else:
form = super().get_form(step, data, files) form = super().get_form(step, data, files)
return form return form