0001-backoffice-warn-about-data-deletion-when-removing-a-.patch
tests/test_admin_pages.py | ||
---|---|---|
1075 | 1075 |
assert '<h3 data-field-id="1">baz</h3>' in resp.body |
1076 | 1076 | |
1077 | 1077 |
def test_form_delete_field(pub): |
1078 |
create_superuser(pub) |
|
1078 | 1079 |
create_role() |
1079 | 1080 | |
1080 | 1081 |
FormDef.wipe() |
... | ... | |
1090 | 1091 |
assert 'Use drag and drop' in resp.body |
1091 | 1092 | |
1092 | 1093 |
resp = resp.click(href='1/delete') |
1094 |
assert 'You are about to remove the "1st field" field.' in resp.body |
|
1095 |
assert 'Warning:' not in resp.body |
|
1093 | 1096 |
resp = resp.forms[0].submit() |
1094 | 1097 |
assert resp.location == 'http://example.net/backoffice/forms/1/fields/' |
1095 | 1098 |
resp = resp.follow() |
1096 | 1099 |
assert len(FormDef.get(1).fields) == 0 |
1097 | 1100 | |
1101 |
def test_form_delete_field_existing_data(pub): |
|
1102 |
create_superuser(pub) |
|
1103 |
create_role() |
|
1104 | ||
1105 |
FormDef.wipe() |
|
1106 |
formdef = FormDef() |
|
1107 |
formdef.name = 'form title' |
|
1108 |
formdef.fields = [ |
|
1109 |
fields.StringField(id='1', label='1st field', type='string'), |
|
1110 |
fields.CommentField(id='2', label='comment field', type='comment'), |
|
1111 |
] |
|
1112 |
formdef.store() |
|
1113 | ||
1114 |
formdata = formdef.data_class()() |
|
1115 |
formdata.just_created() |
|
1116 |
formdata.data = {'1': 'hello'} |
|
1117 |
formdata.store() |
|
1118 | ||
1119 |
app = login(get_app(pub)) |
|
1120 |
resp = app.get('/backoffice/forms/1/') |
|
1121 |
resp = resp.click(href='fields/') |
|
1122 |
resp = resp.click(href='1/delete') |
|
1123 |
assert 'You are about to remove the "1st field" field.' in resp.body |
|
1124 |
assert 'Warning:' in resp.body |
|
1125 |
resp = resp.forms[0].submit() |
|
1126 |
assert resp.location == 'http://example.net/backoffice/forms/1/fields/#itemId_2' |
|
1127 |
resp = resp.follow() |
|
1128 |
assert len(FormDef.get(1).fields) == 1 |
|
1129 | ||
1130 |
# check non-data fields do not show this warning |
|
1131 |
resp = app.get('/backoffice/forms/1/') |
|
1132 |
resp = resp.click(href='fields/') |
|
1133 |
resp = resp.click(href='2/delete') |
|
1134 |
assert 'You are about to remove the "comment field" field.' in resp.body |
|
1135 |
assert 'Warning:' not in resp.body |
|
1136 |
resp = resp.forms[0].submit() |
|
1137 |
resp = resp.follow() |
|
1138 |
assert len(FormDef.get(1).fields) == 0 |
|
1139 |
|
|
1098 | 1140 |
def test_form_duplicate_field(pub): |
1099 | 1141 |
user = create_superuser(pub) |
1100 | 1142 |
create_role() |
... | ... | |
2553 | 2595 |
assert 'foobar' in resp.body |
2554 | 2596 |
resp = resp.click('Edit') |
2555 | 2597 |
assert not 'in_listing' in resp.form.fields.keys() |
2598 |
resp = resp.form.submit('cancel') |
|
2599 |
resp = resp.follow() |
|
2600 |
resp = resp.click('Remove') |
|
2601 |
assert 'You are about to remove the "foobar" field.' in resp.body |
|
2602 |
assert not 'Warning:' in resp.body |
|
2556 | 2603 | |
2557 | 2604 |
def test_workflows_edit_choice_action(pub): |
2558 | 2605 |
create_superuser(pub) |
wcs/admin/fields.py | ||
---|---|---|
98 | 98 |
setattr(self.field, f.replace('-', '_'), widget.parse()) |
99 | 99 |
self.objectdef.store() |
100 | 100 | |
101 |
def get_deletion_extra_warning(self): |
|
102 |
return _('Warning: this field data will be permanently deleted.') |
|
101 | 103 | |
102 | 104 |
def delete(self): |
103 | 105 |
form = Form(enctype='multipart/form-data') |
106 |
ellipsized_field_label = misc.ellipsize(self.field.unhtmled_label, 60) |
|
104 | 107 |
form.widgets.append(HtmlWidget('<p>%s</p>' % _( |
105 |
"You are about to remove a field."))) |
|
108 |
"You are about to remove the \"%s\" field.") % ellipsized_field_label)) |
|
109 |
if self.field.type not in ('page', 'subtitle', 'title', 'comment'): |
|
110 |
warning = self.get_deletion_extra_warning() |
|
111 |
if warning: |
|
112 |
form.widgets.append(HtmlWidget('<div class="warningnotice">%s</div>' % warning)) |
|
106 | 113 |
form.add_submit('delete', _('Submit')) |
107 | 114 |
form.add_submit("cancel", _("Cancel")) |
108 | 115 |
if form.get_widget('cancel').parse(): |
... | ... | |
114 | 121 |
get_response().breadcrumb.append(('delete', _('Delete'))) |
115 | 122 |
self.html_top(title = _('Delete Field')) |
116 | 123 |
r = TemplateIO(html=True) |
117 |
r += htmltext('<h2>%s %s</h2>') % (_('Deleting Field:'), |
|
118 |
misc.ellipsize(self.field.unhtmled_label, 60)) |
|
124 |
r += htmltext('<h2>%s</h2>') % _('Deleting Field: %s') % ellipsized_field_label |
|
119 | 125 |
r += form.render() |
120 | 126 |
return r.getvalue() |
121 | 127 |
else: |
wcs/admin/forms.py | ||
---|---|---|
116 | 116 |
class FieldDefPage(FieldDefPage): |
117 | 117 |
section = 'forms' |
118 | 118 | |
119 |
def get_deletion_extra_warning(self): |
|
120 |
if not self.objectdef.data_class().count(): |
|
121 |
return None |
|
122 |
return _('Warning: this field data will be permanently deleted from existing forms.') |
|
123 | ||
119 | 124 | |
120 | 125 |
class FieldsDirectory(FieldsDirectory): |
121 | 126 |
field_def_page_class = FieldDefPage |
wcs/wf/form.py | ||
---|---|---|
62 | 62 |
form.remove('in_listing') |
63 | 63 |
return form |
64 | 64 | |
65 |
def get_deletion_extra_warning(self): |
|
66 |
return None |
|
67 | ||
65 | 68 | |
66 | 69 |
class WorkflowFormFieldsDirectory(FieldsDirectory): |
67 | 70 |
section = 'workflows' |
68 |
- |