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 | ||
1608 |
foobar = '<font color="red">FOO BAR</font>' |
|
1609 |
username = '<font color="red">Jean Darmette</font>' |
|
1610 | ||
1611 |
data = {'0': foobar, '1': upload} |
|
1612 |
local_user.name = username |
|
1613 |
local_user.store() |
|
1604 | 1614 |
for i in range(30): |
1605 | 1615 |
formdata = data_class() |
1606 | 1616 |
date = time.strptime('2014-01-20', '%Y-%m-%d') |
1607 |
formdata.data = {'0': 'FOO BAR'} |
|
1608 | 1617 |
formdata.geolocations = {'base': {'lat': 48, 'lon': 2}} |
1618 |
formdata.data = data |
|
1609 | 1619 |
formdata.user_id = local_user.id |
1610 | 1620 |
formdata.just_created() |
1611 | 1621 |
if i%3 == 0: |
... | ... | |
1622 | 1632 |
resp = get_app(pub).get(sign_uri('/api/forms/test/geojson', user=local_user)) |
1623 | 1633 |
assert 'features' in resp.json |
1624 | 1634 |
assert len(resp.json['features']) == 10 |
1635 |
display_fields = resp.json['features'][0]['properties']['display_fields'] |
|
1636 |
for field in display_fields: |
|
1637 |
if field['label'] == 'Number': |
|
1638 |
assert field['html_value'] == '1-28' |
|
1639 |
assert field['value'] == '1-28' |
|
1640 |
if field['label'] == 'User Label': |
|
1641 |
assert field['value'] == username |
|
1642 |
assert field['html_value'] == "<font color="red">Jean Darmette</font>" |
|
1643 |
if field['label'] == 'foobar': |
|
1644 |
assert field['value'] == foobar |
|
1645 |
assert field['html_value'] == "<font color="red">FOO BAR</font>" |
|
1646 |
if field['label'] == 'foobar1': |
|
1647 |
assert field['value'] == "test.txt" |
|
1648 |
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 | 1649 | |
1626 | 1650 |
# check with a filter |
1627 | 1651 |
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 | ||
92 |
if field.type == 'file': |
|
93 |
value = value.base_filename |
|
94 |
html_value = str(html_value) |
|
95 |
else: |
|
96 |
value = str(value) |
|
97 |
html_value = str(htmlescape(html_value)) |
|
98 | ||
99 |
display_fields.append({ |
|
100 |
'label': field.label, |
|
101 |
'value': value, |
|
102 |
'html_value': html_value |
|
103 |
}) |
|
91 | 104 | |
92 | 105 |
feature = { |
93 | 106 |
'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_field = $('<p class="popup-field">'); |
|
119 |
$f_label = $('<span class="field-label">').html(field.label); |
|
120 |
$popup_field.append($f_label); |
|
121 |
$f_value = $('<span class="field-value">') |
|
122 |
if (field.html_value) { |
|
123 |
$f_value.html(field.html_value); |
|
124 |
} |
|
125 |
else { |
|
126 |
$f_value.text(field.value); |
|
127 |
} |
|
128 |
$popup_field.append($f_value); |
|
129 |
popup += $popup_field[0].outerHTML |
|
120 | 130 |
}); |
121 | 131 |
} else { |
122 | 132 |
var popup = '<p class="popup-field formdata-name">' + feature.properties.name + '</p>'; |
123 |
- |