Skip to content

Commit

Permalink
check if wikipage exists and disallow user pages for public events
Browse files Browse the repository at this point in the history
  • Loading branch information
qch3n-at authored and ppiro committed Feb 24, 2024
1 parent 2a59c55 commit 2c63fc2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cal/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

0 comments on commit 2c63fc2

Please sign in to comment.