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.

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