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.

171 lines
5.3 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 Intern(Volunteer):
  42. '''abstrat base class for data entry from /intern (except Project)'''
  43. request_url = models.CharField(max_length=2000)
  44. class Meta:
  45. abstract = True
  46. class HonoraryCertificate(Intern):
  47. ''' this class is also used for accreditations '''
  48. # request_url = models.CharField(max_length=2000)
  49. project = models.ForeignKey(Project, null=True, blank=True, on_delete=models.SET_NULL)
  50. def __str__(self):
  51. return "Certificate for " + self.realname
  52. class Travel(Intern):
  53. project = models.ForeignKey(Project, on_delete=models.CASCADE)
  54. #abstract base class for Library and IFG
  55. class Grant(Extern):
  56. cost = models.CharField(max_length=10)
  57. notes = models.CharField(max_length=500, blank=True)
  58. class Meta:
  59. abstract = True
  60. TYPE_CHOICES = {'BIB': 'Bibliotheksstipendium',
  61. 'ELIT': 'eLiteraturstipendium',
  62. 'SOFT': 'Softwarestipendium',
  63. 'VIS': 'Visitenkarten',
  64. 'LIST': 'Mailingliste',
  65. 'MAIL': 'E-Mail-Adresse',
  66. 'IFG': 'Kostenübernahme IFG-Anfrage',
  67. 'LIT': 'Literaturstipendium',}
  68. # same model is used for Library, ELitStip and Software!
  69. class Library(Grant):
  70. type = models.CharField(
  71. max_length=4,
  72. choices=TYPE_CHOICES.items(), #attention: actually only BIB, ELIT, SOFT should be used here
  73. default='LIB',
  74. )
  75. library = models.CharField(max_length=200)
  76. duration = models.CharField(max_length=100)
  77. def __str__(self):
  78. return self.library
  79. class Literature(Grant):
  80. info = models.CharField(max_length=500)
  81. source = models.CharField(max_length=200)
  82. class IFG(Grant):
  83. url = models.CharField(max_length=2000)
  84. def __str__(self):
  85. return "IFG-Anfrage von " + self.realname
  86. DOMAIN_CHOICES = {'PEDIA': '@wikipedia.de',
  87. 'BOOKS': '@wikibooks.de',
  88. 'QUOTE': '@wikiquote.de',
  89. 'SOURCE': '@wikisource.de',
  90. 'VERSITY': '@wikiversity.de',}
  91. class Domain(Extern):
  92. domain = models.CharField(max_length=10,
  93. choices=DOMAIN_CHOICES.items(),
  94. default='PEDIA')
  95. class Meta:
  96. abstract = True
  97. MAIL_CHOICES = {'REALNAME': 'Vorname.Nachname',
  98. 'USERNAME': 'Username',
  99. 'OTHER': 'Sonstiges:'}
  100. class Email(Domain):
  101. address = models.CharField(max_length=50,
  102. choices=MAIL_CHOICES.items(),
  103. default='USERNAME', verbose_name='Adressbestandteil')
  104. other = models.CharField(max_length=50,blank=True,null=True)
  105. class List(Domain):
  106. address = models.CharField(max_length=50, default='NO_ADDRESS')
  107. PROJECT_CHOICE = {'PEDIA': 'Wikipedia',
  108. 'SOURCE': 'Wikisource',
  109. 'BOOKS': 'Wikibooks',
  110. 'QUOTE': 'Wikiquote',
  111. 'VERSITY': 'Wikiversity',
  112. 'VOYAGE': 'Wikivoyage',
  113. 'DATA': 'Wikidata',
  114. 'NEWS': 'Wikinews',
  115. 'COMMONS': 'Wikimedia Commons'}
  116. BC_VARIANT = {'PIC': 'Mit Bild',
  117. 'NOPIC': 'Ohne Bild'}
  118. class BusinessCard(Extern):
  119. project = models.CharField(max_length=20, choices=PROJECT_CHOICE.items(),
  120. default='PEDIA', verbose_name='Wikimedia Projekt')
  121. data = models.CharField(max_length=1000, verbose_name='Persönliche Daten', default='NODATA')
  122. variant = models.CharField(max_length=5, choices=BC_VARIANT.items(),
  123. default='NOPIC', verbose_name='Variante')
  124. sent_to = models.CharField(max_length=1000, verbose_name='Sendungsadresse',
  125. default='NOADRESS')