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.

105 lines
3.0 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 HonoraryCertificate(Volunteer):
  42. ''' this class is also used for accreditations '''
  43. request_url = models.CharField(max_length=2000)
  44. project = models.ForeignKey(Project, null = True, on_delete = models.SET_NULL)
  45. def __str__(self):
  46. return "Certificate for " + self.realname
  47. #abstract base class for Library and IFG
  48. class Grant(Extern):
  49. cost = models.CharField(max_length=10)
  50. notes = models.CharField(max_length=500)
  51. class Meta:
  52. abstract = True
  53. TYPE_CHOICES = {'BIB': 'Bibliotheksstipendium',
  54. 'ELIT': 'eLiteraturstipendium',
  55. 'SOFT': 'Softwarestipendium',
  56. 'VIS': 'Visitenkarten',
  57. 'LIST': 'Mailingliste',
  58. 'MAIL': 'E-Mail-Adresse',
  59. 'IFG': 'Kostenübernahme IFG-Anfrage',
  60. 'LIT': 'Literaturstipendium',}
  61. # same model is used for Library, ELitStip and Software!
  62. class Library(Grant):
  63. type = models.CharField(
  64. max_length=4,
  65. choices=TYPE_CHOICES.items(), #attention: actually only BIB, ELIT, SOFT should be used here
  66. default='LIB',
  67. )
  68. library = models.CharField(max_length=200)
  69. duration = models.CharField(max_length=100)
  70. def __str__(self):
  71. return self.library
  72. class IFG(Grant):
  73. url = models.CharField(max_length=2000)
  74. def __str__(self):
  75. return "IFG-Anfrage von " + self.realname