Unverified Commit a6205fc3 authored by David Haynes's avatar David Haynes
Browse files

User can edit shortlink

- Copies over old attributes that were unedited, deletes old url and
  saves new one

- also fixed css bug on link_box
parent ff22f146
Pipeline #1177 passed with stage
in 1 minute and 1 second
......@@ -61,7 +61,7 @@
<div class="col-md-8">
<!-- what is the address? -->
<h3>Go Address:</h3>
<div id="link-container" class="input-group">
<div id="link-container-{{url.short}}" class="input-group">
<a id="link-{{url.short}}" class="form-control" href="{{domain}}{{url.short}}" target="_blank">
......@@ -224,7 +224,61 @@ def edit(request, short):
# Django will check the form to make sure it's valid
if url_form.is_valid():
return redirect('view', None)
# 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:
# Parse the form and create a new URL object
res = post(request, url_form)
# If there is a 500 error returned, handle it
if res == 500:
return HttpResponseServerError(render(request, '500.html'))
# 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
# Save the new URL
# Redirect to the shiny new *edited URL
return redirect('view', res.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()
# Grab the expiration field value. It's currently an unsable
# string value, so we need to parse it into a datetime object
# relative to right now.
expires = url_form.cleaned_data.get('expires')
# Determine what the expiration date is
if expires == URLForm.DAY:
edited_expires = timezone.now() + timedelta(days=1)
elif expires == URLForm.WEEK:
edited_expires = timezone.now() + timedelta(weeks=1)
elif expires == URLForm.MONTH:
edited_expires = timezone.now() + timedelta(weeks=3)
elif expires == URLForm.CUSTOM:
edited_expires = url_form.cleaned_data.get('expires_custom')
pass # leave the field NULL
if edited_expires != url.expires:
url.expires = edited_expires
# Redirect to the shiny new *edited URL
return redirect('view', res.short)
# Else, there is an error, redisplay the form with the validation errors
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