forked from beba/foerderbarometer
119 lines
3.3 KiB
Python
119 lines
3.3 KiB
Python
from datetime import date
|
|
|
|
from django.db import models
|
|
|
|
from .settings import ACCOUNTS
|
|
|
|
|
|
class Volunteer(models.Model):
|
|
realname = models.CharField(max_length=200, null=True)
|
|
email = models.CharField(max_length=200, null=True)
|
|
username = models.CharField(max_length=200, null=True)
|
|
|
|
# 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(null=True)
|
|
|
|
@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)
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
class Project(Volunteer):
|
|
name = models.CharField(max_length=200)
|
|
start = models.DateField('Startdatum', null=True)
|
|
end = models.DateField('Erwartetes Projektende', null=True)
|
|
account = models.CharField('Kostenstelle', max_length=5,
|
|
choices=ACCOUNTS.items(), null=True,)
|
|
|
|
# the following Fields are not supposed to be edited by users
|
|
pid = models.IntegerField(null=True, blank=True)
|
|
end_mail_send = models.BooleanField(null=True)
|
|
|
|
def save(self,*args,**kwargs):
|
|
# is there a way to call super().save() only once?
|
|
super().save(*args,*kwargs)
|
|
self.pid = 10000 + 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)
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
|
|
class HonoraryCertificate(Intern):
|
|
''' this class is also used for accreditations '''
|
|
|
|
# request_url = models.CharField(max_length=2000)
|
|
project = models.ForeignKey(Project, null = True, on_delete = models.SET_NULL)
|
|
|
|
def __str__(self):
|
|
return "Certificate for " + self.realname
|
|
|
|
|
|
class Travel(Intern):
|
|
project = models.ForeignKey(Project, on_delete = models.CASCADE)
|
|
|
|
|
|
|
|
#abstract base class for Library and IFG
|
|
class Grant(Extern):
|
|
cost = models.CharField(max_length=10)
|
|
notes = models.CharField(max_length=500)
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
|
|
TYPE_CHOICES = {'BIB': 'Bibliotheksstipendium',
|
|
'ELIT': 'eLiteraturstipendium',
|
|
'SOFT': 'Softwarestipendium',
|
|
'VIS': 'Visitenkarten',
|
|
'LIST': 'Mailingliste',
|
|
'MAIL': 'E-Mail-Adresse',
|
|
'IFG': 'Kostenübernahme IFG-Anfrage',
|
|
'LIT': 'Literaturstipendium',}
|
|
|
|
|
|
# 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)
|
|
|
|
def __str__(self):
|
|
return self.library
|
|
|
|
|
|
class IFG(Grant):
|
|
url = models.CharField(max_length=2000)
|
|
|
|
def __str__(self):
|
|
return "IFG-Anfrage von " + self.realname
|