Projet

Général

Profil

0002-backoffice-use-a-template-to-render-workflow-status-.patch

Frédéric Péters, 04 mai 2021 13:19

Télécharger (11 ko)

Voir les différences:

Subject: [PATCH 2/3] backoffice: use a template to render workflow status page
 (#47154)

 tests/admin_pages/test_workflow.py            |   2 +-
 wcs/admin/workflows.py                        | 115 ++++--------------
 .../wcs/backoffice/workflow-status.html       |  93 ++++++++++++++
 3 files changed, 115 insertions(+), 95 deletions(-)
 create mode 100644 wcs/templates/wcs/backoffice/workflow-status.html
tests/admin_pages/test_workflow.py
1863 1863
    resp = resp.forms[0].submit('submit')
1864 1864
    resp.forms[0]['trigger_id'] = 'action:%s' % trigger.identifier
1865 1865
    resp = resp.forms[0].submit('submit').follow().follow()
1866
    assert 'External workflow (action "Global action" on external)' in resp.text
1866
    assert 'External workflow (action "Global action" on external)' in resp.text
1867 1867
    assert Workflow.get(workflow.id).possible_status[0].items[0].target_mode == 'all'
1868 1868
    assert Workflow.get(workflow.id).possible_status[0].items[0].target_id is None
1869 1869

  
wcs/admin/workflows.py
516 516
        ('schema.svg', 'svg'),
517 517
        'svg',
518 518
    ]
519
    do_not_call_in_templates = True
519 520

  
520 521
    def __init__(self, workflow, status_id, html_top):
521 522
        self.html_top = html_top
......
530 531

  
531 532
    def _q_index(self):
532 533
        self.html_top('%s - %s' % (_('Workflow'), self.workflow.name))
533
        r = TemplateIO(html=True)
534 534
        get_response().add_javascript(
535
            ['jquery.js', 'jquery-ui.js', 'biglist.js', 'svg-pan-zoom.js', 'qommon.wysiwyg.js']
535
            [
536
                'jquery.js',
537
                'jquery-ui.js',
538
                'biglist.js',
539
                'svg-pan-zoom.js',
540
                'qommon.wysiwyg.js',
541
                'popup.js',
542
                'jquery.colourpicker.js',
543
            ]
544
        )
545
        return template.QommonTemplateResponse(
546
            templates=['wcs/backoffice/workflow-status.html'],
547
            context={'view': self, 'workflow': self.workflow, 'status': self.status, 'has_sidebar': True},
548
            is_django_native=True,
536 549
        )
537 550

  
538
        r += htmltext('<h2>%s</h2>') % self.status.name
539
        r += get_session().display_message()
540

  
541
        if self.status.get_visibility_restricted_roles():
542
            r += htmltext('<div class="bo-block">')
543
            r += _('This status is hidden from the user.')
544
            if not self.workflow.is_readonly():
545
                r += ' '
546
                r += htmltext('(<a href="display" rel="popup">%s</a>)') % _('change')
547
            r += htmltext('</div>')
548

  
549
        if not self.status.items:
550
            r += htmltext('<div class="infonotice">%s</div>') % _(
551
                'There are not yet any items in this status.'
552
            )
553
        else:
554
            r += htmltext('<div class="bo-block">')
555
            if self.workflow.is_readonly():
556
                r += htmltext('<ul id="items-list" class="biglist">')
557
            else:
558
                r += htmltext('<p class="hint">')
559
                r += _('Use drag and drop with the handles to reorder items.')
560
                r += htmltext('</p>')
561
                r += htmltext('<ul id="items-list" class="biglist sortable">')
562
            for item in self.status.items:
563
                r += htmltext('<li class="biglistitem" id="itemId_%s">') % item.id
564
                if hasattr(item, str('fill_admin_form')):
565
                    r += htmltext('<a href="items/%s/">%s</a>') % (item.id, item.render_as_line())
566
                else:
567
                    r += item.render_as_line()
568
                r += htmltext('<p class="commands">')
