Browse Source

Handle more fields, hack on JSONEncodedDict to handle Decimal()

Gu1 11 years ago
parent
commit
6f0f91c8a6

+ 13 - 3
ffdnispdb/forms.py

@@ -123,17 +123,21 @@ class ProjectForm(Form):
         optstr('mainMailingList', self.main_ml.data)
         optstr('creationDate', self.creation_date.data)
         optstr('progressStatus', self.step.data)
+        optstr('memberCount', self.member_count.data)
+        optstr('subscriberCount', self.subscriber_count.data)
         optlist('chatrooms', filter(bool, self.chatrooms.data)) # remove empty strings
+        optstr('coordinates', {'latitude': self.latitude.data, 'longitude': self.longitude.data}
+                                if self.latitude.data else {})
         return json
 
     @classmethod
     def edit_json(cls, json):
         obj=type('abject', (object,), {})
-        def set_attr(attr, itemk=None):
+        def set_attr(attr, itemk=None, d=json):
             if itemk is None:
                 itemk=attr
-            if itemk in json:
-                setattr(obj, attr, json[itemk])
+            if itemk in d:
+                setattr(obj, attr, d[itemk])
         set_attr('name')
         set_attr('shortname')
         set_attr('description')
@@ -143,6 +147,12 @@ class ProjectForm(Form):
         set_attr('main_ml', 'mainMailingList')
         set_attr('creation_date', 'creationDate')
         set_attr('step', 'progressStatus')
+        set_attr('member_count', 'memberCount')
+        set_attr('subscriber_count', 'subscriberCount')
+        set_attr('chatrooms', 'chatrooms')
+        if 'coordinates' in json:
+            set_attr('latitude', d=json['coordinates'])
+            set_attr('longitude', d=json['coordinates'])
         return cls(obj=obj)
 
 

+ 15 - 1
ffdnispdb/models.py

@@ -1,11 +1,25 @@
 # -*- coding: utf-8 -*-
 
+from decimal import Decimal
 import json
 from . import db
 from sqlalchemy.types import TypeDecorator, VARCHAR
 from sqlalchemy.ext.mutable import MutableDict
 
 
+class fakefloat(float):
+    def __init__(self, value):
+        self._value = value
+    def __repr__(self):
+        return str(self._value)
+
+def defaultencode(o):
+    if isinstance(o, Decimal):
+        # Subclass float with custom repr?
+        return fakefloat(o)
+    raise TypeError(repr(o) + " is not JSON serializable")
+
+
 class JSONEncodedDict(TypeDecorator):
     "Represents an immutable structure as a json-encoded string."
 
@@ -13,7 +27,7 @@ class JSONEncodedDict(TypeDecorator):
 
     def process_bind_param(self, value, dialect):
         if value is not None:
-            value = json.dumps(value)
+            value = json.dumps(value, default=defaultencode)
         return value
 
     def process_result_value(self, value, dialect):

+ 6 - 1
ffdnispdb/static/css/style.css

@@ -13,10 +13,15 @@
     margin-top: 25px;
 }
 
-#main-container h2.page-header {
+#main-container .page-header {
     margin-top: 0;
 }
 
+#main-container .page-header h2 {
+    margin: 0;
+    display: inline;
+}
+
 input#search-input {
     position: relative;
     padding-left: 23px;

+ 11 - 7
ffdnispdb/templates/layout.html

@@ -1,6 +1,6 @@
 {% macro menu_item(name, endpoint=None) -%}
-<li{% if request.endpoint == endpoint %} class="active"{% endif %}><a href="{{ url_for(endpoint) if endpoint else "#" }}">{{ _(name) }}</a></li>
-{% endmacro %}
+<li{% if request.endpoint == endpoint %} class="active"{% endif %}><a href="{{ url_for(endpoint) if endpoint else "#" }}">{{ name }}</a></li>
+{%- endmacro %}
 <!doctype html>
 <html lang="fr">
   <head>
@@ -33,10 +33,10 @@
           <input type="text" id="search-input" class="search-query input-medium" placeholder="{{ _("Search") }}"/>
         </form>
         <ul class="nav pull-right">
-          {{ menu_item('Home', 'home') }}
-          {{ menu_item('Project List', 'project_list') }}
-          {{ menu_item('Schema') }}
-          {{ menu_item('API') }}
+          {{ menu_item(_("Home"), 'home') }}
+          {{ menu_item(_("Project List"), 'project_list') }}
+          {{ menu_item(_("Schema")) }}
+          {{ menu_item(_("API")) }}
           <li class="divider-vertical"></li>
         </ul>
       </div>
@@ -56,7 +56,11 @@
   {% endif %}
 {% endwith %}
 {%- block container %}
-<h2 class="page-header">{% block page_title %}{% endblock %}</h2>
+<div class="page-header">
+  {% block page_header -%}
+  <h2>{% block page_title %}{% endblock %}</h2>
+  {%- endblock %}
+</div>
 <div class="container">
 {% block body %}{% endblock %}
 </div>

+ 63 - 31
ffdnispdb/templates/project_detail.html

@@ -1,42 +1,74 @@
 {% extends "layout.html" %}
+{% macro field(name) -%}
+<dt>{{ name|capitalize }}</dt>
+{%- endmacro %}
 {% block page_title -%}
 {% trans project_name=project.name -%}
 <small>Project:</small> {{ project_name }}
 {%- endtrans %}
 {%- endblock %}
