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

Added link preview page.

parent 74f51dea
......@@ -41,24 +41,19 @@ def index(request):
url.full_clean()
url.save()
return redirect('success')
return redirect('view', url.short)
return render(request, 'index.html', {
'form': url_form,
},
)
# Sucessful url registration page.
@login_required
def success(request):
# Preview a link.
def view(request, short):
url = None
try:
url = URL.objects.filter(owner=request.user).latest('date_created')
except URL.DoesNotExist:
pass
url = get_object_or_404(URL, short__iexact = short)
return render(request, 'success.html', {
return render(request, 'view.html', {
'url': url,
},
)
......@@ -76,7 +71,7 @@ def my_links(request):
# Delete link page.
@login_required
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:
url.delete()
return redirect('my_links')
......
......@@ -8,8 +8,8 @@ urlpatterns = patterns('go.views',
# / - Homepage url.
url(r'^$', 'index', name = 'index'),
# / - Successful url registration page.
url(r'^success$', 'success', name = 'success'),
# /view/<short> - View URL data.
url(r'^view/(?P<short>\w+)$', 'view', name = 'view'),
# /about - About page.
url(r'^about/?$', 'about', name = 'about'),
......@@ -20,7 +20,7 @@ urlpatterns = patterns('go.views',
# /my - My-Links page, view and review 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'),
# /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