Browse Source

Other websites and Covered areas fields are now handled properly

Gu1 11 years ago
parent
commit
0de0aa4aa1

+ 32 - 5
ffdnispdb/forms.py

@@ -60,11 +60,23 @@ TECHNOLOGIES_CHOICES=(
     ('wifi', _('Wi-Fi')),
     ('wifi', _('Wi-Fi')),
 )
 )
 class CoveredArea(InsecureForm):
 class CoveredArea(InsecureForm):
-    area_name    = TextField(_(u'name'), widget=partial(TextInput(), class_='input-medium', placeholder=_(u'Area')))
+    name         = TextField(_(u'name'), widget=partial(TextInput(), class_='input-medium', placeholder=_(u'Area')))
     technologies = SelectMultipleField(_(u'technologies'), choices=TECHNOLOGIES_CHOICES,
     technologies = SelectMultipleField(_(u'technologies'), choices=TECHNOLOGIES_CHOICES,
                                        widget=partial(Select(True), **{'class': 'selectpicker', 'data-title': _(u'Technologies deployed')}))
                                        widget=partial(Select(True), **{'class': 'selectpicker', 'data-title': _(u'Technologies deployed')}))
 #    area          =
 #    area          =
 
 
+    def validate(self, *args, **kwargs):
+        r=super(CoveredArea, self).validate(*args, **kwargs)
+        if bool(self.name.data) != bool(self.technologies.data):
+            self._fields['name'].errors += [_(u'You must fill both fields')]
+            r=False
+        return r
+
+
+class OtherWebsites(InsecureForm):
+    name = TextField(_(u'name'), widget=partial(TextInput(), class_='input-small', placeholder=_(u'Name')))
+    url  = TextField(_(u'url'), widget=partial(TextInput(), class_='input-medium', placeholder=_(u'URL')))
+
 
 
 class ProjectForm(Form):
 class ProjectForm(Form):
     name          = TextField(_(u'full name'), description=[_(u'E.g. French Data Network')],
     name          = TextField(_(u'full name'), description=[_(u'E.g. French Data Network')],
@@ -74,21 +86,25 @@ class ProjectForm(Form):
     description   = TextField(_(u'description'), description=[None, _(u'Short text describing the project')])
     description   = TextField(_(u'description'), description=[None, _(u'Short text describing the project')])
     logo_url      = TextField(_(u'logo url'), validators=[Optional(), URL(require_tld=True)])
     logo_url      = TextField(_(u'logo url'), validators=[Optional(), URL(require_tld=True)])
     website       = TextField(_(u'website'), validators=[Optional(), URL(require_tld=True)])
     website       = TextField(_(u'website'), validators=[Optional(), URL(require_tld=True)])
+    other_websites= FieldList(MyFormField(OtherWebsites, widget=partial(InputListWidget(), class_='formfield')),
+                                          min_entries=1, widget=InputListWidget(),
+                                          description=[None, _(u'Additional websites that you host (e.g. wiki, etherpad...)')])
     contact_email = TextField(_(u'contact email'), validators=[Optional(), Email()],
     contact_email = TextField(_(u'contact email'), validators=[Optional(), Email()],
                               description=[None, _(u'General contact email address')])
                               description=[None, _(u'General contact email address')])
     main_ml       = TextField(_(u'main mailing list'), validators=[Optional(), Email()],
     main_ml       = TextField(_(u'main mailing list'), validators=[Optional(), Email()],
-                              description=[None, u'Address of your main <b>public</b> mailing list'])
+                              description=[None, u'Address of your main mailing list'])
     creation_date = DateField(_(u'creation date'), validators=[Optional()],
     creation_date = DateField(_(u'creation date'), validators=[Optional()],
                               description=[None, u'Date at which the legal structure for your project was created'])
                               description=[None, u'Date at which the legal structure for your project was created'])
     chatrooms     = FieldList(TextField(_(u'chatrooms')), min_entries=1, widget=InputListWidget(),
     chatrooms     = FieldList(TextField(_(u'chatrooms')), min_entries=1, widget=InputListWidget(),
                               description=[None, _(u'In URI form, e.g. <code>irc://irc.isp.net/#isp</code> or '+
                               description=[None, _(u'In URI form, e.g. <code>irc://irc.isp.net/#isp</code> or '+
                                                     '<code>xmpp:isp@chat.isp.net?join</code>')])
                                                     '<code>xmpp:isp@chat.isp.net?join</code>')])
-    covered_areas = FieldList(MyFormField(CoveredArea, widget=partial(InputListWidget(), class_='formfield')), min_entries=1, widget=InputListWidget(),
+    covered_areas = FieldList(MyFormField(CoveredArea, widget=partial(InputListWidget(), class_='formfield')),
+                                          min_entries=1, widget=InputListWidget(),
                                           description=[None, _(u'Descriptive name of the covered areas and technologies deployed')])
                                           description=[None, _(u'Descriptive name of the covered areas and technologies deployed')])
     latitude      = DecimalField(_(u'latitude'), validators=[Optional(), NumberRange(min=-90, max=90)],
     latitude      = DecimalField(_(u'latitude'), validators=[Optional(), NumberRange(min=-90, max=90)],
                              description=[None, _(u'Geographical coordinates of your registered office or usual meeting location.')])
                              description=[None, _(u'Geographical coordinates of your registered office or usual meeting location.')])
     longitude     = DecimalField(_(u'longitude'), validators=[Optional(), NumberRange(min=-180, max=180)])
     longitude     = DecimalField(_(u'longitude'), validators=[Optional(), NumberRange(min=-180, max=180)])
-    step          = SelectField(_(u'step'), choices=[(k, u'%u - %s' % (k, STEPS[k])) for k in STEPS], coerce=int)
+    step          = SelectField(_(u'progress step'), choices=[(k, u'%u - %s' % (k, STEPS[k])) for k in STEPS], coerce=int)
     member_count     = IntegerField(_(u'members'), validators=[Optional(), NumberRange(min=0)],
     member_count     = IntegerField(_(u'members'), validators=[Optional(), NumberRange(min=0)],
                                     description=[None, _('Number of members')])
                                     description=[None, _('Number of members')])
     subscriber_count = IntegerField(_(u'subscribers'), validators=[Optional(), NumberRange(min=0)],
     subscriber_count = IntegerField(_(u'subscribers'), validators=[Optional(), NumberRange(min=0)],
@@ -101,6 +117,11 @@ class ProjectForm(Form):
             r=False
             r=False
         return r
         return r
 
 
+    def validate_covered_areas(self, field):
+        if len(filter(lambda e: e['name'], field.data)) == 0:
+            # not printed, whatever..
+            raise ValidationError(_(u'You must specify at least one area'))
+
     def to_json(self, json=None):
     def to_json(self, json=None):
         if json is None:
         if json is None:
             json={}
             json={}
@@ -119,6 +140,7 @@ class ProjectForm(Form):
         optstr('description', self.description.data)
         optstr('description', self.description.data)
         optstr('logoURL', self.logo_url.data)
         optstr('logoURL', self.logo_url.data)
         optstr('website', self.website.data)
         optstr('website', self.website.data)
+        optstr('otherWebsites', dict(((w['name'], w['url']) for w in self.other_websites.data)))
         optstr('email', self.contact_email.data)
         optstr('email', self.contact_email.data)
         optstr('mainMailingList', self.main_ml.data)
         optstr('mainMailingList', self.main_ml.data)
         optstr('creationDate', self.creation_date.data)
         optstr('creationDate', self.creation_date.data)
@@ -128,11 +150,12 @@ class ProjectForm(Form):
         optlist('chatrooms', filter(bool, self.chatrooms.data)) # remove empty strings
         optlist('chatrooms', filter(bool, self.chatrooms.data)) # remove empty strings
         optstr('coordinates', {'latitude': self.latitude.data, 'longitude': self.longitude.data}
         optstr('coordinates', {'latitude': self.latitude.data, 'longitude': self.longitude.data}
                                 if self.latitude.data else {})
                                 if self.latitude.data else {})
+        optlist('coveredAreas', filter(lambda e: e['name'], self.covered_areas.data))
         return json
         return json
 
 
     @classmethod
     @classmethod
     def edit_json(cls, json):
     def edit_json(cls, json):
-        obj=type('abject', (object,), {})
+        obj=type('abject', (object,), {})()
         def set_attr(attr, itemk=None, d=json):
         def set_attr(attr, itemk=None, d=json):
             if itemk is None:
             if itemk is None:
                 itemk=attr
                 itemk=attr
@@ -153,8 +176,12 @@ class ProjectForm(Form):
         if 'coordinates' in json:
         if 'coordinates' in json:
             set_attr('latitude', d=json['coordinates'])
             set_attr('latitude', d=json['coordinates'])
             set_attr('longitude', d=json['coordinates'])
             set_attr('longitude', d=json['coordinates'])
+        if 'otherWebsites' in json:
+            setattr(obj, 'other_websites', [{'name': n, 'url': w} for n, w in json['otherWebsites'].iteritems()])
+        set_attr('covered_areas', 'coveredAreas')
         return cls(obj=obj)
         return cls(obj=obj)
 
 
 
 
 class ProjectJSONForm(Form):
 class ProjectJSONForm(Form):
     url = TextField(_(u'link url'), validators=[Optional(), URL(require_tld=True)])
     url = TextField(_(u'link url'), validators=[Optional(), URL(require_tld=True)])
+

+ 10 - 2
ffdnispdb/templates/project_detail.html

@@ -32,12 +32,20 @@
         {%- endif %}
         {%- endif %}
         {%- if project.coveredAreas %}
         {%- if project.coveredAreas %}
         {{ field(_("covered areas")) }}
         {{ field(_("covered areas")) }}
-          <dd>{{ project.coveredAreas }}</dd>
+          {% for a in project.coveredAreas -%}
+          <dd>{{ a.name }} ({{ a.technologies|join(',') }})</dd>
+          {%- endfor -%}
         {%- endif %}
         {%- endif %}
-        {%- if project.website%}
+        {%- if project.website %}
         {{ field(_("website")) }}
         {{ field(_("website")) }}
           <dd><a href="{{ project.website }}">{{ project.website }}</a></dd>
           <dd><a href="{{ project.website }}">{{ project.website }}</a></dd>
         {%- endif %}
         {%- endif %}
+        {%- if project.otherWebsites %}
+        {{ field(_("other websites")) }}
+          {% for n, w in project.otherWebsites.iteritems() -%}
+          <dd>{{ n }}: <a href="{{ w }}">{{ w }}</a></dd>
+          {%- endfor -%}
+        {%- endif %}
         {%- if project.email %}
         {%- if project.email %}
         {{ field(_("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>
           <dd>{% if project.email %}<a href="mailto:{{ project.email }}"><i class="icon-envelope"></i> {{ project.email }}</a>{% else %}<em>None given</em>{% endif %}</dd>

+ 15 - 2
ffdnispdb/templates/project_form.html

@@ -12,13 +12,27 @@
         {{ fm.render_field(form.description) }}
         {{ fm.render_field(form.description) }}
         {{ fm.render_field(form.logo_url) }}
         {{ fm.render_field(form.logo_url) }}
         {{ fm.render_field(form.website) }}
         {{ fm.render_field(form.website) }}
+        <div class="control-group{% if form.other_websites.errors %} error{% endif %}">
+          <label class="control-label" for="coordinates">{{ form.other_websites.label.text }}</label>
+          <div class="controls">
+            <ul class="fieldlist">
+              {% for c in form.other_websites -%}
+              <li>{{ c() }}{{ fm.display_errors(c.flattened_errors) }}</li>
+              {%- endfor %}
+            </ul>
+            {% if form.other_websites.description.1 -%}
+            <span class="help-block">{{ form.other_websites.description.1|safe }}</span>
+            {%- endif %}
+          </div>
+        </div>
         {{ fm.render_field(form.contact_email) }}
         {{ fm.render_field(form.contact_email) }}
         {{ fm.render_field(form.main_ml) }}
         {{ fm.render_field(form.main_ml) }}
         {{ fm.render_field(form.creation_date) }}
         {{ fm.render_field(form.creation_date) }}
+        {{ fm.render_field(form.step) }}
         {{ fm.render_field(form.member_count, class_="input-small") }}
         {{ fm.render_field(form.member_count, class_="input-small") }}
         {{ fm.render_field(form.subscriber_count, class_="input-small") }}
         {{ fm.render_field(form.subscriber_count, class_="input-small") }}
         {{ fm.render_field(form.chatrooms, class="fieldlist") }}
         {{ fm.render_field(form.chatrooms, class="fieldlist") }}
-        <div class="control-group{% if form.covered_areas.errors %} error{% endif %}">
+        <div class="control-group required{% if form.covered_areas.errors %} error{% endif %}">
           <label class="control-label" for="coordinates">{{ form.covered_areas.label.text }}</label>
           <label class="control-label" for="coordinates">{{ form.covered_areas.label.text }}</label>
           <div class="controls">
           <div class="controls">
             <ul class="fieldlist">
             <ul class="fieldlist">
@@ -45,7 +59,6 @@
             {%- endif %}
             {%- endif %}
           </div>
           </div>
         </div>
         </div>
-        {{ fm.render_field(form.step) }}
         <div class="form-actions">
         <div class="form-actions">
           <input type="submit" class="btn btn-primary" value="{{ _("Submit") }}" />
           <input type="submit" class="btn btn-primary" value="{{ _("Submit") }}" />
           <input type="reset" class="btn" value="{{ _("Cancel") }}" />
           <input type="reset" class="btn" value="{{ _("Cancel") }}" />