0001-admin-make-it-possible-to-edit-named-data-sources-sl.patch
tests/test_admin_pages.py | ||
---|---|---|
2369 | 2369 |
resp = resp.follow() |
2370 | 2370 |
assert NamedDataSource.count() == 0 |
2371 | 2371 | |
2372 |
def test_data_sources_edit_slug(pub): |
|
2373 |
create_superuser(pub) |
|
2374 |
NamedDataSource.wipe() |
|
2375 |
data_source = NamedDataSource(name='foobar') |
|
2376 |
data_source.data_source = {'type': 'formula', 'value': '[]'} |
|
2377 |
data_source.store() |
|
2378 |
assert NamedDataSource.get(1).slug == 'foobar' |
|
2379 | ||
2380 |
FormDef.wipe() |
|
2381 |
app = login(get_app(pub)) |
|
2382 | ||
2383 |
resp = app.get('/backoffice/settings/data-sources/1/') |
|
2384 |
resp = resp.click(href='edit') |
|
2385 |
assert resp.forms[0]['name'].value == 'foobar' |
|
2386 |
resp.forms[0]['slug'] = 'foo_bar' |
|
2387 |
resp = resp.forms[0].submit('submit') |
|
2388 |
assert resp.location == 'http://example.net/backoffice/settings/data-sources/' |
|
2389 |
assert NamedDataSource.get(1).slug == 'foo_bar' |
|
2390 | ||
2391 |
data_source = NamedDataSource(name='barfoo') |
|
2392 |
data_source.data_source = {'type': 'formula', 'value': '[]'} |
|
2393 |
data_source.store() |
|
2394 | ||
2395 |
resp = app.get('/backoffice/settings/data-sources/1/') |
|
2396 |
resp = resp.click(href='edit') |
|
2397 |
assert resp.forms[0]['name'].value == 'foobar' |
|
2398 |
resp.forms[0]['slug'] = 'barfoo' |
|
2399 |
resp = resp.forms[0].submit('submit') |
|
2400 |
assert 'This value is already used' in resp.body |
|
2401 | ||
2402 |
resp.forms[0]['slug'] = 'foobar' |
|
2403 |
resp = resp.forms[0].submit('submit') |
|
2404 |
assert resp.location == 'http://example.net/backoffice/settings/data-sources/' |
|
2405 | ||
2372 | 2406 |
def test_settings_permissions(pub): |
2373 | 2407 |
create_superuser(pub) |
2374 | 2408 |
role1 = create_role() |
wcs/admin/data_sources.py | ||
---|---|---|
29 | 29 |
self.datasource = NamedDataSource() |
30 | 30 | |
31 | 31 |
def get_form(self): |
32 |
form = Form(enctype='multipart/form-data') |
|
32 |
form = Form(enctype='multipart/form-data', |
|
33 |
advanced_label=_('Additional options')) |
|
33 | 34 |
form.add(StringWidget, 'name', title=_('Name'), required=True, size=30, |
34 | 35 |
value=self.datasource.name) |
35 | 36 |
form.add(TextWidget, 'description', title=_('Description'), |
... | ... | |
40 | 41 |
title=_('Data Source'), |
41 | 42 |
allow_named_sources=False, |
42 | 43 |
required=True) |
44 |
if self.datasource.slug: |
|
45 |
form.add(StringWidget, 'slug', |
|
46 |
value=self.datasource.slug, |
|
47 |
title=_('Identifier'), |
|
48 |
hint=_('Beware it is risky to change it'), |
|
49 |
required=True, advanced=True, |
|
50 |
) |
|
43 | 51 |
form.add_submit('submit', _('Submit')) |
44 | 52 |
form.add_submit('cancel', _('Cancel')) |
45 | 53 |
return form |
46 | 54 | |
47 | 55 |
def submit_form(self, form): |
48 | 56 |
name = form.get_widget('name').parse() |
57 |
if self.datasource.slug: |
|
58 |
slug = form.get_widget('slug').parse() |
|
49 | 59 | |
50 |
found_error = False |
|
51 | 60 |
for nds in NamedDataSource.select(): |
52 | 61 |
if nds.id == self.datasource.id: |
53 | 62 |
continue |
54 | 63 |
if name == nds.name: |
55 |
form.get_widget('name').set_error(_('This name is already used')) |
|
56 |
raise ValueError() |
|
64 |
form.get_widget('name').set_error(_('This name is already used.')) |
|
65 |
if slug == nds.slug: |
|
66 |
form.get_widget('slug').set_error(_('This value is already used.')) |
|
67 |
if form.has_errors(): |
|
68 |
raise ValueError() |
|
57 | 69 | |
58 | 70 |
self.datasource.name = name |
59 | 71 |
self.datasource.description = form.get_widget('description').parse() |
60 | 72 |
self.datasource.data_source = form.get_widget('data_source') |
73 |
if self.datasource.slug: |
|
74 |
self.datasource.slug = slug |
|
61 | 75 |
self.datasource.store() |
62 | 76 | |
63 | 77 | |
64 |
- |