From e108db8a83b40ff5ed9a971ff951d66180ddd11b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 16 2015 14:45:05 +0000 Subject: Create a hasattr jinja filter to go around broken pygit2 --- diff --git a/progit/__init__.py b/progit/__init__.py index 7072582..542a981 100644 --- a/progit/__init__.py +++ b/progit/__init__.py @@ -208,6 +208,14 @@ def set_session(): flask.session.permanent = True +@APP.template_filter('hasattr') +def jinja_hasattr(obj, string): + """ Template filter checking if the provided object at the provided + string as attribute + """ + return hasattr(obj, string) + + @APP.template_filter('lastcommit_date') def lastcommit_date_filter(repo): """ Template filter returning the last commit date of the provided repo. diff --git a/progit/templates/pull_request.html b/progit/templates/pull_request.html index 580e651..3ffd3bc 100644 --- a/progit/templates/pull_request.html +++ b/progit/templates/pull_request.html @@ -138,7 +138,11 @@ identifier=branch_from, filename=patch.new_file_path) }}" {% endif %} + {% if patch |hasattr('new_id') %} title="View file as of {{ patch.new_id|short }}">View + {% else %} + title="View file as of {{ patch.new_oid|short }}">View + {% endif %}