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.

183 lines
5.9 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. # the following Fields are not supposed to be edited by users
  24. service_id = models.CharField(max_length=15, null=True, blank=True)
  25. def save(self,*args,**kwargs):
  26. # is there a way to call super().save() only once?
  27. super().save(*args,*kwargs)
  28. print('******EXTERNSAVE********')
  29. self.service_id = type(self).__name__ + str(self.pk)
  30. super().save(*args,*kwargs)
  31. class Meta:
  32. abstract = True
  33. class Project(Volunteer):
  34. name = models.CharField(max_length=200)
  35. start = models.DateField('Startdatum', null=True)
  36. end = models.DateField('Erwartetes Projektende', null=True)
  37. account = models.CharField('Kostenstelle', max_length=5,
  38. choices=ACCOUNTS.items(), null=True,)
  39. # the following Fields are not supposed to be edited by users
  40. pid = models.CharField(max_length=15, null=True, blank=True)
  41. end_mail_send = models.BooleanField(null=True)
  42. status = models.CharField(max_length=3,choices=(('RUN', 'läuft'),('END','beendet')),default='RUN')
  43. persons = models.IntegerField(default=1)
  44. def save(self,*args,**kwargs):
  45. # is there a way to call super().save() only once?
  46. super().save(*args,*kwargs)
  47. self.pid = self.account + str(self.pk)
  48. super().save(*args,*kwargs)
  49. def __str__(self):
  50. return f"{self.pid} {self.name}"
  51. class Intern(Volunteer):
  52. '''abstrat base class for data entry from /intern (except Project)'''
  53. request_url = models.CharField(max_length=2000)
  54. class Meta:
  55. abstract = True
  56. class HonoraryCertificate(Intern):
  57. ''' this class is also used for accreditations '''
  58. # request_url = models.CharField(max_length=2000)
  59. project = models.ForeignKey(Project, null=True, blank=True, on_delete=models.SET_NULL)
  60. def __str__(self):
  61. return "Certificate for " + self.realname
  62. class Travel(Intern):
  63. project = models.ForeignKey(Project, on_delete=models.CASCADE)
  64. #abstract base class for Library and IFG
  65. class Grant(Extern):
  66. cost = models.CharField(max_length=10)
  67. notes = models.CharField(max_length=500, blank=True)
  68. class Meta:
  69. abstract = True
  70. TYPE_CHOICES = {'BIB': 'Bibliotheksstipendium',
  71. 'ELIT': 'eLiteraturstipendium',
  72. 'SOFT': 'Softwarestipendium',
  73. 'VIS': 'Visitenkarten',
  74. 'LIST': 'Mailingliste',
  75. 'MAIL': 'E-Mail-Adresse',
  76. 'IFG': 'Kostenübernahme IFG-Anfrage',
  77. 'LIT': 'Literaturstipendium',}
  78. # same model is used for Library, ELitStip and Software!
  79. class Library(Grant):
  80. type = models.CharField(
  81. max_length=4,
  82. choices=TYPE_CHOICES.items(), #attention: actually only BIB, ELIT, SOFT should be used here
  83. default='LIB',
  84. )
  85. library = models.CharField(max_length=200)
  86. duration = models.CharField(max_length=100)
  87. def __str__(self):
  88. return self.library
  89. class Literature(Grant):
  90. info = models.CharField(max_length=500)
  91. source = models.CharField(max_length=200)
  92. class IFG(Grant):
  93. url = models.CharField(max_length=2000)
  94. def __str__(self):
  95. return "IFG-Anfrage von " + self.realname
  96. DOMAIN_CHOICES = {'PEDIA': '@wikipedia.de',
  97. 'BOOKS': '@wikibooks.de',
  98. 'QUOTE': '@wikiquote.de',
  99. 'SOURCE': '@wikisource.de',
  100. 'VERSITY': '@wikiversity.de',}
  101. class Domain(Extern):
  102. domain = models.CharField(max_length=10,
  103. choices=DOMAIN_CHOICES.items(),
  104. default='PEDIA')
  105. class Meta:
  106. abstract = True
  107. MAIL_CHOICES = {'REALNAME': 'Vorname.Nachname',
  108. 'USERNAME': 'Username',
  109. 'OTHER': 'Sonstiges:'}
  110. class Email(Domain):
  111. address = models.CharField(max_length=50,
  112. choices=MAIL_CHOICES.items(),
  113. default='USERNAME', verbose_name='Adressbestandteil')
  114. other = models.CharField(max_length=50,blank=True,null=True)
  115. class List(Domain):
  116. address = models.CharField(max_length=50, default='NO_ADDRESS')
  117. PROJECT_CHOICE = {'PEDIA': 'Wikipedia',
  118. 'SOURCE': 'Wikisource',
  119. 'BOOKS': 'Wikibooks',
  120. 'QUOTE': 'Wikiquote',
  121. 'VERSITY': 'Wikiversity',
  122. 'VOYAGE': 'Wikivoyage',
  123. 'DATA': 'Wikidata',
  124. 'NEWS': 'Wikinews',
  125. 'COMMONS': 'Wikimedia Commons'}
  126. BC_VARIANT = {'PIC': 'Mit Bild',
  127. 'NOPIC': 'Ohne Bild'}
  128. class BusinessCard(Extern):
  129. project = models.CharField(max_length=20, choices=PROJECT_CHOICE.items(),
  130. default='PEDIA', verbose_name='Wikimedia Projekt')
  131. data = models.CharField(max_length=1000, verbose_name='Persönliche Daten', default='')
  132. variant = models.CharField(max_length=5, choices=BC_VARIANT.items(),
  133. default='NOPIC', verbose_name='Variante')
  134. sent_to = models.CharField(max_length=1000, verbose_name='Sendungsadresse',
  135. default='')