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.

90 lines
2.6 KiB

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