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.

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