Skip to content
Snippets Groups Projects
Commit dcafb769 authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Move link-autogeneration from submission form to model and disable frontend editing

This ensures that it is always called when new AKs are created.
Additionally, editing of links in frontend is disabled, preventing diverging links between our tool and the wiki export.
This fixes #193 and #204.
parent 73e8b938
Branches
No related tags found
1 merge request!216Improve submission & fix model errors
Pipeline #228643 passed
......@@ -317,7 +317,7 @@ class AK(models.Model):
owners = models.ManyToManyField(to=AKOwner, blank=True, verbose_name=_('Owners'),
help_text=_('Those organizing the AK'))
# TODO generate automatically
# Will be automatically generated in save method if not set
link = models.URLField(blank=True, verbose_name=_('Web Link'), help_text=_('Link to wiki page'))
protocol_link = models.URLField(blank=True, verbose_name=_('Protocol Link'), help_text=_('Link to protocol'))
......@@ -466,6 +466,17 @@ class AK(models.Model):
return reverse_lazy('submit:ak_detail', kwargs={'event_slug': self.event.slug, 'pk': self.id})
return self.edit_url
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
# Auto-Generate Link if not set yet
if self.link == "":
link = self.event.base_url + self.name.replace(" ", "_")
# Truncate links longer than 200 characters (default length of URL fields in django)
self.link = link[:200]
# Tell Django that we have updated the link field
if update_fields is not None:
update_fields = {"link"}.union(update_fields)
super().save(force_insert, force_update, using, update_fields)
class Room(models.Model):
""" A room describes where an AK can be held.
......
......@@ -33,7 +33,6 @@ class AKForm(AvailabilitiesFormMixin, forms.ModelForm):
model = AK
fields = ['name',
'short_name',
'link',
'protocol_link',
'owners',
'description',
......@@ -101,7 +100,7 @@ class AKForm(AvailabilitiesFormMixin, forms.ModelForm):
"""
Normalize/clean inputs
Generate a (not yet used) short name if field was left blank, generate a wiki link,
Generate a (not yet used) short name if field was left blank,
create a list of normalized slot durations
:return: cleaned inputs
......@@ -128,12 +127,6 @@ class AKForm(AvailabilitiesFormMixin, forms.ModelForm):
short_name = f'{short_name[:-(digits + 1)]}-{i}'
cleaned_data["short_name"] = short_name
# Generate wiki link
if self.cleaned_data["event"].base_url:
link = self.cleaned_data["event"].base_url + self.cleaned_data["name"].replace(" ", "_")
# Truncate links longer than 200 characters (default length of URL fields in django)
self.cleaned_data["link"] = link[:200]
# Get durations from raw durations field
if "durations" in cleaned_data:
cleaned_data["durations"] = [self._clean_duration(d) for d in self.cleaned_data["durations"].split()]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment