From dfeda94e8754b18fb975068ed20b00e4c6798b36 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 28 Jul 2011 21:02:17 +0200 Subject: [PATCH] eplips urls overview, decode html urls --- urlweb/shortener/models.py | 6 ++++++ urlweb/shortener/views.py | 7 ++++++- urlweb/templates/shortener/index.html | 4 ++-- urlweb/urls.py | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/urlweb/shortener/models.py b/urlweb/shortener/models.py index fcad23e..87047bf 100644 --- a/urlweb/shortener/models.py +++ b/urlweb/shortener/models.py @@ -50,6 +50,12 @@ class Link(models.Model): def short_url(self): return settings.SITE_BASE_URL + self.to_base62() + + def display_url(self): + url = self.url[:100] + if len(self.url) > 100: + url += '...' + return url def __unicode__(self): return self.to_base62() + ' : ' + self.url diff --git a/urlweb/shortener/views.py b/urlweb/shortener/views.py index 6141ff1..54e9038 100644 --- a/urlweb/shortener/views.py +++ b/urlweb/shortener/views.py @@ -23,7 +23,12 @@ def follow(request, base62_id): link = get_object_or_404(Link, pk = key) link.usage_count += 1 link.save() - return HttpResponse("" % (link.url,)); + if link.url.startswith('data:text/html;charset=utf-8;base64,'): + html = link.url[len('data:text/html;charset=utf-8;base64,'):] + html = html.decode('base64') + return HttpResponse(html); + else: + return HttpResponse("" % (link.url,)); def default_values(request, link_form=None): """ diff --git a/urlweb/templates/shortener/index.html b/urlweb/templates/shortener/index.html index c1bae4c..2611928 100644 --- a/urlweb/templates/shortener/index.html +++ b/urlweb/templates/shortener/index.html @@ -3,7 +3,7 @@

Recent Links

@@ -11,7 +11,7 @@

Most Popular Links

diff --git a/urlweb/urls.py b/urlweb/urls.py index 272634a..a7b2145 100644 --- a/urlweb/urls.py +++ b/urlweb/urls.py @@ -7,7 +7,7 @@ admin.autodiscover() urlpatterns = patterns( '', (r'^$', 'shortener.views.index'), - (r'^admin/(.*)', admin.site.root), + (r'^admin/', include(admin.site.urls)), (r'^submit/$', 'shortener.views.submit'), (r'^(?P\w+)$', 'shortener.views.follow'), (r'^info/(?P\w+)$', 'shortener.views.info'),