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.

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