eplips urls overview, decode html urls
This commit is contained in:
parent
74ce0b7f94
commit
dfeda94e87
|
@ -51,6 +51,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
|
||||
|
||||
|
|
|
@ -23,6 +23,11 @@ def follow(request, base62_id):
|
|||
link = get_object_or_404(Link, pk = key)
|
||||
link.usage_count += 1
|
||||
link.save()
|
||||
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):
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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'),
|
||||
|
|
Loading…
Reference in New Issue
Block a user