Browse Source

eplips urls overview, decode html urls

master
j 13 years ago
parent
commit
dfeda94e87
  1. 6
      urlweb/shortener/models.py
  2. 7
      urlweb/shortener/views.py
  3. 4
      urlweb/templates/shortener/index.html
  4. 2
      urlweb/urls.py

6
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

7
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("<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):
"""

4
urlweb/templates/shortener/index.html

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

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

Loading…
Cancel
Save