Projet

Général

Profil

0001-backoffice-display-list-of-workflows-on-mail-templat.patch

Frédéric Péters, 10 avril 2020 07:25

Télécharger (3,8 ko)

Voir les différences:

Subject: [PATCH] backoffice: display list of workflows on mail template page
 (#41309)

 tests/test_mail_templates.py                   | 14 ++++++++++++--
 wcs/mail_templates.py                          |  9 ++++++---
 .../wcs/backoffice/mail-template.html          | 18 ++++++++++++++++--
 3 files changed, 34 insertions(+), 7 deletions(-)
tests/test_mail_templates.py
121 121
    assert 'first mail template' in resp
122 122

  
123 123

  
124
def test_mail_template_in_use(pub, mail_templates_option):
124
def test_mail_template_in_use(pub, superuser, mail_templates_option):
125 125
    Workflow.wipe()
126 126
    MailTemplate.wipe()
127
    workflow = Workflow(name='test mail template')
127
    workflow = Workflow(name='test workflow')
128 128
    st1 = workflow.add_status('Status1')
129 129
    item = SendmailWorkflowStatusItem()
130 130
    item.to = ['_receiver']
......
144 144
    workflow.store()
145 145
    assert mail_template.is_in_use() is True
146 146

  
147
    # check workflow usage is displayed
148
    app = login(get_app(pub))
149
    resp = app.get('/backoffice/workflows/mail-templates/%s/' % mail_template.id)
150
    assert 'Usage in workflows' in resp.text
151
    assert 'test workflow' in resp.text
152
    resp.click('test workflow')  # make sure the link is ok
153

  
154
    resp = resp.click('Delete')
155
    assert 'still used' in resp.text
156

  
147 157

  
148 158
def test_admin_workflow_edit(pub, superuser, mail_templates_option):
149 159
    Workflow.wipe()
wcs/mail_templates.py
59 59
            new_slug = '%s-%s' % (base_new_slug, suffix_no)
60 60
        return new_slug
61 61

  
62
    def is_in_use(self):
62
    def get_places_of_use(self):
63 63
        from wcs.workflows import Workflow
64 64
        for workflow in Workflow.select(ignore_errors=True, ignore_migration=True):
65 65
            for item in workflow.get_all_items():
66 66
                if item.key != 'sendmail':
67 67
                    continue
68 68
                if item.mail_template == self.slug:
69
                    return True
70
        return False
69
                    yield workflow
70
                    break
71

  
72
    def is_in_use(self):
73
        return any(self.get_places_of_use())
71 74

  
72 75
    @classmethod
73 76
    def get_as_options_list(cls):
wcs/templates/wcs/backoffice/mail-template.html
14 14
{% endif %}
15 15

  
16 16
{% if mail_template.subject and mail_template.body %}
17
<div class="bo-block">
18
<div class="mail-subject"><strong>{% trans "Subject:" %} </strong>{{ mail_template.subject }}</div>
17
<div class="section">
18
<h3 class="mail-subject"><strong>{% trans "Subject:" %} </strong>{{ mail_template.subject }}</h3>
19 19
<div class="mail-body">{{ mail_template.body }}</div>
20 20
</div>
21

  
22
{% for workflow in mail_template.get_places_of_use %}
23
{% if forloop.first %}
24
<div class="section">
25
 <h3>{% trans "Usage in workflows" %}</h3>
26
 <ul class="objects-list single-links">
27
{% endif %}
28
  <li><a href="../../{{ workflow.id }}/">{{ workflow.name }}</a></li>
29
{% if forloop.last %}
30
 </ul>
31
</div>
32
{% endif %}
33
{% endfor %}
34

  
21 35
{% else %}
22 36
<div class="infonotice">{% trans "This mail template still needs to be configured." %}</div>
23 37
{% endif %}
24
-