def _context_to_resource(env, context): """Find parent realm and resource_id and optional TracForms subcontext. Some guesswork is knowingly involved here to finally overcome previous potentially ambiguous contexts by distinct resource parameters. """ realm, resource_path = resource_from_page(env, context) subcontext = None if resource_path is not None: # ambiguous: ':' could be part of resource_id or subcontext or # the start of subcontext segments = re.split(':', resource_path) id = '' resource_id = None while len(segments) > 0: id += segments.pop(0) # guess: shortest valid resource_id is parent, # the rest is a TracForms subcontext if resource_exists(env, Resource(realm, id)): resource_id = id subcontext = ':'.join(segments) break id += ':' # valid resource_id in context NOT FOUND if resource_id is None: resource_id = resource_path else: # realm in context NOT FOUND resource_id = context realm = '' return realm, resource_id, subcontext
def post_process_request(self, req, template, data, content_type): env = self.env page = req.path_info realm, resource_id = resource_from_page(env, page) # break (recursive) search for form in forms realm if tfpageRE.match(page) == None and resource_id is not None: if page == '/wiki' or page == '/wiki/': page = '/wiki/WikiStart' form = Form(env, realm, resource_id) if 'FORM_VIEW' in req.perm(form.resource): if len(form.siblings) == 0: # no form record found for this parent resource href = req.href.form() return (template, data, content_type) elif form.resource.id is not None: # single form record found href = req.href.form(form.resource.id) else: # multiple form records found href = req.href.form(action='select', realm=realm, resource_id=resource_id) add_ctxtnav(req, _("Form details"), href=href, title=_("Review form data")) elif page.startswith('/form') and not resource_id == '': form = Form(env, form_id=resource_id) parent = form.resource.parent if len(form.siblings) > 1: href = req.href.form(action='select', realm=parent.realm, resource_id=parent.id) add_ctxtnav(req, _("Back to forms list"), href=href) return (template, data, content_type)
def execute(self): formatter = self.formatter args = self.args name = self.name # Look in the formatter req object for evidence we are executing. self.subform = getattr(formatter.req, type(self).__name__, False) if not self.subform: setattr(formatter.req, type(self).__name__, True) self.env = dict(getattr(formatter.req, 'tracform_env', ())) # Setup preliminary context self.page = formatter.req.path_info if self.page == '/wiki' or self.page == '/wiki/': self.page = '/wiki/WikiStart' realm, resource_id = resource_from_page(formatter.env, self.page) # Remove leading comments and process commands. textlines = [] errors = [] srciter = iter(args.split('\n')) for line in srciter: if line[:1] == '#': # Comment or operation. line = line.strip()[1:] if line[:1] == '!': # It's a command, parse the arguments... kw = {} args = list(self.getargs(line[1:], kw)) if len(args): cmd = args.pop(0) fn = getattr(self, 'cmd_' + cmd.lower(), None) if fn is None: errors.append( _("ERROR: No TracForms command '%s'" % cmd)) else: try: fn(*args, **kw) except FormError, e: errors.append(str(e)) except Exception, e: errors.append(traceback.format_exc())