Projet

Général

Profil

0002-backoffice-divide-submission-screen-in-three-section.patch

Frédéric Péters, 08 novembre 2015 12:34

Télécharger (7,43 ko)

Voir les différences:

Subject: [PATCH 2/3] backoffice: divide submission screen in three sections
 (#8913)

- create: to create new formdata
- existing: to get back to existing drafts
- empty: to get back empty drafts (typically, mails)
 tests/test_backoffice_pages.py      | 37 ++++++++++++++++++++
 wcs/backoffice/submission.py        | 67 ++++++++++++++++++++++++++++---------
 wcs/formdata.py                     |  6 ++++
 wcs/qommon/static/css/dc2/admin.css |  5 +++
 4 files changed, 99 insertions(+), 16 deletions(-)
tests/test_backoffice_pages.py
740 740
    # check it kept the same id
741 741
    assert resp.location == 'http://example.net/backoffice/management/form-title/%s/' % formdata_no
742 742

  
743
def test_backoffice_submission_sections(pub):
744
    user = create_user(pub)
745
    create_environment(pub)
746

  
747
    app = login(get_app(pub))
748

  
749
    formdef = FormDef.get_by_urlname('form-title')
750
    formdef.enable_tracking_codes = True
751
    formdef.backoffice_submission_roles = user.roles[:]
752
    formdef.store()
753
    data_class = formdef.data_class()
754
    data_class.wipe()
755

  
756
    resp = app.get('/backoffice/submission/')
757
    assert not 'Submission to complete' in resp.body
758
    assert not 'Running submission' in resp.body
759

  
760
    formdata = data_class()
761
    formdata.data = {}
762
    formdata.status = 'draft'
763
    formdata.backoffice_submission = True
764
    formdata.receipt_time = datetime.datetime(2015, 1, 1).timetuple()
765
    formdata.store()
766

  
767
    resp = app.get('/backoffice/submission/')
768
    assert 'Submission to complete' in resp.body
769
    assert not 'Running submission' in resp.body
770
    assert '>#%s' % formdata.id in resp.body
771

  
772
    formdata.data = {'1': 'xxx'}
773
    formdata.store()
774
    resp = app.get('/backoffice/submission/')
775
    assert not 'Submission to complete' in resp.body
776
    assert 'Running submission' in resp.body
777
    assert '>#%s' % formdata.id in resp.body
778

  
779

  
743 780
def test_backoffice_submission_prefill_user_via_formula(pub):
744 781
    user = create_user(pub)
745 782
    create_environment(pub)
wcs/backoffice/submission.py
139 139
        misc_cat.formdefs = [x for x in list_forms if not x.category]
140 140
        cats.append(misc_cat)
141 141

  
142
        for cat in cats:
143
            if not cat.formdefs:
142
        for mode in ['create', 'existing', 'empty']:
143
            list_content = TemplateIO()
144
            for cat in cats:
145
                if not cat.formdefs:
146
                    continue
147
                list_content += self.form_list(cat.formdefs, title=cat.name, mode=mode)
148
            if not list_content.getvalue().strip():
144 149
                continue
145
            r += self.form_list(cat.formdefs, title=cat.name)
150
            r += htmltext('<div class="bo-block">')
151
            r += htmltext('<h2>%s</h2>') % {
152
                    'create': _('Submission'),
153
                    'existing': _('Running submission'),
154
                    'empty': _('Submission to complete'),
155
                    }.get(mode)
156
            r += htmltext('<ul class="biglist">')
157
            r += htmltext(list_content.getvalue())
158
            r += htmltext('</ul>')
159
            r += htmltext('</div>')
146 160

  
147 161
        return r.getvalue()
148 162

  
149
    def form_list(self, formdefs, title=None):
163
    def form_list(self, formdefs, title=None, mode='create'):
150 164
        r = TemplateIO(html=True)
151
        r += htmltext('<div class="bo-block">')
152
        if title:
153
            r += htmltext('<h2>%s</h2>') % title
165
        if mode != 'create':
166
            skip = True
167
            for formdef in formdefs:
168
                if not hasattr(formdef, '_formdatas'):
169
                    data_class = formdef.data_class()
170
                    formdata_ids = data_class.get_ids_with_indexed_value('status', 'draft')
171
                    formdef._formdatas = [x for x in data_class.get_ids(formdata_ids)
172
                            if x.backoffice_submission is True]
173
                skip &= not(bool(formdef._formdatas))
174
            if skip:
175
                return
176

  
177
        first = True
154 178

  
155
        r += htmltext('<ul class="biglist">')
156 179
        for formdef in formdefs:
180
            if mode != 'create':
181
                formdatas = formdef._formdatas[:]
182
                if mode == 'empty':
183
                    formdatas = [x for x in formdatas if x.has_empty_data()]
184
                elif mode == 'existing':
185
                    formdatas = [x for x in formdatas if not x.has_empty_data()]
186
                if not formdatas:
187
                    continue
188

  
189
            if first and title:
190
                r += htmltext('<li><h3>%s</h3></li>') % title
191
                first = False
192

  
157 193
            r += htmltext('<li>')
158
            r += htmltext('<strong class="label"><a href="%s/">%s</a></strong>') % (
159
                    formdef.url_name, formdef.name)
194
            if mode == 'create':
195
                r += htmltext('<strong class="label"><a href="%s/">%s</a></strong>') % (
196
                        formdef.url_name, formdef.name)
197
            else:
198
                r += htmltext('<strong class="label"><a class="fake">%s</a></strong>') % formdef.name
160 199
            r += htmltext('</li>')
161
            data_class = formdef.data_class()
162
            formdata_ids = data_class.get_ids_with_indexed_value('status', 'draft')
163
            formdatas = [x for x in data_class.get_ids(formdata_ids)
164
                    if x.backoffice_submission is True]
200
            if mode == 'create':
201
                continue
165 202
            for formdata in formdatas:
166 203
                r += htmltext('<li class="smallitem">')
167 204
                label = _('Draft #%s, %s') % (formdata.id,
......
170 207
                        formdef.url_name, formdata.id, label)
171 208
                r += htmltext('</li>')
172 209

  
173
        r += htmltext('</ul>')
174
        r += htmltext('</div>')
175 210
        return r.getvalue()
176 211

  
177 212
    def _q_lookup(self, component):
wcs/formdata.py
222 222
                self.user_id = None
223 223
    user = property(get_user, set_user)
224 224

  
225
    def has_empty_data(self):
226
        empty = True
227
        for key in self.data or {}:
228
            empty &= (self.data.get(key) is None)
229
        return empty
230

  
225 231
    def just_created(self):
226 232
        self.receipt_time = time.localtime()
227 233
        self.status = 'wf-%s' % self.formdef.workflow.possible_status[0].id
wcs/qommon/static/css/dc2/admin.css
550 550
	padding: 1ex;
551 551
	font-weight: normal;
552 552
	margin: 0;
553
	font-size: 130%;
553 554
}
554 555

  
555 556
div.bo-block > h3 {
......
576 577
	transition: all 0.25s ease 0s;
577 578
}
578 579

  
580
div.bo-block ul.biglist strong a.fake {
581
	color: #505050;
582
}
583

  
579 584
div.bo-block ul.biglist li.smallitem > a {
580 585
	padding: 0.2ex 1ex 0.2ex 4ex;
581 586
}
582
-