Commits

Benoît Allard committed 19f1f22

Add url rendering for binaries

Comments (0)

Files changed (4)

web/templates/macros.j2

   {% endif %}
 {% endmacro %}
 
+{% macro render_binary(binary) %}
+  {% set url = url_for_binary(binary) %}
+  {% if url %}
+   <a href="{{ url }}" class="external">{{ binary.module.name }} - {{ binary.build.number }}</a>
+  {% else %}
+   {{ binary.module.name }} - {{ binary.build.number }}
+  {% endif %}
+{% endmacro %}
+
 {% macro diff_repo(repopath, repo, optparams) %}
 {% set oldch, newch, issuesmin, issuesplus, num_annon = repo %}
 {% if oldch != newch %}

web/templates/releases.html

     <ul>
       {% for binary in release.binaries %}
       <li>
-        {{ binary.module.name }} - {{ binary.build.number }}
+        {{ macros.render_binary(binary)|safe }}
       </li>
       {% endfor %}
     </ul>
         return None
     if 'issue' not in conf['links']:
         return None
-    if not conf['links']['issue']:
-        return None
     for choice in conf['links']['issue']:
         regex = choice['re']
         res = re.match(regex, issue.ref)
         return choice['url'] % dict
     return None
 
+def url_for_binary(binary):
+    conf = current_app.config
+    links = conf.get('links', {})
+    binaries = links.get('binary', [])
+    for choice in binaries:
+        regex = choice.get('re', '(?P<module>.+)')
+        res = re.match(regex, binary.module.name)
+        if res is None:
+            # try next one
+            continue
+        dict = setdefault(res.groupdict(), choice.get('default', {}))
+        if '%(buildnumber)s' in choice['url']:
+            dict['buildnumber'] = binary.build.number
+        # that's risky !
+        return choice['url'] % dict
+    return None
+    
 def request_wants_(mimetype):
     """from http://flask.pocoo.org/snippets/45/"""
     best = request.accept_mimetypes.best_match([mimetype, 'text/html'])
         url_for_repository=url_for_repository,
         url_for_changeset=url_for_changeset,
         url_for_issue=url_for_issue,
+        url_for_binary=url_for_binary,
     )
 
     return app