Projet

Général

Profil

0001-general-keep-submission-context-additional-details-8.patch

Frédéric Péters, 21 septembre 2015 16:14

Télécharger (10,5 ko)

Voir les différences:

Subject: [PATCH] general: keep submission context additional details (#8306)

 wcs/api.py                          |  2 ++
 wcs/backoffice/management.py        | 31 +++++++++++++++++++++++++++++++
 wcs/backoffice/submission.py        | 27 +++++++++++++++++++--------
 wcs/formdata.py                     |  1 +
 wcs/forms/root.py                   |  5 ++++-
 wcs/qommon/static/css/dc2/admin.css |  9 +++++++++
 wcs/sql.py                          | 19 ++++++++++++++++---
 7 files changed, 82 insertions(+), 12 deletions(-)
wcs/api.py
202 202
            formdata.backoffice_submission = True
203 203
        else:
204 204
            formdata.user_id = user.id
205
        if json_input.get('context'):
206
            formdata.extra_submission_context = json_input['context']
205 207
        formdata.store()
206 208
        if self.formdef.enable_tracking_codes:
207 209
            code = get_publisher().tracking_code_class()
wcs/backoffice/management.py
1100 1100
        return html_top('management', title)
1101 1101

  
1102 1102
    def _q_index(self):
1103
        get_response().filter['sidebar'] = self.get_sidebar()
1103 1104
        return self.status()
1104 1105

  
1106
    def get_sidebar(self):
1107
        return self.get_extra_context_bar()
1108

  
1109
    def get_extra_context_bar(self):
1110
        formdata = self.filled
1111
        if not formdata.extra_submission_context:
1112
            return ''
1113

  
1114
        r = TemplateIO(html=True)
1115
        extra_context = formdata.extra_submission_context or {}
1116
        r += htmltext('<div class="extra-context">')
1117
        if extra_context.get('channel'):
1118
            channel_labels = {
1119
                'mail': _('Mail'),
1120
            }
1121
            r += htmltext('<h3>%s</h3>') % '%s: %s' % (
1122
                    _('Channel'), channel_labels.get(extra_context.get('channel'), '?'))
1123
        if extra_context.get('thumbnail_url'):
1124
            r += htmltext('<p class="thumbnail"><img src="%s" alt=""/></p>'
1125
                    ) % extra_context.get('thumbnail_url')
1126
        if extra_context.get('user_id'):
1127
            r += htmltext('<h3>%s</h3>') % _('Associated User')
1128
            r += htmltext('<p>%s</p>') % get_publisher().user_class.get(
1129
                    extra_context.get('user_id')).display_name
1130
        if extra_context.get('comments'):
1131
            r += htmltext('<h3>%s</h3>') % _('Comments')
1132
            r += htmltext('<p>%s</p>') % extra_context.get('comments')
1133
        r += htmltext('</div>')
1134
        return r.getvalue()
1135

  
1105 1136

  
1106 1137
class FakeField(object):
1107 1138
    def __init__(self, id, type_, label):
wcs/backoffice/submission.py
25 25
from wcs.categories import Category
26 26
from wcs.forms.root import FormPage as PublicFormFillPage
27 27

  
28
from .management import FormBackOfficeStatusPage
29

  
28 30

  
29 31
class FormFillPage(PublicFormFillPage):
30 32
    def html_top(self, *args, **kwargs):
......
42 44
    def get_sidebar(self, data):
43 45
        r = TemplateIO(html=True)
44 46

  
47
        formdata = None
48
        draft_formdata_id = data.get('draft_formdata_id')
49
        if draft_formdata_id:
50
            formdata = self.formdef.data_class().get(draft_formdata_id)
45 51
        if self.formdef.enable_tracking_codes:
46
            draft_formdata_id = data.get('draft_formdata_id')
47 52
            r += htmltext('<h3>%s</h3>') % _('Tracking Code')
48
            tracking_code = None
49
            if draft_formdata_id:
50
                formdata = self.formdef.data_class().get(draft_formdata_id)
51
                if formdata.tracking_code:
52
                    tracking_code = formdata.tracking_code
53
            if tracking_code:
54
                r += htmltext('<p>%s</p>') % tracking_code
53
            if formdata and formdata.tracking_code:
54
                tracking_code = formdata.tracking_code
55
                r += htmltext('<p>%s</p>') % formdata.tracking_code
55 56
            else:
56 57
                r += htmltext('<p>-</p>')
57 58

  
59
        if formdata and formdata.extra_submission_context:
60
            r += FormBackOfficeStatusPage(self.formdef, formdata).get_extra_context_bar()
61

  
58 62
        return r.getvalue()
59 63

  
60 64
    def form_side(self, step_no, page_no=0, log_detail=None, data=None, editing=None):
......
72 76
        filled.backoffice_submission = True
73 77
        filled.store()
74 78

  
79
        magictoken = get_request().form.get('magictoken')
80
        form_data = get_session().get_by_magictoken(magictoken, {})
81
        draft_formdata_id = form_data.get('draft_formdata_id')
82
        if draft_formdata_id:
83
            old_draft_formdata = self.formdef.data_class().get(draft_formdata_id)
84
            filled.extra_submission_context = old_draft_formdata.extra_submission_context
85

  
75 86
        self.keep_tracking_code(filled)
76 87
        get_session().remove_magictoken(get_request().form.get('magictoken'))
77 88

  
wcs/formdata.py
158 158
    editable_by = None
159 159
    tracking_code = None
160 160
    backoffice_submission = False
161
    extra_submission_context = None
161 162

  
162 163
    workflow_data = None
163 164
    workflow_roles = None
wcs/forms/root.py
509 509
            if get_request().form.has_key('mt'):
510 510
                magictoken = get_request().form['mt']
511 511
                data = session.get_by_magictoken(magictoken, {})
512
                session.remove_magictoken(magictoken)
512
                if not get_request().is_in_backoffice():
513
                    # don't remove magictoken as the backoffice agent may get
514
                    # the page reloaded.
515
                    session.remove_magictoken(magictoken)
513 516
                if data:
514 517
                    # create a new one since the other has been exposed in a url
515 518
                    magictoken = randbytes(8)
wcs/qommon/static/css/dc2/admin.css
1089 1089
	background: #eee;
1090 1090
}
1091 1091

  
1092
div.extra-context p.thumbnail {
1093
	text-align: center;
1094
}
1095

  
1096
div.extra-context p.thumbnail img {
1097
	box-shadow: 0 0 3px black;
1098
	transform: rotate(2deg);
1099
}
1100

  
1092 1101
@media print {
1093 1102
	div#sidebar {
1094 1103
		display: none;
wcs/sql.py
307 307
        'status', 'workflow_data', 'id_display', 'fts', 'page_no',
308 308
        'anonymised', 'workflow_roles', 'workflow_roles_array',
309 309
        'concerned_roles_array', 'tracking_code',
310
        'actions_roles_array', 'backoffice_submission'])
