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.

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