569
                if not self.workflow.is_readonly():
570
                    if hasattr(item, 'fill_admin_form'):
571
                        r += command_icon('items/%s/' % item.id, 'edit')
572
                    r += command_icon('items/%s/delete' % item.id, 'remove', popup=True)
573
                r += htmltext('</p>')
574
                r += htmltext('</li>')
575
            r += htmltext('</ul>')
576
            r += htmltext('</div>')  # bo-block
577

  
578
        source_status = []
551
    def get_source_statuses(self):
552
        statuses = []
579 553
        for status in self.workflow.possible_status:
580 554
            if status is self.status:
581 555
                continue
582 556
            for item in status.items:
583 557
                if self.status in item.get_target_status():
584
                    source_status.append(status)
558
                    statuses.append(status)
585 559
                    break
560
        return statuses
586 561

  
587
        if source_status:
588
            r += htmltext('<div class="bo-block">')
589
            r += htmltext('<h3>%s</h3>') % _('Jumps')
590
            r += htmltext('<p>%s ') % _('This status is reachable from the following status:')
591
            r += htmltext(', ').join(
592
                [htmltext('<a href="../%s/">%s</a>') % (x.id, x.name) for x in source_status]
593
            )
594
            r += htmltext('.</p>')
595
            r += htmltext('</div>')
596

  
597
        r += htmltext('<p><a href="../../">%s</a></p>') % _('Back to workflow main page')
598

  
599
        r += htmltext('<div class="bo-block">')
600
        r += htmltext(
601
            graphviz(self.workflow, url_prefix='../../', include=True, select='%s' % self.status.id)
602
        )
603
        r += htmltext('<div class="full-screen-link"><a href="schema.svg">%s</a></div>') % _('Full Screen')
604
        r += htmltext('</div>')
605

  
606
        get_response().filter['sidebar'] = self.get_sidebar()
607

  
608
        return r.getvalue()
562
    def graphviz(self):
563
        return graphviz(self.workflow, url_prefix='../../', include=True, select='%s' % self.status.id)
609 564

  
610 565
    def svg(self):
611 566
        response = get_response()
......
616 571
            self.workflow, url_prefix='../../', include=False, select='%s' % self.status.id
617 572
        ).replace('?>', '?>\n<?xml-stylesheet href="%s" type="text/css"?>\n' % css)
618 573

  
619
    def get_sidebar(self):
620
        get_response().add_javascript(['popup.js', 'jquery.colourpicker.js'])
621
        r = TemplateIO(html=True)
622
        if self.workflow.is_default():
623
            r += htmltext('<p>')
624
            r += _(
625
                '''This is the default workflow, you cannot edit it but you can
626
                 duplicate it to base your own workflow on it.'''
627
            )
628
            r += htmltext('</p>')
629
        elif self.workflow.is_readonly():
630
            r += htmltext('<div class="infonotice"><p>%s</p></div>') % _('This workflow is readonly.')
631
        else:
632
            r += htmltext('<ul id="sidebar-actions">')
633
            r += htmltext('<li><a href="edit" rel="popup">%s</a></li>') % _('Change Status Name')
634
            r += htmltext('<li><a href="display" rel="popup">%s</a></li>') % _('Change Display Settings')
635
            r += htmltext('<li><a href="endpoint" rel="popup">%s</a></li>') % _('Change Terminal Status')
636
            r += htmltext('<li><a href="backoffice-info-text" rel="popup">%s</a></li>') % _(
637
                'Change Backoffice Information Text'
638
            )
639
            r += htmltext('<li><a href="delete" rel="popup">%s</a></li>') % _('Delete')
640
            r += htmltext('</ul>')
641
            r += htmltext('<div id="new-field">')
642
            r += htmltext('<h3>%s</h3>') % _('New Action')
643
            r += self.get_new_item_form().render()
644
            r += htmltext('</div>')
645
        return r.getvalue()
646

  
647 574
    def is_item_available(self, item):
648 575
        return item.is_available(workflow=self.workflow)
