1
0
Fork 0
foerderbarometer/input/models.py

215 lines
10 KiB
Python

from datetime import date
from django.db import models
from django.utils.html import format_html
from .settings import ACCOUNTS
class Volunteer(models.Model):
realname = models.CharField(max_length=200, null=True, verbose_name="Realname",
help_text="Bitte gib deinen Vornamen und deinen Nachnamen ein.")
email = models.EmailField(max_length=200, null=True, verbose_name='E-Mail-Adresse',
help_text=format_html('Bitte gib deine E-Mail-Adresse ein, damit dich<br>Wikimedia Deutschland bei Rückfragen oder für<br>die Zusage kontaktieren kann.'))
# the following Fields are not supposed to be edited by users
granted = models.BooleanField(null=True)
granted_date = models.DateField(null=True)
survey_mail_send = models.BooleanField(default=False, verbose_name='Keine Umfragemail schicken')
@classmethod
def set_granted(cl, key, b):
obj = cl.objects.get(pk=key)
obj.granted = b
obj.granted_date = date.today()
obj.save()
class Meta:
abstract = True
class Extern(Volunteer):
''' abstract basis class for all data entered by extern volunteers '''
username = models.CharField(max_length=200, null=True, verbose_name='Benutzer_innenname',
help_text=format_html("Bitte gib den Namen ein, mit dem du dich<br>in den Wikimedia-Projekten registriert hast."))
# the following Fields are not supposed to be edited by users
service_id = models.CharField(max_length=15, null=True, blank=True)
def save(self,*args,**kwargs):
# is there a way to call super().save() only once?
super().save(*args,*kwargs)
self.service_id = type(self).__name__ + str(self.pk)
super().save(*args,*kwargs)
class Meta:
abstract = True
class Project(Volunteer):
name = models.CharField(max_length=200, verbose_name='Name des Projekts')
description = models.CharField(max_length=500, verbose_name="Kurzbeschreibung", null=True)
start = models.DateField('Startdatum', null=True, blank= True)
end = models.DateField('Erwartetes Projektende', null=True)
otrs = models.CharField(max_length=300, null=True, verbose_name='OTRS-Link')
plan = models.CharField(max_length=2000, null=True, blank=True, verbose_name="Link zum Förderplan")
page = models.CharField(max_length=2000, null=True, blank=True, verbose_name="Link zur Projektseite")
urls = models.CharField(max_length=2000, null=True, blank=True, verbose_name="Weitere Links")
group = models.CharField(max_length=2000, null=True, blank=True, verbose_name="Mitorganisierende")
location = models.CharField(max_length=2000, null=True, blank=True, verbose_name="Ort/Adresse/Location")
participants_estimated = models.IntegerField(blank=True, null=True, verbose_name='Teilnehmende angefragt')
participants_real = models.IntegerField(blank=True, null=True, verbose_name='Teilnehmende ausgezählt')
insurance = models.BooleanField(default=False, verbose_name='Haftpflichtversicherung')
insurance_technic = models.BooleanField(default=False, verbose_name='Technikversicherung Ausland')
support = models.CharField(max_length=300, blank=True, null=True, verbose_name='Betreuungsperson und Vertretung')
cost = models.IntegerField(blank=True, null=True)
account = models.CharField('Kostenstelle', max_length=5,
choices=ACCOUNTS.items(), null=True,)
granted_from = models.CharField(max_length=100,null=True,verbose_name='Bewilligt von')
notes = models.CharField(max_length=1000,null=True,blank=True,verbose_name='Anmerkungen')
# the following Fields are not supposed to be edited by users
pid = models.CharField(max_length=15, null=True, blank=True)
end_mail_send = models.BooleanField(null=True)
status = models.CharField(max_length=3,choices=(('RUN', 'läuft'),('END','beendet')),default='RUN')
persons = models.IntegerField(default=1)
def save(self,*args,**kwargs):
# is there a way to call super().save() only once?
super().save(*args,*kwargs)
self.pid = self.account + str(self.pk)
super().save(*args,*kwargs)
def __str__(self):
return f"{self.pid} {self.name}"
class Intern(Volunteer):
'''abstrat base class for data entry from /intern (except Project)'''
request_url = models.CharField(max_length=2000, verbose_name='Antrag (URL)')
class Meta:
abstract = True
class HonoraryCertificate(Intern):
''' this class is also used for accreditations '''
project = models.ForeignKey(Project, null=True, blank=True, on_delete=models.SET_NULL)
def __str__(self):
return "Certificate for " + self.realname
TRANSPORT_CHOICES = {'BAHN': 'Bahn',
'NONE': 'Keine Fahrtkosten',
'OTHER': 'Sonstiges (mit Begründung)'}
PAYEDBY_CHOICES = {'WMDE': 'WMDE',
'REQU': 'Antragstellender Mensch'}
class Travel(Intern):
project = models.ForeignKey(Project, on_delete=models.CASCADE)
transport = models.CharField(max_length=5, choices=TRANSPORT_CHOICES.items(), default='BAHN')
other_transport = models.CharField(max_length=200, null=True, blank=True, verbose_name='Sonstige Transportmittel (mit Begründung)')
travelcost = models.CharField(max_length=10, default="0", verbose_name="Fahrtkosten")
checkin = models.DateField(blank=True, null=True, verbose_name='Check In')
checkout = models.DateField(blank=True, null=True, verbose_name='Check Out')
payed_for_hotel_by = models.CharField(max_length=4, choices=PAYEDBY_CHOICES.items(), blank=True, null=True, verbose_name='Kostenauslage Hotel durch')
payed_for_travel_by = models.CharField(max_length=4, choices=PAYEDBY_CHOICES.items(), blank=True, null=True, verbose_name='Kostenauslage Fahrt durch')
notes = models.CharField(max_length=500, blank=True)
#abstract base class for Library and IFG
class Grant(Extern):
cost = models.CharField(max_length=10, verbose_name='Kosten')
notes = models.CharField(max_length=500, blank=True, verbose_name='Anmerkungen')
class Meta:
abstract = True
TYPE_CHOICES = {'BIB': format_html('<a href="https://de.wikipedia.org/wiki/Wikipedia:Förderung/Zugang_zu_Fachliteratur#Bibliotheksstipendium">Bibliotheksstipendium</a>'),
'ELIT': format_html('<a href="https://de.wikipedia.org/wiki/Wikipedia:Förderung/Zugang_zu_Fachliteratur#eLiteraturstipendium">eLiteraturstipendium</a>'),
'MAIL': format_html('<a href="https://de.wikipedia.org/wiki/Wikipedia:Förderung/E-Mail-Adressen_und_Visitenkarten#E-Mail-Adressen">E-Mail-Adresse</a>'),
'IFG': format_html('<a href="https://de.wikipedia.org/wiki/Wikipedia:Förderung/Gebührenerstattungen_für_Behördenanfragen">Kostenübernahme IFG-Anfrage</a>'),
'LIT': format_html('<a href="https://de.wikipedia.org/wiki/Wikipedia:Förderung/Zugang_zu_Fachliteratur#Literaturstipendium">Literaturstipendium</a>'),
'LIST': format_html('<a href="https://de.wikipedia.org/wiki/Wikipedia:Förderung/E-Mail-Adressen_und_Visitenkarten#Mailinglisten">Mailingliste</a>'),
'SOFT': format_html('<a href="https://de.wikipedia.org/wiki/Wikipedia:Förderung/Software-Stipendien">Softwarestipendium</a>'),
'VIS': format_html('<a href="https://de.wikipedia.org/wiki/Wikipedia:Förderung/E-Mail-Adressen_und_Visitenkarten#Visitenkarten">Visitenkarten</a>'),
}
# same model is used for Library, ELitStip and Software!
class Library(Grant):
type = models.CharField(
max_length=4,
choices=TYPE_CHOICES.items(), #attention: actually only BIB, ELIT, SOFT should be used here
default='LIB',
)
library = models.CharField(max_length=200)
duration = models.CharField(max_length=100, verbose_name="Dauer")
def __str__(self):
return self.library
class Literature(Grant):
info = models.CharField(max_length=500, verbose_name='Informationen zum Werk')
source = models.CharField(max_length=200, verbose_name='Bezugsquelle')
class IFG(Grant):
url = models.CharField(max_length=2000)
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):
address = models.CharField(max_length=50,
choices=MAIL_CHOICES.items(),
default='USERNAME', verbose_name='Adressbestandteil')
other = models.CharField(max_length=50,blank=True,null=True)
class List(Domain):
address = models.CharField(max_length=50, default='NO_ADDRESS')
PROJECT_CHOICE = {'PEDIA': 'Wikipedia',
'SOURCE': 'Wikisource',
'BOOKS': 'Wikibooks',
'QUOTE': 'Wikiquote',
'VERSITY': 'Wikiversity',
'VOYAGE': 'Wikivoyage',
'DATA': 'Wikidata',
'NEWS': 'Wikinews',
'COMMONS': 'Wikimedia Commons'}
BC_VARIANT = {'PIC': 'Mit Bild',
'NOPIC': 'Ohne Bild'}
class BusinessCard(Extern):
project = models.CharField(max_length=20, choices=PROJECT_CHOICE.items(),
default='PEDIA', verbose_name='Wikimedia Projekt')
data = models.CharField(max_length=1000, verbose_name='Persönliche Daten', default='')
variant = models.CharField(max_length=5, choices=BC_VARIANT.items(),
default='NOPIC', verbose_name='Variante')
sent_to = models.CharField(max_length=1000, verbose_name='Sendungsadresse',
default='')