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.

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