diff --git a/AKModel/models.py b/AKModel/models.py index 3908a1a13ed2022f399d27c08e21c8a9174af7a8..6d48498990699fd87e8682cc840292cbc6191e1f 100644 --- a/AKModel/models.py +++ b/AKModel/models.py @@ -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. diff --git a/AKSubmission/forms.py b/AKSubmission/forms.py index 1ee786d22963dacf1301d1b2984b7771defc1d58..f7187adebe067dea3ae6b73df2c149c6e0ae7c07 100644 --- a/AKSubmission/forms.py +++ b/AKSubmission/forms.py @@ -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()]