Commits

Benoît Allard committed dd1846f

web: Add a link filling information to the repositories page

Comments (0)

Files changed (4)

web/templates/repositories.html

 {% set title="Repositories" %}
 {% block items %}
 {% for repo in repositories %}
+{% set curfil = filling[loop.index - 1] %}
   <li class="repository">
-    {{ macros.render_repository(repo)|safe }} (<span class="badge badge-info">{{ repo.changesets|count }}</span> changesets)
+    {{ macros.render_repository(repo)|safe }} contains <span class="badge badge-info">{{ repo.changesets|count }}</span> changesets,
+    <span class="badge {{ curfil | percent_badge }}">
+      {{ '%0.02f'|format(curfil) }}
+    </span>
   </li>
 {% endfor %}
 {% endblock %}
     resp = make_response(render_template('redirect.txt'), code)
     resp.headers['Location'] = location
     return resp
+
+def percent_badge(value):
+    d = ((5., 'badge-important'),
+         (20., 'badge-warning'),
+         (50., 'badge-info'),
+         (100., 'badge-success'),)
+    for k, v in d:
+        if int(value) <= k:
+            return v
+    return ''
+
 @views.route('/binaries/', defaults={'page': 1})
 @views.route('/binaries/page/<int:page>')
 def listbinaries(page):
-    query = request.dbsession.query(models.Binary)
+    query = request.dbsession.query(models.Binary) \
+                             .order_by(models.Binary.id.desc())
     items = query.limit(PER_PAGE).offset((page - 1) * PER_PAGE).all()
     if not items and page != 1:
         abort(404)
     if not items and page != 1:
         abort(404)
     pgnation = Pagination(page, PER_PAGE, query.count())
+    filling = []
+    for repository in items:
+        count = request.dbsession.query(models.Changeset) \
+                                 .filter_by(repository=repository) \
+                                 .filter(models.Changeset.issues.any()) \
+                                 .count()
+        total = len(repository.changesets)
+        if total == 0:
+            filling.append(100.)
+        else:
+            filling.append((count * 100.) / total)
     return render_template('repositories.html',
                            pagination=pgnation,
                            repositories=items,
+                           filling=filling,
                            )
 
 @views.route('/modules/', defaults={'page': 1})
         url_for_issue=url_for_issue,
         url_for_binary=url_for_binary,
     )
+    app.jinja_env.filters.update(
+        percent_badge = percent_badge,
+    )
 
     return app