310
        'actions_roles_array', 'backoffice_submission',
311
        'extra_submission_context'])
311 312

  
312 313
    # migrations
313 314
    if not 'fts' in existing_fields:
......
336 337
    if not 'backoffice_submission' in existing_fields:
337 338
        cur.execute('''ALTER TABLE %s ADD COLUMN backoffice_submission boolean''' % table_name)
338 339

  
340
    if not 'extra_submission_context' in existing_fields:
341
        cur.execute('''ALTER TABLE %s ADD COLUMN extra_submission_context bytea''' % table_name)
342

  
339 343
    # add new fields
340 344
    for field in formdef.fields:
341 345
        assert field.id is not None
......
926 930
        ('actions_roles_array', 'text[]'),
927 931
        ('tracking_code', 'varchar'),
928 932
        ('backoffice_submission', 'boolean'),
933
        ('extra_submission_context', 'bytea'),
929 934
    ]
930 935

  
931 936
    def __init__(self, id=None):
......
1018 1023
                'anonymised': self.anonymised,
1019 1024
                'tracking_code': self.tracking_code,
1020 1025
                'backoffice_submission': self.backoffice_submission,
1026
                'extra_submission_context': self.extra_submission_context,
1021 1027
        }
1022 1028
        if self.receipt_time:
1023 1029
            sql_dict['receipt_time'] = datetime.datetime.fromtimestamp(time.mktime(self.receipt_time)),
......
1029 1035
        else:
1030 1036
            sql_dict['workflow_roles'] = None
1031 1037
            sql_dict['workflow_roles_array'] = None
1038
        if self.extra_submission_context:
1039
            sql_dict['extra_submission_context'] = bytearray(cPickle.dumps(self.extra_submission_context))
1040
        else:
1041
            sql_dict['extra_submission_context'] = None
1032 1042

  
1033 1043
        sql_dict['concerned_roles_array'] = [str(x) for x in self.concerned_roles if x]
1034 1044
        sql_dict['actions_roles_array'] = [str(x) for x in self.actions_roles if x]
......
1133 1143
            o.workflow_data = cPickle.loads(str(o.workflow_data))
1134 1144
        if o.workflow_roles:
1135 1145
            o.workflow_roles = cPickle.loads(str(o.workflow_roles))
1146
        if o.extra_submission_context:
1147
            o.extra_submission_context = cPickle.loads(str(o.extra_submission_context))
1136 1148
        o.data = cls._row2obdata(row, cls._formdef)
1137 1149
        return o
1138 1150
    _row2ob = classmethod(_row2ob)
......
1658 1670
    return result
1659 1671

  
1660 1672

  
1661
SQL_LEVEL = 7
1673
SQL_LEVEL = 8
1662 1674

  
1663 1675
def migrate_global_views(conn, cur):
1664 1676
    cur.execute('''SELECT COUNT(*) FROM information_schema.tables
......
1707 1719
        migrate_views(conn, cur)
1708 1720
        for formdef in FormDef.select():
1709 1721
            formdef.data_class().rebuild_security()
1710
    if sql_level < 7:
1722
    if sql_level < 8:
1711 1723
        # 7: add backoffice_submission to tables and views
1724
        # 8: add extra_submission_context to tables
1712 1725
        migrate_views(conn, cur)
1713 1726

  
1714 1727
    cur.execute('''UPDATE wcs_meta SET value = %s WHERE key = %s''', (
1715
-