0001-fields-warning-if-prefill-with-email-on-non-Email-fi.patch
tests/test_forms_admin_pages.py | ||
---|---|---|
1263 | 1263 |
assert '<legend>Additional parameters</legend>' in resp.text |
1264 | 1264 |
assert '>Prefill</label>' in resp.text |
1265 | 1265 |
# check the "prefill" field is under additional parameters |
1266 |
assert resp.text.index('<legend>Additional parameters</legend>') < \ |
|
1267 |
resp.text.index('>Prefill</label>') |
|
1266 |
assert resp.text.index('<legend>Additional parameters</legend>') < resp.text.index('>Prefill</label>') |
|
1268 | 1267 | |
1269 | 1268 |
# complete the "prefill" field |
1270 | 1269 |
resp.forms[0]['prefill$type'] = 'String / Template' |
... | ... | |
1281 | 1280 |
assert '<legend>Additional parameters</legend>' in resp.text |
1282 | 1281 |
assert '>Data Source</label>' in resp.text |
1283 | 1282 |
# check the "data source" field is under additional parameters |
1284 |
assert resp.text.index('<legend>Additional parameters</legend>') < \ |
|
1285 |
resp.text.index('>Data Source</label>') |
|
1283 |
assert resp.text.index('<legend>Additional parameters</legend>') < resp.text.index('>Data Source</label>') |
|
1286 | 1284 | |
1287 | 1285 |
# start filling the "data source" field |
1288 | 1286 |
resp.forms[0]['data_source$type'] = 'json' |
... | ... | |
1294 | 1292 |
resp = resp.click('Edit', href='1/') |
1295 | 1293 |
assert resp.text.index('<legend>Additional parameters</legend>') > resp.text.index('>Data Source</label>') |
1296 | 1294 | |
1295 |
resp = app.get('/backoffice/forms/1/fields/1/') |
|
1296 |
assert resp.forms[0]['label'].value == '1st field' |
|
1297 |
resp.forms[0]['prefill$type'] = 'User Field' |
|
1298 |
resp.forms[0]['prefill$value_user'] = 'Email (builtin)' |
|
1299 |
resp = resp.forms[0].submit('submit') |
|
1300 |
assert resp.location == 'http://example.net/backoffice/forms/1/fields/' |
|
1301 |
resp = resp.follow() |
|
1302 |
assert ""1st field" is not an email field. Are you sure you want to prefill it with user's email?" in resp.text |
|
1303 | ||
1304 |
formdef.fields += [fields.EmailField(id='2', label='2nd field')] |
|
1305 |
formdef.store() |
|
1306 |
resp = app.get('/backoffice/forms/1/fields/2/') |
|
1307 |
assert resp.forms[0]['label'].value == '2nd field' |
|
1308 |
resp.forms[0]['prefill$type'] = 'User Field' |
|
1309 |
resp.forms[0]['prefill$value_string'] = 'email' |
|
1310 |
resp = resp.forms[0].submit('submit') |
|
1311 |
assert resp.location == 'http://example.net/backoffice/forms/1/fields/#itemId_2' |
|
1312 |
resp = resp.follow() |
|
1313 |
assert "Are you sure you want to prefill" not in resp.text |
|
1314 | ||
1297 | 1315 | |
1298 | 1316 |
def test_form_prefill_field(pub): |
1299 | 1317 |
create_superuser(pub) |
wcs/admin/fields.py | ||
---|---|---|
16 | 16 |
# You should have received a copy of the GNU General Public License |
17 | 17 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
18 | 18 | |
19 |
import copy |
|
20 | ||
19 | 21 |
from quixote import redirect |
20 | 22 |
from quixote.directory import Directory |
21 | 23 |
from quixote.html import TemplateIO, htmltext, htmlescape |
... | ... | |
23 | 25 |
from wcs.qommon import _ |
24 | 26 |
from wcs.qommon.form import * |
25 | 27 |
from wcs.qommon import errors, misc |
28 |
from wcs.qommon import get_cfg |
|
26 | 29 |
from wcs.qommon.backoffice.menu import html_top |
27 | 30 |
from wcs.qommon.admin.menu import command_icon |
28 | 31 | |
29 | 32 |
from wcs import fields |
30 | 33 |
from wcs.formdef import FormDef |
31 |
from wcs.fields import get_field_types, get_field_options |
|
32 |
import copy |
|
34 |
from wcs.fields import get_field_options |
|
33 | 35 | |
34 | 36 | |
35 | 37 |
class FieldDefPage(Directory): |
... | ... | |
86 | 88 |
r += htmltext('<h2>%s</h2>') % misc.ellipsize(self.field.unhtmled_label, 80) |
87 | 89 |
r += form.render() |
88 | 90 |
return r.getvalue() |
89 |
else: |
|
90 |
self.submit(form) |
|
91 |
if form.get_widget('items') is None and self.field.type == 'item': |
|
92 |
return redirect('.') |
|
93 |
return redirect('../#itemId_%s' % self.field.id) |
|
91 | ||
92 |
self.submit(form) |
|
93 |
if form.get_widget('items') is None and self.field.type == 'item': |
|
94 |
return redirect('.') |
|
95 | ||
96 |
prefill_type = self.field.prefill.get('type') if self.field.prefill else None |
|
97 |
prefill_value = self.field.prefill.get('value') if self.field.prefill else None |
|
98 |
users_cfg = get_cfg('users', {}) |
|
99 |
field_email = users_cfg.get('field_email') or 'email' |
|
100 |
if self.field.key != 'email' and prefill_type == 'user' and prefill_value == field_email: |
|
101 |
get_session().message = ( |
|
102 |
'warning', |
|
103 |
_("\"%s\" is not an email field. Are you sure you want to prefill it with user's email?") |
|
104 |
% self.field.label) |
|
105 |
return redirect('..') |
|
106 | ||
107 |
return redirect('../#itemId_%s' % self.field.id) |
|
94 | 108 | |
95 | 109 |
def submit(self, form): |
96 | 110 |
for f in self.field.get_admin_attributes(): |
97 |
- |