+{% block page_header %}
+    {{ super() }}
+    <a class="btn btn-success btn-small pull-right" style="margin: 15px 10px 0;" href="{{ url_for('edit_project', projectid=project_row.id) }}"><i class="icon-edit icon-white"></i> {{ _("Edit") }}</a>
+{% endblock %}
 {% block body %}
-  <div class="pull-right">
-    <div class="text-right">
-      <a class="btn btn-success btn-small" href="{{ url_for('edit_project', projectid=project_row.id) }}"><i class="icon-edit icon-white"></i> {{ _("Edit") }}</a>
-    </div>
+  <div class="row-fluid">
+    <div class="pull-right">
 {%- if project.logoURL %}
-    <a href="{{ project.website }}"><img alt="{{ project.name }}" src="{{ project.logoURL }}" style="max-width: 300px;" /></a>
+      <a href="{{ project.website }}"><img alt="{{ project.name }}" src="{{ project.logoURL }}" style="max-width: 300px; margin: 30px 30px 0;" /></a>
 {%- endif %}
+    </div>
+    <div class="span6 offset1">
+      <dl class="dl-horizontal">
+        {{ field(_("name")) }}
+          <dd>{{ project.name }}</dd>
+        {%- if project.shortname %}
+        {{ field(_("short name")) }}
+          <dd>{{ project.shortname }}</dd>
+        {%- endif %}
+        {%- if project.description %}
+        {{ field(_("description")) }}
+          <dd>{{ project.description }}</dd>
+        {%- endif %}
+        {%- if project.coveredAreas %}
+        {{ field(_("covered areas")) }}
+          <dd>{{ project.coveredAreas }}</dd>
+        {%- endif %}
+        {%- if project.website%}
+        {{ field(_("website")) }}
+          <dd><a href="{{ project.website }}">{{ project.website }}</a></dd>
+        {%- endif %}
+        {%- if project.email %}
+        {{ field(_("email")) }}
+          <dd>{% if project.email %}<a href="mailto:{{ project.email }}"><i class="icon-envelope"></i> {{ project.email }}</a>{% else %}<em>None given</em>{% endif %}</dd>
+        {%- endif %}
+        {%- if project.mainMailingList %}
+        {{ field(_("main mailing list")) }}
+          <dd>{% if project.mainMailingList %}<a href="mailto:{{ project.mainMailingList }}"><i class="icon-envelope"></i> {{ project.mainMailingList }}</a>{% else %}<em>None given</em>{% endif %}</dd>
+        {%- endif %}
+        {%- if project.progressStatus %}
+        {{ field(_("step")) }}
+          <dd>{{ project.progressStatus|step_to_label|safe }}</dd>
+        {%- endif %}
+        {%- if project.memberCount %}
+        {{ field(_("members")) }}
+          <dd>{{ project.memberCount }}</dd>
+        {%- endif %}
+        {%- if project.subscriberCount %}
+        {{ field(_("subscribers")) }}
+          <dd>{{ project.subscriberCount }}</dd>
+        {%- endif %}
+        {%- if project.chatrooms %}
+        {{ field(_("chatrooms")) }}
+          {% for c in project.chatrooms -%}
+          <dd><code>{{ c }}</code></dd>
+          {%- endfor -%}
+        {%- endif %}
+        {%- if project.coordinates %}
+        {{ field(_("coordinates")) }}
+          <dd>{{ project.coordinates.latitude }} {{ project.coordinates.longitude }}</dd>
+        {%- endif %}
+      </dl>
+    </div>
   </div>
-  <dl class="dl-horizontal">
-    <dt>{{ _("name")|capitalize }}</dt>
-      <dd>{{ project.name }}</dd>
-    <dt>{{ _("short name")|capitalize }}</dt>
-      <dd>{{ project.shortname }}</dd>
-    <dt>{{ _("description")|capitalize }}</dt>
-      <dd>{{ project.description|default(_("<em>None yet</em>")) }}</dd>
-    <dt>{{ _("covered areas")|capitalize }}</dt>
-      <dd>{{ project.zone|default(_("<em>None yet</em>")) }}</dd>
-    <dt>{{ _("website")|capitalize }}</dt>
-      <dd>{% if project.website %}<a href="{{ project.website }}">{{ project.website }}</a>{% else %}<em>None</em>{% endif %}</dd>
-    <dt>{{ _("email")|capitalize }}</dt>
-      <dd>{% if project.email %}<a href="mailto:{{ project.email }}">{{ project.email }}</a>{% else %}<em>None given</em>{% endif %}</dd>
-    <dt>{{ _("main mailing list")|capitalize }}</dt>
-      <dd>{% if project.mainMailingList %}<a href="mailto:{{ project.mainMailingList }}">{{ project.mainMailingList }}</a>{% else %}<em>None given</em>{% endif %}</dd>
-    <dt>{{ _("chatrooms")|capitalize }}</dt>
-      {% for c in project.chatrooms -%}
-      <dd><code>{{ c }}</code></dd>
-      {%- else -%}
-      <dd><em>None</em></dd>
-      {%- endfor -%}
-    {% autoescape false %}
-    <dt>{{ _("step")|capitalize }}</dt>
-      <dd>{{ project.progressStatus | step_to_label }}</dd>
-    {% endautoescape %}
-  </dl>
 {% endblock %}