0001-submission-allow-NameID-and-channel-is-query-string-.patch
tests/test_backoffice_pages.py | ||
---|---|---|
2270 | 2270 |
resp = app.get('/backoffice/submission/%s/' % formdef.url_name) |
2271 | 2271 |
assert 'submission_channel' not in resp.form.fields |
2272 | 2272 | |
2273 |
def test_backoffice_submission_with_nameid_and_channel(pub, local_user): |
|
2274 |
user = create_user(pub) |
|
2275 |
create_environment(pub) |
|
2276 | ||
2277 |
formdef = FormDef.get_by_urlname('form-title') |
|
2278 |
formdef.fields[0].prefill = {'type': 'formula', 'value': 'form_user_email'} |
|
2279 |
formdef.backoffice_submission_roles = user.roles[:] |
|
2280 |
formdef.enable_tracking_codes = True |
|
2281 |
formdef.store() |
|
2282 | ||
2283 |
app = login(get_app(pub)) |
|
2284 |
resp = app.get('/backoffice/submission/form-title/?NameID=%s&channel=mail' % local_user.name_identifiers[0]) |
|
2285 |
assert resp.location.startswith('http://example.net/backoffice/submission/form-title/') |
|
2286 | ||
2287 |
formdata_no = resp.location.split('/')[-1] |
|
2288 |
formdata = formdef.data_class().get(formdata_no) |
|
2289 |
assert formdata.user_id == str(local_user.id) |
|
2290 |
assert formdata.submission_channel == 'mail' |
|
2291 |
assert formdata.status == 'draft' |
|
2292 | ||
2293 |
resp = resp.follow() # redirect to created draft |
|
2294 |
resp = resp.follow() # redirect to ?mt= |
|
2295 | ||
2296 |
assert resp.form['f1'].value == local_user.email # prefill with form_user_email |
|
2297 |
resp.form['f2'] = 'baz' |
|
2298 |
resp.form['f3'] = 'C' |
|
2299 |
resp = resp.form.submit('submit') |
|
2300 |
assert 'Check values then click submit.' in resp.body |
|
2301 |
# final submit |
|
2302 |
resp = resp.form.submit('submit') |
|
2303 | ||
2304 |
formdata_no = resp.location.split('/')[-2] |
|
2305 |
data_class = formdef.data_class() |
|
2306 |
formdata = data_class.get(formdata_no) |
|
2307 |
assert formdata.user_id == str(local_user.id) |
|
2308 |
assert formdata.submission_channel == 'mail' |
|
2309 |
assert formdata.status == 'wf-new' |
|
2310 | ||
2273 | 2311 |
def test_backoffice_wscall_failure_display(http_requests, pub): |
2274 | 2312 |
user = create_user(pub) |
2275 | 2313 |
create_environment(pub) |
wcs/backoffice/submission.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU General Public License |
15 | 15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import time |
|
18 | ||
17 | 19 |
from django.utils.safestring import mark_safe |
18 | 20 | |
19 | 21 |
from quixote import get_publisher, get_request, get_response, get_session, redirect |
... | ... | |
85 | 87 |
self.remove_draft = RemoveDraftDirectory(self) |
86 | 88 | |
87 | 89 |
def _q_index(self, *args, **kwargs): |
90 |
# if NameID or channel are in query string, create a new draft with |
|
91 |
# these parameters, and redirect to it |
|
92 |
submission_channel = get_request().form.get('channel') |
|
93 |
name_id = get_request().form.get('NameID') |
|
94 |
if name_id or submission_channel: |
|
95 |
formdata = self.formdef.data_class()() |
|
96 |
formdata.data = {} |
|
97 |
formdata.backoffice_submission = True |
|
98 |
formdata.submission_channel = submission_channel or '' |
|
99 |
formdata.submission_context = {'agent_id': get_request().user.id} |
|
100 |
formdata.status = 'draft' |
|
101 |
formdata.receipt_time = time.localtime() |
|
102 |
if name_id: |
|
103 |
users = list(get_publisher().user_class.get_users_with_name_identifier(name_id)) |
|
104 |
if users: |
|
105 |
formdata.user_id = users[0].id |
|
106 |
formdata.store() |
|
107 |
self.set_tracking_code(formdata) |
|
108 |
return redirect('%s' % formdata.id) |
|
109 | ||
88 | 110 |
self.selected_submission_channel = get_request().form.get('submission_channel') or '' |
89 | 111 |
return super(FormFillPage, self)._q_index(*args, **kwargs) |
90 | 112 | |
... | ... | |
127 | 149 |
r += htmltext('<p>-</p>') |
128 | 150 | |
129 | 151 |
welco_url = get_publisher().get_site_option('welco_url', 'options') |
130 |
if not welco_url and not self.edit_mode: |
|
152 |
if formdata and formdata.submission_context: |
|
153 |
from .management import FormBackOfficeStatusPage |
|
154 |
r += FormBackOfficeStatusPage(self.formdef, formdata).get_extra_context_bar() |
|
155 |
elif not welco_url and not self.edit_mode: |
|
131 | 156 |
r += htmltext('<div class="submit-channel-selection" style="display: none;">') |
132 | 157 |
r += htmltext('<h3>%s</h3>') % _('Channel') |
133 | 158 |
r += htmltext('<select>') |
... | ... | |
140 | 165 |
r += htmltext('</select>') |
141 | 166 |
r += htmltext('</div>') |
142 | 167 | |
143 |
if formdata and formdata.submission_context: |
|
144 |
from .management import FormBackOfficeStatusPage |
|
145 |
r += FormBackOfficeStatusPage(self.formdef, formdata).get_extra_context_bar() |
|
146 | ||
147 | 168 |
return r.getvalue() |
148 | 169 | |
149 | 170 |
def create_view_form(self, *args, **kwargs): |
150 |
- |