Parcourir la source

Improve project list & detail pages, add helper methods to ISP model

Gu1 il y a 11 ans
Parent
commit
7b90f070bb

+ 1 - 2
ffdnispdb/forms.py

@@ -1,7 +1,6 @@
 from functools import partial
 import itertools
 import urlparse
-from datetime import datetime
 from flask.ext.wtf import Form
 from wtforms import Form as InsecureForm
 from wtforms import (TextField, DateField, DecimalField, IntegerField, SelectField,
@@ -173,7 +172,7 @@ class ProjectForm(Form):
         set_attr('main_ml', 'mainMailingList')
         set_attr('creation_date', 'creationDate')
         if hasattr(obj, 'creation_date'):
-            obj.creation_date=datetime.strptime(obj.creation_date, '%Y-%m-%d')
+            obj.creation_date=ISP.str2date(obj.creation_date)
         set_attr('step', 'progressStatus')
         set_attr('member_count', 'memberCount')
         set_attr('subscriber_count', 'subscriberCount')

+ 19 - 0
ffdnispdb/models.py

@@ -3,6 +3,7 @@
 from decimal import Decimal
 import json
 from . import db
+from datetime import datetime
 from sqlalchemy.types import TypeDecorator, VARCHAR
 from sqlalchemy.ext.mutable import MutableDict
 
@@ -54,6 +55,24 @@ class ISP(db.Model):
         super(ISP, self).__init__(*args, **kwargs)
         self.json={}
 
+    def covered_areas_names(self):
+        return [c['name'] for c in self.json.get('coveredAreas', [])]
+
+    @staticmethod
+    def str2date(_str):
+        d=None
+        try:
+            d=datetime.strptime(_str, '%Y-%m-%d')
+        except ValueError:
+            pass
+
+        if d is None:
+            try:
+                d=datetime.strptime(_str, '%Y-%m')
+            except ValueError:
+                pass
+        return d
+
     def __repr__(self):
         return '<ISP %r>' % (self.shortname if self.shortname else self.name,)
 

+ 5 - 0
ffdnispdb/static/css/style.css

@@ -91,6 +91,11 @@ input#search-input {
     }
 }
 
+.project-list .btn-small {
+    padding-right: 6px;
+    padding-left: 6px;
+}
+
 .project-choice {
     padding: 30px;
     background-color: #dddddd;

+ 10 - 0
ffdnispdb/templates/project_detail.html

@@ -58,6 +58,16 @@
         {{ field(_("step")) }}
           <dd>{{ project.progressStatus|step_to_label|safe }}</dd>
         {%- endif %}
+        {%- if project_row.is_ffdn_member %}
+        <dt>{{ _("FFDN Member") }}</dt>
+          <dd>
+          {%- if project.ffdnMemberSince -%}
+            {% trans date=project_row.str2date(project.ffdnMemberSince)|dateformat('medium') %}Yes, since {{ date }}{% endtrans %}
+          {%- else -%}
+            {{ _("Yes") }}
+          {%- endif -%}
+          </dd>
+        {%- endif %}
         {%- if project.memberCount %}
         {{ field(_("members")) }}
           <dd>{{ project.memberCount }}</dd>

+ 10 - 8
ffdnispdb/templates/project_list.html

@@ -2,7 +2,7 @@
 {% block page_title %}{{ _("Project List") }}{% endblock %}
 {% block body %}
 <div>
-<table class="table table-condensed table-striped table-hover">
+<table class="project-list table table-condensed table-striped table-hover">
   <thead>
     <tr>
       <th>{{ _("Name") }}</th>
@@ -14,13 +14,15 @@
   <tbody>
     {% for project in projects -%}
     <tr>
-      <td>{% autoescape false %}{{ project.isFFDNMember | member_to_label }}{% endautoescape %} &nbsp;
-        <a href="{{ url_for('project', projectid=project.id) }}">{{ project.name }}</a></td>
-      <td>{{ project.zone }}</td>
-      {% autoescape false -%}
-      <td>{{ project.json.progressStatus|step_to_label }}</td>
-      {%- endautoescape %}
-      <td><a class="pull-right btn btn-small" href="{{ url_for('project', projectid=project.id) }}"><i class="icon-search"></i></a>
+      <td><a href="{{ url_for('project', projectid=project.id) }}">{{ project.name }}</a></td>
+      <td>{{ ', '.join(project.covered_areas_names())|truncate(30) }}</td>
+      <td>
+        {{ project.json.progressStatus|step_to_label|safe }}
+        {%- if project.is_ffdn_member %}
+        &thinsp;<a href="#" rel="tooltip" data-placement="right" title="{{ _("Member of the FDN Federation") }}"><span class="label label-info">FFDN</span></a>
+        {%- endif %}
+      </td>
+      <td><a class="pull-right btn btn-small" title="{{ _("Examine") }}" href="{{ url_for('project', projectid=project.id) }}"><i class="icon-search"></i></a>
     </tr>
     {% endfor -%}
   </tbody>