Commit ffd2c75e authored by Jean Michel Rouly's avatar Jean Michel Rouly
Browse files

Added link preview page.

parent 74f51dea
...@@ -41,24 +41,19 @@ def index(request): ...@@ -41,24 +41,19 @@ def index(request):
url.full_clean() url.full_clean()
url.save() url.save()
return redirect('success') return redirect('view', url.short)
return render(request, 'index.html', { return render(request, 'index.html', {
'form': url_form, 'form': url_form,
}, },
) )
# Sucessful url registration page. # Preview a link.
@login_required def view(request, short):
def success(request):
url = None url = get_object_or_404(URL, short__iexact = short)
try:
url = URL.objects.filter(owner=request.user).latest('date_created')
except URL.DoesNotExist:
pass
return render(request, 'success.html', { return render(request, 'view.html', {
'url': url, 'url': url,
}, },
) )
...@@ -76,7 +71,7 @@ def my_links(request): ...@@ -76,7 +71,7 @@ def my_links(request):
# Delete link page. # Delete link page.
@login_required @login_required
def delete(request, short): def delete(request, short):
url = get_object_or_404(URL, short = short ) url = get_object_or_404(URL, short__iexact = short )
if url.owner == request.user: if url.owner == request.user:
url.delete() url.delete()
return redirect('my_links') return redirect('my_links')
......
...@@ -8,8 +8,8 @@ urlpatterns = patterns('go.views', ...@@ -8,8 +8,8 @@ urlpatterns = patterns('go.views',
# / - Homepage url. # / - Homepage url.
url(r'^$', 'index', name = 'index'), url(r'^$', 'index', name = 'index'),
# / - Successful url registration page. # /view/<short> - View URL data.
url(r'^success$', 'success', name = 'success'), url(r'^view/(?P<short>\w+)$', 'view', name = 'view'),
# /about - About page. # /about - About page.
url(r'^about/?$', 'about', name = 'about'), url(r'^about/?$', 'about', name = 'about'),
...@@ -20,7 +20,7 @@ urlpatterns = patterns('go.views', ...@@ -20,7 +20,7 @@ urlpatterns = patterns('go.views',
# /my - My-Links page, view and review links. # /my - My-Links page, view and review links.
url(r'^my/?$', 'my_links', name = 'my_links'), url(r'^my/?$', 'my_links', name = 'my_links'),
# /delete - Delete a link, no content display. # /delete/<short> - Delete a link, no content display.
url(r'^delete/(?P<short>\w+)$', 'delete', name = 'delete'), url(r'^delete/(?P<short>\w+)$', 'delete', name = 'delete'),
# /admin - Administrator interface. # /admin - Administrator interface.
......
{% extends 'base.html' %}
{% block title %}
Go - Success
{% endblock %}
{% block content %}
{# If it exists, display the most recently created URL. #}
{% if url %}
<h3>~Shorten URL~</h3>
<p><em>Original URL</em>: <a href="{{ url.target }}">{{ url.target }}</a></p>
<p><em>Shortened URL</em>: <a href="{{ url.short }}">{{ url.short }}</a></p>
{% else %}
<p>Nothing here.</p>
{% endif %}
{% endblock %}
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