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.

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