Projet

Général

Profil

0002-datasources-hide-buttons-to-delete-or-change-slug-of.patch

Nicolas Roche, 12 octobre 2019 00:39

Télécharger (4,1 ko)

Voir les différences:

Subject: [PATCH 2/2] datasources: hide buttons to delete or change slug of
 datasources in use (#15163)

 tests/test_admin_pages.py                      |  6 ++++++
 wcs/admin/data_sources.py                      | 14 +++++++++-----
 wcs/templates/wcs/backoffice/data-sources.html |  2 ++
 3 files changed, 17 insertions(+), 5 deletions(-)
tests/test_admin_pages.py
4872 4872

  
4873 4873
    app = login(get_app(pub))
4874 4874
    resp = app.get('/backoffice/settings/data-sources/1/')
4875
    assert "href='delete'" not in resp.body
4875 4876
    resp = app.get('/backoffice/settings/data-sources/1/delete', status=404)
4876 4877

  
4877 4878
def test_data_sources_edit_slug(pub):
......
4920 4921
    app = login(get_app(pub))
4921 4922
    resp = app.get('/backoffice/settings/data-sources/1/')
4922 4923
    resp = resp.click(href='edit')
4924
    assert '<label for="form_slug">' in resp.body
4923 4925

  
4924 4926
    formdef.name = 'form title'
4925 4927
    formdef.fields = [
......
4932 4934
    resp.forms[0]['slug'] = 'barfoo'
4933 4935
    resp = resp.forms[0].submit('submit', status=404)
4934 4936

  
4937
    resp = app.get('/backoffice/settings/data-sources/1/')
4938
    resp = resp.click(href='edit')
4939
    assert '<label for="form_slug">' not in resp.body
4940

  
4935 4941
def test_wscalls_new(pub):
4936 4942
    create_superuser(pub)
4937 4943
    NamedWsCall.wipe()
wcs/admin/data_sources.py
85 85
                    'data-dynamic-display-child-of': 'data_source$type',
86 86
                    'data-dynamic-display-value': 'json',
87 87
                })
88
        if self.datasource.slug:
88
        if self.datasource.slug and not self.is_datasource_in_use():
89 89
            form.add(StringWidget, 'slug',
90 90
                    value=self.datasource.slug,
91 91
                    title=_('Identifier'),
......
99 99
    def submit_form(self, form):
100 100
        name = form.get_widget('name').parse()
101 101
        if self.datasource.slug:
102
            slug = form.get_widget('slug').parse()
102
            slug_widget = form.get_widget('slug')
103
            if not slug_widget:
104
                raise errors.TraversalError()
105
            slug = slug_widget.parse()
103 106
        else:
104 107
            slug = None
105
        if self.datasource.slug != slug and self.is_datasource_in_use():
106
            raise errors.TraversalError()
107 108

  
108 109
        for nds in NamedDataSource.select():
109 110
            if nds.id == self.datasource.id:
......
148 149
                formdefs.append(formdef)
149 150
        return formdefs
150 151

  
152
    def is_datasource_in_use(self):
153
        return self.datasource_ui.is_datasource_in_use()
154

  
151 155
    def preview_block(self):
152 156
        if self.datasource.data_source.get('type') not in ('json', 'formula'):
153 157
            return ''
......
200 204
        return r.getvalue()
201 205

  
202 206
    def delete(self):
203
        if self.datasource_ui.is_datasource_in_use():
207
        if self.is_datasource_in_use():
204 208
            raise errors.TraversalError()
205 209
        form = Form(enctype='multipart/form-data')
206 210
        form.widgets.append(HtmlWidget('<p>%s</p>' % _(
wcs/templates/wcs/backoffice/data-sources.html
4 4
<div id="appbar">
5 5
<h2>{% trans "Data Source" %} - {{ datasource.name }}</h2>
6 6
<span class="actions">
7
{% if not view.is_datasource_in_use %}
7 8
  <a href="delete" rel="popup">{% trans "Delete" %}</a>
9
{% endif %}
8 10
  <a href="edit">{% trans "Edit" %}</a>
9 11
</span>
10 12
</div>
11
-