def process_request(self, req): if req.method != 'POST': raise HTTPBadRequest(_("Only POST is supported")) query = Query(self.env, constraints=QueryModule(self.env)._get_constraints(req), cols=req.args['col'], desc=req.args.get('desc', 0), group=req.args['group'], groupdesc=req.args.get('groupdesc', 0), max=req.args['max'], order=req.args['order']) req.session['default_user_query'] = query.get_href(req.href) add_notice(req, _("Your default query has been changed")) # Let the query system handle the request req.redirect(query.get_href(req.href))
def process_request(self, req): req.perm.assert_permission('TICKET_VIEW') constraints = self._get_constraints(req) if not constraints and not 'order' in req.args: # If no constraints are given in the URL, use the default ones. if req.authname and req.authname != 'anonymous': qstring = self.default_query user = req.authname else: email = req.session.get('email') name = req.session.get('name') qstring = self.default_anonymous_query user = email or name or None if user: qstring = qstring.replace('$USER', user) self.log.debug('TasklistPlugin: Using default query: %s', qstring) constraints = Query.from_string(self.env, qstring).constraints # Ensure no field constraints that depend on $USER are used # if we have no username. for field, vals in constraints.items(): for val in vals: if val.endswith('$USER'): del constraints[field] cols = req.args.get('col') if not cols: cols = self.default_cols cols.append(self.field_name) if isinstance(cols, basestring): cols = [cols] form_cols = copy.copy(cols) # Since we don't show 'id' or the tasklist_field as an option # to the user, we need to re-insert it here. if cols and 'id' not in cols: cols.insert(0, 'id') if cols and self.field_name not in cols: cols.insert(0, self.field_name) rows = req.args.get('row', []) if isinstance(rows, basestring): rows = [rows] q = Query(self.env, constraints=constraints, cols=cols) query = Query(self.env, req.args.get('report'), constraints, cols, req.args.get('order'), 'desc' in req.args, req.args.get('group'), 'groupdesc' in req.args, 'verbose' in req.args, rows, req.args.get('limit')) if 'update' in req.args: # Reset session vars for var in ('query_constraints', 'query_time', 'query_tickets'): if var in req.session: del req.session[var] req.redirect(q.get_href(req.href).replace('/query', '/tasklist')) if 'add' in req.args: req.perm.require('TICKET_CREATE') t = Ticket(self.env) if req.method == 'POST' and 'field_owner' in req.args and \ 'TICKET_MODIFY' not in req.perm: del req.args['field_owner'] self._populate(req, t) reporter_id = req.args.get('field_reporter') or \ get_reporter_id(req, 'author') t.values['reporter'] = reporter_id valid = None valid = self._validate_ticket(req, t) if valid: t.insert() # Notify try: tn = TicketNotifyEmail(self.env) tn.notify(t, newticket=True) except Exception, e: self.log.exception( "Failure sending notification on creation of " "ticket #%s: %s" % (t.id, e)) req.redirect(q.get_href(req.href).replace('/query', '/tasklist'))
def process_request(self, req): req.perm.assert_permission('TICKET_VIEW') constraints = self._get_constraints(req) if not constraints and not 'order' in req.args: # If no constraints are given in the URL, use the default ones. if req.authname and req.authname != 'anonymous': qstring = self.default_query user = req.authname else: email = req.session.get('email') name = req.session.get('name') qstring = self.default_anonymous_query user = email or name or None if user: qstring = qstring.replace('$USER', user) self.log.debug('TasklistPlugin: Using default query: %s', qstring) constraints = Query.from_string(self.env, qstring).constraints # Ensure no field constraints that depend on $USER are used # if we have no username. for field, vals in constraints.items(): for val in vals: if val.endswith('$USER'): del constraints[field] cols = req.args.get('col') if not cols: cols = self.default_cols cols.append(self.field_name) if isinstance(cols, basestring): cols = [cols] form_cols = copy.copy(cols) # Since we don't show 'id' or the tasklist_field as an option # to the user, we need to re-insert it here. if cols and 'id' not in cols: cols.insert(0, 'id') if cols and self.field_name not in cols: cols.insert(0, self.field_name) rows = req.args.get('row', []) if isinstance(rows, basestring): rows = [rows] q = Query(self.env, constraints=constraints, cols=cols) query = Query(self.env, req.args.get('report'), constraints, cols, req.args.get('order'), 'desc' in req.args, req.args.get('group'), 'groupdesc' in req.args, 'verbose' in req.args, rows, req.args.get('limit')) if 'update' in req.args: # Reset session vars for var in ('query_constraints', 'query_time', 'query_tickets'): if var in req.session: del req.session[var] req.redirect(q.get_href(req.href).replace('/query', '/tasklist')) if 'add' in req.args: req.perm.require('TICKET_CREATE') t = Ticket(self.env) if req.method == 'POST' and 'field_owner' in req.args and \ 'TICKET_MODIFY' not in req.perm: del req.args['field_owner'] self._populate(req, t) reporter_id = req.args.get('field_reporter') or \ get_reporter_id(req, 'author') t.values['reporter'] = reporter_id valid = None valid = self._validate_ticket(req, t) if valid: t.insert() # Notify try: tn = TicketNotifyEmail(self.env) tn.notify(t, newticket=True) except Exception, e: self.log.exception("Failure sending notification on creation of " "ticket #%s: %s" % (t.id, e)) req.redirect(q.get_href(req.href).replace('/query', '/tasklist'))
def process_request(self, req): req.perm.assert_permission('TICKET_VIEW') constraints = self._get_constraints(req) if not constraints and not req.args.has_key('order'): # avoid displaying all tickets when the query module is invoked # with no parameters. Instead show only open tickets, possibly # associated with the user constraints = {'status': ('new', 'assigned', 'reopened')} if req.authname and req.authname != 'anonymous': constraints['owner'] = (req.authname,) else: email = req.session.get('email') name = req.session.get('name') if email or name: constraints['cc'] = ('~%s' % email or name,) query = Query(self.env, constraints, req.args.get('order'), req.args.has_key('desc'), req.args.get('group'), req.args.has_key('groupdesc'), req.args.has_key('verbose')) if req.args.has_key('update'): # Reset session vars for var in ('query_constraints', 'query_time', 'query_tickets'): if req.session.has_key(var): del req.session[var] req.redirect(query.get_href()) add_link(req, 'alternate', query.get_href('rss'), 'RSS Feed', 'application/rss+xml', 'rss') add_link(req, 'alternate', query.get_href('csv'), 'Comma-delimited Text', 'text/plain') add_link(req, 'alternate', query.get_href('tab'), 'Tab-delimited Text', 'text/plain') constraints = {} for k, v in query.constraints.items(): constraint = {'values': [], 'mode': ''} for val in v: neg = val.startswith('!') if neg: val = val[1:] mode = '' if val[:1] in ('~', '^', '$'): mode, val = val[:1], val[1:] constraint['mode'] = (neg and '!' or '') + mode constraint['values'].append(val) constraints[k] = constraint req.hdf['query.constraints'] = constraints format = req.args.get('format') if format == 'rss': self.display_rss(req, query) return 'query_rss.cs', 'application/rss+xml' elif format == 'csv': self.display_csv(req, query) elif format == 'tab': self.display_csv(req, query, '\t') else: self.display_html(req, query) return 'query.cs', None
def process_request(self, req): req.perm.assert_permission("TICKET_VIEW") if not self.env.config.has_option("ticket-custom", self.field_name): raise TracError( 'Configuration error: the custom ticket field "%s" has not been defined ' "in the [ticket-custom] section of trac.ini. See the documentation " "for more info on configuring the TaskListPlugin." % self.field_name ) constraints = self._get_constraints(req) if not constraints and not "order" in req.args: # If no constraints are given in the URL, use the default ones. if req.authname and req.authname != "anonymous": qstring = self.default_query user = req.authname else: email = req.session.get("email") name = req.session.get("name") qstring = self.default_anonymous_query user = email or name or None if user: qstring = qstring.replace("$USER", user) self.log.debug("TasklistPlugin: Using default query: %s", qstring) constraints = Query.from_string(self.env, qstring).constraints # Ensure no field constraints that depend on $USER are used # if we have no username. # It may be possible to just use constraints[0] here, rather than # iterating over constraints. See th#6336. for constraint in constraints: for field, vals in constraint.items(): for val in vals: if val.endswith("$USER"): del constraint[field] cols = req.args.get("col") if not cols: cols = self.default_cols cols.append(self.field_name) if isinstance(cols, basestring): cols = [cols] form_cols = copy.copy(cols) # Since we don't show 'id' or the tasklist_field as an option # to the user, we need to re-insert it here. if cols and "id" not in cols: cols.insert(0, "id") if cols and self.field_name not in cols: cols.insert(0, self.field_name) rows = req.args.get("row", []) if isinstance(rows, basestring): rows = [rows] q = Query(self.env, constraints=constraints, cols=cols) query = Query( self.env, req.args.get("report"), constraints, cols, req.args.get("order"), "desc" in req.args, req.args.get("group"), "groupdesc" in req.args, "verbose" in req.args, rows, req.args.get("limit"), ) if "update" in req.args: # Reset session vars for var in ("query_constraints", "query_time", "query_tickets"): if var in req.session: del req.session[var] req.redirect(q.get_href(req.href).replace("/query", "/tasklist")) if "add" in req.args: req.perm.require("TICKET_CREATE") t = Ticket(self.env) if req.method == "POST" and "field_owner" in req.args and "TICKET_MODIFY" not in req.perm: del req.args["field_owner"] self._populate(req, t) reporter_id = req.args.get("field_reporter") or get_reporter_id(req, "author") t.values["reporter"] = reporter_id valid = None valid = self._validate_ticket(req, t) if valid: t.insert() # Notify try: tn = TicketNotifyEmail(self.env) tn.notify(t, newticket=True) except Exception, e: self.log.exception("Failure sending notification on creation of " "ticket #%s: %s" % (t.id, e)) req.redirect(q.get_href(req.href).replace("/query", "/tasklist"))