From f60623d485c2a410395f583c1c2a1d718f339253 Mon Sep 17 00:00:00 2001 From: alpcentaur Date: Wed, 25 Oct 2023 15:50:40 +0000 Subject: [PATCH] user gets automatically written, not in the form anymore --- input/forms.py | 2 +- input/middleware/oauth.py | 6 +++--- input/models.py | 7 +++++-- input/views.py | 2 ++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/input/forms.py b/input/forms.py index 79fa58c..a66b828 100755 --- a/input/forms.py +++ b/input/forms.py @@ -38,7 +38,7 @@ class ExternForm(FdbForm): class Meta: model = ConcreteExtern - exclude = ('granted', 'granted_date', 'survey_mail_send', 'service_id', 'survey_mail_date', 'mail_state') + exclude = ('username', 'granted', 'granted_date', 'survey_mail_send', 'service_id', 'survey_mail_date', 'mail_state') INTERN_CHOICES = {'PRO': 'Projektsteckbrief', diff --git a/input/middleware/oauth.py b/input/middleware/oauth.py index ca30b1f..0d5239e 100644 --- a/input/middleware/oauth.py +++ b/input/middleware/oauth.py @@ -5,7 +5,7 @@ from django.shortcuts import redirect from django.utils.deprecation import MiddlewareMixin from foerderbarometer import settings from input import views - +from input import models class OAuthMiddleware(MiddlewareMixin): @@ -33,8 +33,8 @@ class OAuthMiddleware(MiddlewareMixin): print('oi') self.clear_session(request) request.session['token'] = sso_client.authorize_access_token(request) - print('blub', request.session['token']) - print('user', self.get_current_user(sso_client, request)) + # print('blub', request.session['token']) + models.Extern.username = self.get_current_user(sso_client, request)['username'] if self.get_current_user(sso_client, request) is not None: redirect_uri = request.session.pop('redirect_uri', None) if redirect_uri is not None: diff --git a/input/models.py b/input/models.py index 6e0e58a..de4b8b5 100755 --- a/input/models.py +++ b/input/models.py @@ -13,11 +13,12 @@ EMAIL_STATES = {'NONE': 'noch keine Mail versendet', class Volunteer(models.Model): realname = models.CharField(max_length=200, null=True, verbose_name="Realname", - help_text="Bitte gib deinen Vornamen und deinen Nachnamen ein.") + help_text="Bitte gib deinen Vornamen und deinen Nachnamen ein.", default='oi') email = models.EmailField(max_length=200, null=True, verbose_name='E-Mail-Adresse', help_text=format_html('Bitte gib deine E-Mail-Adresse ein, damit dich
Wikimedia Deutschland bei Rückfragen oder für
die Zusage kontaktieren kann.')) # the following Fields are not supposed to be edited by users + granted = models.BooleanField(null=True, verbose_name='bewilligt') granted_date = models.DateField(null=True, verbose_name='bewilligt am') survey_mail_date = models.DateField(verbose_name='Umfragemail wurde verschickt am', null=True, blank=True) @@ -36,10 +37,12 @@ class Volunteer(models.Model): abstract = True + class Extern(Volunteer): ''' abstract basis class for all data entered by extern volunteers ''' + username = models.CharField(max_length=200, null=True, verbose_name='Benutzer_innenname', - help_text=format_html("Bitte gib den Namen ein, mit dem du dich
in den Wikimedia-Projekten registriert hast.")) + help_text=format_html("Wikimedia Benutzer_innenname")) # the following Fields are not supposed to be edited by users service_id = models.CharField(max_length=15, null=True, blank=True) diff --git a/input/views.py b/input/views.py index 8a3df6f..e25e12d 100755 --- a/input/views.py +++ b/input/views.py @@ -216,6 +216,8 @@ class ExternView(CookieWizardView): data = {} for form in form_list: data = {**data, **form.cleaned_data} + + data['username'] = self.request.session['user']['username'] if data['choice'] == 'LIT': if data['selfbuy'] == 'TRUE':