649 576

  
wcs/templates/wcs/backoffice/workflow-status.html
1
{% extends "wcs/backoffice.html" %}
2
{% load i18n %}
3

  
4
{% block appbar-title %}{{ status.name }}{% endblock %}
5

  
6
{% block content %}
7
{{ block.super }}
8

  
9
{% if status.get_visibility_restricted_roles %}
10
<div class="bo-block">
11
{% trans "This status is hidden from the user." %}
12
{% if not workflow.is_readonly %}
13
(<a href="display" rel="popup">{% trans "change" %}</a>)
14
{% endif %}
15
</div>
16
{% endif %}
17

  
18
{% if not status.items %}
19
<div class="infonotice">
20
{% trans "There are not yet any items in this status." %}
21
</div>
22
{% else %}
23
{% spaceless %}
24
<div class="bo-block">
25
  {% if workflow.is_readonly %}
26
  <ul id="items-list" class="biglist">
27
  {% else %}
28
  <p class="hint">{% trans "Use drag and drop with the handles to reorder items." %}</p>
29
  <ul id="items-list" class="biglist sortable">
30
  {% endif %}
31
  {% for item in status.items %}
32
  <li class="biglistitem" id="itemId_{{ item.id }}">
33
    <a href="items/{{ item.id }}/">{{ item.render_as_line|safe }}</a>
34
  <p class="commands">
35
  {% if not workflow.is_readonly %}
36
  <span class="edit"><a href="items/{{ item.id }}/" title="{% trans "Edit" %}">{% trans "Edit" %}</a></span>
37
  <span class="remove"><a href="items/{{ item.id }}/delete" rel="popup" title="{% trans "Delete" %}">{% trans "Delete" %}</a></span>
38
  {% endif %}
39
  </p>
40
  </li>
41
  {% endfor %}
42
 </ul>
43
</div>
44
{% endspaceless %}
45
{% endif %}
46

  
47
{% with source_statuses=view.get_source_statuses %}
48
 {% if source_statuses %}
49
 <div class="bo-block">
50
 <h3>{% trans "Jumps" %}</h3>
51
 <p>{% trans "This status is reachable from the following status:" %}
52
 {% for source in source_statuses %}
53
 <a href="../{{ source.id }}/">{{ source.name }}</a>{% if not forloop.last %}, {% endif %}
54
 {% endfor %}
55
 </p>
56
 </div>
57
 {% endif %}
58
{% endwith %}
59

  
60
<p><a href="../../">{% trans "Back to workflow main page" %}</a></p>
61

  
62
<div class="bo-block">
63
{{ view.graphviz|safe }}
64
<div class="full-screen-link"><a href="schema.svg">{% trans "Full Screen" %}</a></div>
65
</div>
66

  
67
{% endblock %}
68

  
69
{% block sidebar-content %}
70
{% if workflow.is_default %}
71
<p>
72
{% blocktrans %}
73
This is the default workflow, you cannot edit it but you can
74
duplicate it to base your own workflow on it.
75
{% endblocktrans %}
76
</p>
77
{% elif workflow.is_readonly %}
78
<div class="infonotice"><p>{% trans "This workflow is readonly." %}</p></div>
79
{% else %}
80
<ul id="sidebar-actions">
81
<li><a href="edit" rel="popup">{% trans "Change Status Name" %}</a></li>
82
<li><a href="display" rel="popup">{% trans "Change Display Settings" %}</a></li>
83
<li><a href="endpoint" rel="popup">{% trans "Change Terminal Status" %}</a></li>
84
<li><a href="backoffice-info-text" rel="popup">{% trans "Change Backoffice Information Text" %}</a></li>
85
<li><a href="delete" rel="popup">{% trans "Delete" %}</a></li>
86
</ul>
87
<div id="new-field">
88
<h3>{% trans "New Action" %}</h3>
89
{{ view.get_new_item_form.render|safe }}
90
</div>
91
{% endif %}
92

  
93
{% endblock %}
0
-