def _url_to_json(state_url): """Convert urlencoded state serial to JSON state serial.""" state = parse_qs(state_url) for name, value in state.iteritems(): if isinstance(value, (list, tuple)): for item in value: state[name] = xml_unescape(item) else: state[name] = xml_unescape(value) return json.dumps(state, separators=(',', ':'))
def process_request(self, req): req.perm.require('FORM_EDIT_VAL') try: self.log.debug('UPDATE ARGS:' + str(req.args)) args = dict(req.args) backpath = args.pop('__backpath__', None) context = json.loads( unquote_plus(args.pop('__context__', '[null, null, null]'))) if None in context: # TRANSLATOR: HTTP error message raise HTTPBadRequest(_("__context__ is required")) basever = args.pop('__basever__', None) keep_history = args.pop('__keep_history__', None) track_fields = args.pop('__track_fields__', None) args.pop('__FORM_TOKEN', None) # Ignore. # wipe not JSON serializable arguments rejargs = [] for key, value in args.iteritems(): try: len(value) except AttributeError: rejargs.append(key) pass for key in rejargs: args.pop(key) who = req.authname result = json.dumps(args, separators=(',', ':')) self.save_tracform(context, result, who, basever, keep_history=keep_history, track_fields=track_fields) buffer = 'OK' if backpath is not None: req.send_response(302) req.send_header('Content-Type', 'text/plain') req.send_header('Location', backpath) req.send_header('Content-Length', str(len(buffer))) req.end_headers() req.write(buffer) else: req.send_response(200) req.send_header('Content-Type', 'text/plain') req.send_header('Content-Length', str(len(buffer))) req.end_headers() req.write(buffer) except Exception, e: buffer = str(e) req.send_response(500) req.send_header('Content-type', 'text/plain') req.send_header('Content-Length', str(len(buffer))) req.end_headers() req.write(buffer)
def build_form(self, text): if not self.subform: form_class = self.form_class form_cssid = self.form_cssid or self.subcontext form_name = self.form_name or self.subcontext dest = self.formatter.req.href('/form/update') yield ('<FORM class="printableform" ' + 'method="POST" action=%r' % str(dest) + (form_cssid is not None and ' id="%s"' % form_cssid or '') + (form_name is not None and ' name="%s"' % form_name or '') + (form_class is not None and ' class="%s"' % form_class or '') + '>') yield text if self.allow_submit: # TRANSLATOR: Default submit button label submit_label = self.submit_label or _("Update Form") yield '<INPUT class="buttons" type="submit"' if not self.macro.save_tracform_allowed(self.context[0], self.context[1]): yield ' disabled="disabled"' if self.submit_name: yield ' name=%r' % str(self.submit_name) yield ' value=%r' % xml_escape(submit_label) yield '>' if self.keep_history: yield '<INPUT type="hidden"' yield ' name="__keep_history__" value="yes">' if self.track_fields: yield '<INPUT type="hidden"' yield ' name="__track_fields__" value="yes">' if self.form_updated_on is not None: yield '<INPUT type="hidden" name="__basever__"' yield ' value="' + str(self.form_updated_on) + '">' context = json.dumps( self.context, separators=(',', ':')) yield '<INPUT type="hidden" ' + \ 'name="__context__" value=%r>' % context backpath = self.formatter.req.href(self.formatter.req.path_info) yield '<INPUT type="hidden" ' \ 'name="__backpath__" value=%s>' % str(backpath) form_token = self.formatter.req.form_token yield '<INPUT type="hidden" ' \ 'name="__FORM_TOKEN" value=%r>' % str(form_token) yield '</FORM>' else: yield text
def process_request(self, req): req.perm.require('FORM_EDIT_VAL') try: self.log.debug('UPDATE ARGS:' + str(req.args)) args = dict(req.args) backpath = args.pop('__backpath__', None) context = json.loads(unquote_plus( args.pop('__context__', '[null, null, null]'))) basever = args.pop('__basever__', None) keep_history = args.pop('__keep_history__', None) track_fields = args.pop('__track_fields__', None) args.pop('__FORM_TOKEN', None) # Ignore. if context is None: # TRANSLATOR: HTTP error message raise HTTPBadRequest(_("__context__ is required")) # wipe not JSON serializable arguments rejargs = [] for key, value in args.iteritems(): try: len(value) except AttributeError: rejargs.append(key) pass for key in rejargs: args.pop(key) who = req.authname result = json.dumps(args, separators=(',', ':')) self.save_tracform(context, result, who, basever, keep_history=keep_history, track_fields=track_fields) buffer = 'OK' if backpath is not None: req.send_response(302) req.send_header('Content-Type', 'text/plain') req.send_header('Location', backpath) req.send_header('Content-Length', str(len(buffer))) req.end_headers() req.write(buffer) else: req.send_response(200) req.send_header('Content-Type', 'text/plain') req.send_header('Content-Length', str(len(buffer))) req.end_headers() req.write(buffer) except Exception, e: buffer = str(e) req.send_response(500) req.send_header('Content-type', 'text/plain') req.send_header('Content-Length', str(len(buffer))) req.end_headers() req.write(buffer)
def build_form(self, text): if not self.subform: form_class = self.form_class form_cssid = self.form_cssid or self.subcontext form_name = self.form_name or self.subcontext dest = self.formatter.req.href('/form/update') yield ('<FORM class="printableform" ' + 'method="POST" action=%r' % str(dest) + (form_cssid is not None and ' id="%s"' % form_cssid or '') + (form_name is not None and ' name="%s"' % form_name or '') + (form_class is not None and ' class="%s"' % form_class or '') + '>') yield text if self.allow_submit: # TRANSLATOR: Default submit button label submit_label = self.submit_label or _("Update Form") yield '<INPUT class="buttons" type="submit"' if self.submit_name: yield ' name=%r' % str(self.submit_name) yield ' value=%r' % xml_escape(submit_label) yield '>' if self.keep_history: yield '<INPUT type="hidden"' yield ' name="__keep_history__" value="yes">' if self.track_fields: yield '<INPUT type="hidden"' yield ' name="__track_fields__" value="yes">' if self.form_updated_on is not None: yield '<INPUT type="hidden" name="__basever__"' yield ' value="' + str(self.form_updated_on) + '">' context = json.dumps( self.context, separators=(',', ':')) yield '<INPUT type="hidden" ' + \ 'name="__context__" value=%r>' % context backpath = self.formatter.req.href(self.formatter.req.path_info) yield '<INPUT type="hidden" ' \ 'name="__backpath__" value=%s>' % str(backpath) form_token = self.formatter.req.form_token yield '<INPUT type="hidden" ' \ 'name="__FORM_TOKEN" value=%r>' % str(form_token) yield '</FORM>' else: yield text
def process_request(self, req): req.perm.require('FORM_EDIT_VAL') try: self.log.debug('UPDATE ARGS:' + str(req.args)) args = dict(req.args) backpath = args.pop('__backpath__', None) context = json.loads( unquote_plus(args.pop('__context__', None)) or \ '(None, None, None)') basever = args.pop('__basever__', None) keep_history = args.pop('__keep_history__', None) track_fields = args.pop('__track_fields__', None) args.pop('__FORM_TOKEN', None) # Ignore. if context is None: # TRANSLATOR: HTTP error message raise HTTPBadRequest(_("__context__ is required")) who = req.authname result = json.dumps(args, separators=(',', ':')) self.save_tracform(context, result, who, basever, keep_history=keep_history, track_fields=track_fields) buffer = 'OK' if backpath is not None: req.send_response(302) req.send_header('Content-Type', 'text/plain') req.send_header('Location', backpath) req.send_header('Content-Length', str(len(buffer))) req.end_headers() req.write(buffer) else: req.send_response(200) req.send_header('Content-Type', 'text/plain') req.send_header('Content-Length', str(len(buffer))) req.end_headers() req.write(buffer) except Exception, e: buffer = str(e) req.send_response(500) req.send_header('Content-type', 'text/plain') req.send_header('Content-Length', str(len(buffer))) req.end_headers() req.write(buffer)