eplips urls overview, decode html urls

This commit is contained in:
j 2011-07-28 21:02:17 +02:00
parent 74ce0b7f94
commit dfeda94e87
4 changed files with 15 additions and 4 deletions

View File

@ -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

View File

@ -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("<script>window.location = '%s';</script>" % (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("<script>window.location = '%s';</script>" % (link.url,));
def default_values(request, link_form=None):
"""

View File

@ -3,7 +3,7 @@
<h2>Recent Links</h2>
<ul>
{% for link in recent_links %}
<li><a href="{{ link.short_url }}">{{ link.url }}</a> (Score: {{ link.usage_count }})
<li><a href="{{ link.short_url }}">{{ link.display_url }}</a> (Score: {{ link.usage_count }})
(<a href="{% url shortener.views.info link.to_base62 %}">Info</a>)</li>
{% endfor %}
</ul>
@ -11,7 +11,7 @@
<h2>Most Popular Links</h2>
<ul>
{% for link in most_popular_links %}
<li><a href="{{ link.short_url }}">{{ link.url }}</a> (Score: {{ link.usage_count }})
<li><a href="{{ link.short_url }}">{{ link.display_url }}</a> (Score: {{ link.usage_count }})
(<a href="{% url shortener.views.info link.to_base62 %}">Info</a>)</li>
{% endfor %}
</ul>

View File

@ -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<base62_id>\w+)$', 'shortener.views.follow'),
(r'^info/(?P<base62_id>\w+)$', 'shortener.views.info'),