0001-api-change-geojson-display-fields-format-22031.patch
tests/test_api.py | ||
---|---|---|
1586 | 1586 |
formdef.name = 'test' |
1587 | 1587 |
formdef.workflow_roles = {'_receiver': role.id} |
1588 | 1588 |
formdef.fields = [ |
1589 |
fields.StringField(id='0', label='foobar', varname='foobar'), |
|
1590 |
] |
|
1589 |
fields.StringField(id='0', label='foobar', varname='foobar', type='string'), |
|
1590 |
fields.FileField(id='1', label='foobar1', varname='file', type='file') |
|
1591 |
] |
|
1591 | 1592 |
formdef.store() |
1592 | 1593 | |
1593 | 1594 |
data_class = formdef.data_class() |
... | ... | |
1601 | 1602 |
# even if there's an anonymse parameter |
1602 | 1603 |
resp = get_app(pub).get(sign_uri('/api/forms/test/geojson?anonymise', user=local_user), status=403) |
1603 | 1604 | |
1605 |
upload = PicklableUpload('test.txt', 'text/plain', 'ascii') |
|
1606 |
upload.receive(['base64me']) |
|
1607 | ||
1604 | 1608 |
for i in range(30): |
1605 | 1609 |
formdata = data_class() |
1606 | 1610 |
date = time.strptime('2014-01-20', '%Y-%m-%d') |
1607 |
formdata.data = {'0': 'FOO BAR'} |
|
1611 |
formdata.data = {'0': 'FOO BAR', '1': upload}
|
|
1608 | 1612 |
formdata.geolocations = {'base': {'lat': 48, 'lon': 2}} |
1609 | 1613 |
formdata.user_id = local_user.id |
1610 | 1614 |
formdata.just_created() |
... | ... | |
1622 | 1626 |
resp = get_app(pub).get(sign_uri('/api/forms/test/geojson', user=local_user)) |
1623 | 1627 |
assert 'features' in resp.json |
1624 | 1628 |
assert len(resp.json['features']) == 10 |
1629 |
display_fields = resp.json['features'][0]['properties']['display_fields'] |
|
1630 |
for field in display_fields: |
|
1631 |
if field['label'] == 'Number': |
|
1632 |
assert field['html_value'] == '1-28' |
|
1633 |
if field['label'] == 'User': |
|
1634 |
assert field['html_value'] == 'Jean Darmette' |
|
1635 |
if field['label'] == 'foobar1': |
|
1636 |
assert field['html_value'] == '<div class="file-field"><a download="test.txt" href="http://example.net/backoffice/management/test/28/?f=1"><span>test.txt</span></a></div>' |
|
1625 | 1637 | |
1626 | 1638 |
# check with a filter |
1627 | 1639 |
resp = get_app(pub).get(sign_uri('/api/forms/test/geojson?filter=done', user=local_user)) |
wcs/backoffice/management.py | ||
---|---|---|
83 | 83 |
for field in fields: |
84 | 84 |
if field.type == 'map': |
85 | 85 |
continue |
86 |
value = formdata.get_field_view_value(field, max_length=60) |
|
87 |
value = value.replace('[download]', formdata_backoffice_url) |
|
88 |
if not value: |
|
86 |
html_value = formdata.get_field_view_value(field, max_length=60) |
|
87 |
html_value = html_value.replace('[download]', formdata_backoffice_url) |
|
88 |
value = formdata.get_field_view_value(field) |
|
89 |
if not html_value and not value: |
|
89 | 90 |
continue |
90 |
display_fields.append((str(htmlescape(field.label)), str(htmlescape(value)))) |
|
91 |
if field.type == 'file': |
|
92 |
value = html_value |
|
93 | ||
94 |
data = {'label': field.label} |
|
95 |
if html_value: |
|
96 |
data['html_value'] = str(html_value) |
|
97 |
else: |
|
98 |
data['value'] = str(value) |
|
99 |
display_fields.append(data) |
|
91 | 100 | |
92 | 101 |
feature = { |
93 | 102 |
'type': 'Feature', |
wcs/qommon/static/js/qommon.map.js | ||
---|---|---|
115 | 115 |
if (feature.properties.display_fields.length > 0) { |
116 | 116 |
var popup = ''; |
117 | 117 |
$.each(feature.properties.display_fields, function(index, field) { |
118 |
popup += '<p class="popup-field"><span class="field-label">' + field[0] + '</span>'; |
|
119 |
popup += '<span class="field-value">' + field[1] + '</span></p>'; |
|
118 |
popup += '<p class="popup-field"><span class="field-label">' + field.label + '</span>'; |
|
119 |
if (field.html_value) { |
|
120 |
popup += '<span class="field-value">' + field.html_value + '</span></p>'; |
|
121 |
} |
|
122 |
else { |
|
123 |
popup += '<span class="field-value">' + encodeURI(field.value) + '</span></p>'; |
|
124 |
} |
|
120 | 125 |
}); |
121 | 126 |
} else { |
122 | 127 |
var popup = '<p class="popup-field formdata-name">' + feature.properties.name + '</p>'; |
123 |
- |