Skip to content
Snippets Groups Projects
Commit 566954b6 authored by Benjamin Hättasch's avatar Benjamin Hättasch Committed by Nadja Geisler
Browse files

Move link creation from view to form

This makes the usage of save(commit=False) obsolete that could cause issues for the creation of Availabilities (due to atomicy of transactions).
parent 8978f21c
No related branches found
No related tags found
1 merge request!123Fix smaller issues
...@@ -2,6 +2,7 @@ import itertools ...@@ -2,6 +2,7 @@ import itertools
import re import re
from django import forms from django import forms
from django.contrib import messages
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
...@@ -100,6 +101,15 @@ class AKForm(AvailabilitiesFormMixin, forms.ModelForm): ...@@ -100,6 +101,15 @@ class AKForm(AvailabilitiesFormMixin, forms.ModelForm):
short_name = '{}-{}'.format(short_name[:-(digits + 1)], i) short_name = '{}-{}'.format(short_name[:-(digits + 1)], i)
cleaned_data["short_name"] = short_name 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]
if len(link) > 200:
messages.add_message(self.request, messages.WARNING,
_("Due to technical reasons, the link you entered was truncated to a length of 200 characters"))
# Get tag names from raw tags # Get tag names from raw tags
cleaned_data["tag_names"] = [name.strip().lower() for name cleaned_data["tag_names"] = [name.strip().lower() for name
in self.split_string.split(cleaned_data["tags_raw"]) in self.split_string.split(cleaned_data["tags_raw"])
......
...@@ -215,18 +215,6 @@ class AKAndAKWishSubmissionView(EventSlugMixin, EventInactiveRedirectMixin, Crea ...@@ -215,18 +215,6 @@ class AKAndAKWishSubmissionView(EventSlugMixin, EventInactiveRedirectMixin, Crea
return redirect(reverse_lazy('submit:submission_overview', return redirect(reverse_lazy('submit:submission_overview',
kwargs={'event_slug': form.cleaned_data["event"].slug})) kwargs={'event_slug': form.cleaned_data["event"].slug}))
# Generate object but don't store it in the database yet
self.object = form.save(commit=False)
# Generate wiki link
if form.cleaned_data["event"].base_url:
link = form.cleaned_data["event"].base_url + form.cleaned_data["name"].replace(" ", "_")
# Truncate links longer than 200 characters (default length of URL fields in django)
self.object.link = link[:200]
if len(link) > 200:
messages.add_message(self.request, messages.WARNING,
_("Due to technical reasons, the link you entered was truncated to a length of 200 characters"))
# Try to save AK and get redirect URL # Try to save AK and get redirect URL
super_form_valid = super().form_valid(form) super_form_valid = super().form_valid(form)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment