From 182fb57999d82ca46b29ce212a593bfcdca68c2f Mon Sep 17 00:00:00 2001 From: steve Date: Sun, 5 Mar 2017 16:58:33 +0000 Subject: [PATCH] Update views.py Had an issue where my urls were creating duplicates. Took me a while but figured it out. Thanks for the course J. --- src/shortener/views.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/shortener/views.py b/src/shortener/views.py index a25a617..b3147cc 100644 --- a/src/shortener/views.py +++ b/src/shortener/views.py @@ -35,6 +35,16 @@ def post(self, request, *args, **kwargs): template = "shortener/home.html" if form.is_valid(): new_url = form.cleaned_data.get("url") + # checks incoming url against three variants x.com*, www.x.com* and http://x.com*. + if "http" in new_url: + new_value = new_url + else: + if "www" in new_url: + new_value = new_url + else: + new_value = 'www.' + new_url + new_value = 'http://' + new_value + obj, created = KirrURL.objects.get_or_create(url=new_url) context = { "object": obj,