From c433c2c1e8ea81fd96eb97898457cc923b972c59 Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Fri, 26 Aug 2016 16:45:56 +0200 Subject: [PATCH] If redirect detected, button with final uri --- digimarks.py | 12 ++++++++++++ templates/bookmarks.html | 2 +- templates/edit.html | 17 ++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/digimarks.py b/digimarks.py index 7cb70c5..7d323b2 100644 --- a/digimarks.py +++ b/digimarks.py @@ -106,6 +106,7 @@ class Bookmark(db.Model): # Status code: 200 is OK, 404 is not found, for example (showing an error) http_status = IntegerField(default=200) + redirect_uri = None created_date = DateTimeField(default=datetime.datetime.now) modified_date = DateTimeField(null=True) @@ -191,6 +192,17 @@ class Bookmark(db.Model): tags_clean = clean_tags(tags_split) self.tags = ','.join(tags_clean) + def get_redirect_uri(self): + if self.redirect_uri: + return self.redirect_uri + if self.http_status == 301 or self.http_status == 302: + result = requests.head(self.url, allow_redirects=True) + self.http_status = result.status_code + self.redirect_uri = result.url + return result.url + else: + return None + @classmethod def strip_url_params(cls, url): parsed = urlparse(url) diff --git a/templates/bookmarks.html b/templates/bookmarks.html index c51f407..6f031d7 100644 --- a/templates/bookmarks.html +++ b/templates/bookmarks.html @@ -82,7 +82,7 @@ {% if bookmark.favicon %}
{% endif %} - {% if bookmark.http_status != 200 %} + {% if bookmark.http_status != 200 and bookmark.http_status != 304 %}
report_problem
{% endif %} {% if bookmark.starred == True %} diff --git a/templates/edit.html b/templates/edit.html index 01fc389..750b9d7 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -3,13 +3,15 @@ {% block pageheader %}{{ action }}{% endblock %} {% block pagecontent %} -{% if bookmark.http_status != 200 %} +{% if bookmark.http_status != 200 and bookmark.http_status != 304 %}
{% if bookmark.http_status == 404 %} report_problem  URL not found (404), broken/outdated link? + {% elif bookmark.http_status == 302 %} + report_problem  HTTP status (302), moved temporarily {% else %} report_problem  HTTP status {{ bookmark.http_status }} {% endif %} @@ -48,6 +50,19 @@ turned_in + {% if bookmark.get_redirect_uri() %} + + + {% endif %}