Unverified Commit 9c022931 authored by David Haynes's avatar David Haynes
Browse files

Finish first pass on editing links

- Can edit short, target, and expiration date
- Get around the short  PK by just making a copy and applying changes and then
saving it
parent a6205fc3
Pipeline #1178 passed with stage
in 1 minute and 2 seconds
......@@ -222,11 +222,16 @@ def edit(request, short):
# request
url_form = URLForm(request.POST, host=request.META.get('HTTP_HOST'))
# Make a copy of the old URL
copy = url
# Remove the old one
# Django will check the form to make sure it's valid
if url_form.is_valid():
# If the short changed then we need to create a new object and
# migrate some data over
if url_form.cleaned_data.get('short').strip() != url.short:
if url_form.cleaned_data.get('short').strip() != copy.short:
# Parse the form and create a new URL object
res = post(request, url_form)
......@@ -237,12 +242,9 @@ def edit(request, short):
# We can procede with the editing process
# Migrate clicks data
res.clicks = url.clicks
res.qrclicks = url.clicks
res.socialclicks = url.clicks
# Remove the old one
res.clicks = copy.clicks
res.qrclicks = copy.clicks
res.socialclicks = copy.clicks
# Save the new URL
......@@ -252,9 +254,9 @@ def edit(request, short):
# The short was not edited and thus, we can directly edit the url
if url_form.cleaned_data.get('target').strip() != url.target:
url.target = url_form.cleaned_data.get('target').strip()
if url_form.cleaned_data.get('target').strip() != copy.target:
copy.target = url_form.cleaned_data.get('target').strip()
# Grab the expiration field value. It's currently an unsable
# string value, so we need to parse it into a datetime object
......@@ -273,12 +275,12 @@ def edit(request, short):
pass # leave the field NULL
if edited_expires != url.expires:
url.expires = edited_expires
if edited_expires != copy.expires:
copy.expires = edited_expires
# Redirect to the shiny new *edited URL
return redirect('view', res.short)
return redirect('view', copy.short)
# Else, there is an error, redisplay the form with the validation errors
......@@ -308,9 +310,6 @@ def edit(request, short):
return render(request, 'core/edit_link.html', {
'form': url_form
# redirect to my_links
# return redirect('my_links')
# do not allow them to edit
raise PermissionDenied()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment