From 2c63fc2bf8f668955a0f40e0d6fac04a08c04647 Mon Sep 17 00:00:00 2001 From: qch3n Date: Sat, 24 Feb 2024 20:36:18 +0100 Subject: [PATCH] check if wikipage exists and disallow user pages for public events --- cal/forms.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cal/forms.py b/cal/forms.py index deebb51..2f2627d 100644 --- a/cal/forms.py +++ b/cal/forms.py @@ -4,7 +4,8 @@ from django.forms.fields import SplitDateTimeField from django.contrib.admin.widgets import AdminSplitDateTime from .models import Event -import re +import re +import requests class EventForm(ModelForm): @@ -27,5 +28,13 @@ def clean(self): end_date = cleaned_data.get('endDate') if end_date and end_date < start_date: self.add_error('endDate', 'End date must be greater than start date') - cleaned_data['wikiPage'] = re.sub(r'^http(s)://metalab.at/wiki/', '',cleaned_data.get('wikiPage')) - return cleaned_data + wikipage = re.sub(r'^http(s)://metalab.at/wiki/', '',cleaned_data.get('wikiPage')) + cleaned_data['wikiPage'] = wikipage + if cleaned_data.get('advertise') and re.match(r'^(Benutzer|User):', wikipage): + self.add_error('wikiPage', 'Userpages don\'t provide adequate information for public Events') + + r = requests.get('https://metalab.at/wiki/%s' % wikipage) + + if r.status_code == 404: + self.add_error('wikiPage', 'Wikipage not found: https://metalab.at/wiki/%s' % wikipage) #TODO Figure out how to make clickable + return cleaned_data \ No newline at end of file