You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.3 KiB

4 years ago
4 years ago
  1. from datetime import date
  2. from django.db import models
  3. from .settings import ACCOUNTS
  4. class Volunteer(models.Model):
  5. realname = models.CharField(max_length=200, null=True)
  6. email = models.CharField(max_length=200, null=True)
  7. # username = models.CharField(max_length=200, null=True)
  8. # the following Fields are not supposed to be edited by users
  9. granted = models.BooleanField(null=True)
  10. granted_date = models.DateField(null=True)
  11. survey_mail_send = models.BooleanField(null=True)
  12. @classmethod
  13. def set_granted(cl, key, b):
  14. obj = cl.objects.get(pk=key)
  15. obj.granted = b
  16. obj.granted_date = date.today()
  17. obj.save()
  18. class Meta:
  19. abstract = True
  20. class Extern(Volunteer):
  21. ''' abstract basis class for all data entered by extern volunteers '''
  22. username = models.CharField(max_length=200, null=True)
  23. class Meta:
  24. abstract = True
  25. class Project(Volunteer):
  26. name = models.CharField(max_length=200)
  27. start = models.DateField('Startdatum', null=True)
  28. end = models.DateField('Erwartetes Projektende', null=True)
  29. account = models.CharField('Kostenstelle', max_length=5,
  30. choices=ACCOUNTS.items(), null=True,)
  31. # the following Fields are not supposed to be edited by users
  32. pid = models.IntegerField(null=True, blank=True)
  33. end_mail_send = models.BooleanField(null=True)
  34. def save(self,*args,**kwargs):
  35. # is there a way to call super().save() only once?
  36. super().save(*args,*kwargs)
  37. self.pid = 10000 + self.pk
  38. super().save(*args,*kwargs)
  39. def __str__(self):
  40. return f"{self.pid} {self.name}"
  41. class Intern(Volunteer):
  42. '''abstrat base class for data entry from /intern (except Project)'''
  43. request_url = models.CharField(max_length=2000)
  44. class Meta:
  45. abstract = True
  46. class HonoraryCertificate(Intern):
  47. ''' this class is also used for accreditations '''
  48. # request_url = models.CharField(max_length=2000)
  49. project = models.ForeignKey(Project, null=True, blank=True, on_delete=models.SET_NULL)
  50. def __str__(self):
  51. return "Certificate for " + self.realname
  52. class Travel(Intern):
  53. project = models.ForeignKey(Project, on_delete=models.CASCADE)
  54. #abstract base class for Library and IFG
  55. class Grant(Extern):
  56. cost = models.CharField(max_length=10)
  57. notes = models.CharField(max_length=500)
  58. class Meta:
  59. abstract = True
  60. TYPE_CHOICES = {'BIB': 'Bibliotheksstipendium',
  61. 'ELIT': 'eLiteraturstipendium',
  62. 'SOFT': 'Softwarestipendium',
  63. 'VIS': 'Visitenkarten',
  64. 'LIST': 'Mailingliste',
  65. 'MAIL': 'E-Mail-Adresse',
  66. 'IFG': 'Kostenübernahme IFG-Anfrage',
  67. 'LIT': 'Literaturstipendium',}
  68. # same model is used for Library, ELitStip and Software!
  69. class Library(Grant):
  70. type = models.CharField(
  71. max_length=4,
  72. choices=TYPE_CHOICES.items(), #attention: actually only BIB, ELIT, SOFT should be used here
  73. default='LIB',
  74. )
  75. library = models.CharField(max_length=200)
  76. duration = models.CharField(max_length=100)
  77. def __str__(self):
  78. return self.library
  79. class IFG(Grant):
  80. url = models.CharField(max_length=2000)
  81. def __str__(self):
  82. return "IFG-Anfrage von " + self.realname