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.

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