Exemple #1
0
 def get_ticket_changes(self, req, ticket, action):
     id = "vote_%s_result" % (action,)
     selected = req.args.get(id, "for")
     priorities = list(Priority.select(self.env))
     orig_ticket = Ticket(self.env, ticket.id)
     current_priority = int(Priority(self.env, name=orig_ticket["priority"]).value)
     if selected == "for":
         # priorities are 1-based, not 0-based
         new_value = max(1, current_priority - 1)
     else:
         maxval = max([int(p.value) for p in priorities])
         new_value = min(maxval, current_priority + 1)
     return {"priority": [p.name for p in priorities if int(p.value) == new_value][0]}
Exemple #2
0
 def get_ticket_changes(self, req, ticket, action):
     id = 'vote_%s_result' % (action, )
     selected = req.args.get(id, 'for')
     priorities = list(Priority.select(self.env))
     orig_ticket = Ticket(self.env, ticket.id)
     current_priority = int(Priority(self.env, name=
                                     orig_ticket['priority']).value)
     if selected == 'for':
         # priorities are 1-based, not 0-based
         new_value = max(1, current_priority - 1)
     else:
         maxval = max([int(p.value) for p in priorities])
         new_value = min(maxval, current_priority + 1)
     return {'priority': [p.name for p in priorities
                          if int(p.value) == new_value][0]}
Exemple #3
0
    def get_ticket_changes(self, req, ticket, action):
        id = self.id_for_action % action
        selected = req.args.get(id, self.vote_options[0])
        priorities = list(Priority.select(self.env))
        name_by_val = {int(p.value): p.name for p in priorities}
        ticket_priority_name = ticket._old.get('priority', ticket['priority'])
        ticket_priority = \
            [p for p in priorities if p.name == ticket_priority_name][0]
        if selected == self.vote_options[0]:
            max_val = max(name_by_val)
            new_val = min(max_val, int(ticket_priority.value) + 1)
        else:
            min_val = min(name_by_val)
            new_val = max(min_val, int(ticket_priority.value) - 1)

        return {'priority': name_by_val[new_val]}
	def _do_enter_sticket(self, sticket):
		ticket = Ticket(self.env)
		ticket.values['status'] = 'new'
		ticket.values['reporter'] = 'scheduled'
		ticket.values['summary'] = sticket['summary']
		ticket.values['description'] = sticket['description']

		priorities = Priority.select(self.env)
		for priority in priorities:
			if int(priority.value) == sticket['priority']:
				ticket.values['priority'] = priority.name

		for manipulator in self.ticket_manipulators:
			manipulator.validate_ticket([], ticket)

		# This was largely copied from trac.ticket.web_ui
		ticket.insert()
		try:
			tn = TicketNotifyEmail(self.env)
			tn.notify(ticket, newticket=True)
		except Exception, e:
			error = "Failure sending notification on creation of ticket #%s: %s" % (ticket.id, exception_to_unicode(e))
			self.log.error(error)
			print error
	def process_request(self, req):
		add_stylesheet(req, 'scheduled/css/scheduled.css')
		m = re.match(r'/scheduled(?:/delete/(\d+))?/?$', req.path_info)
		if m:
			tid = m.group(1)
			deleted_message = None
			if tid is not None:
				deleted = False
				for row in self.env.db_query("SELECT summary FROM scheduled WHERE id=%s", str(tid)):
					deleted = True
					with self.env.db_transaction as db:
						cursor = db.cursor()
						cursor.execute("DELETE FROM scheduled WHERE id=%s",
							str(tid))
					deleted_message = "Scheduled ticket succesfully deleted: " + row[0]
				if not deleted:
					deleted_message = "No ticket found with that ID, none deleted"

			tickets = []
			index = 0
			for row in self.env.db_query("SELECT id, summary, description, priority, recurring_days, scheduled_start, enabled FROM scheduled ORDER BY enabled DESC, scheduled_start ASC"):
				ticket = self.row_to_dict(row)
				ticket['__idx__'] = index
				tickets.append(ticket)
				index += 1
			return 'scheduled.html', \
			   {'scheduled_tickets': tickets, \
			   'deleted_message': deleted_message}, None
		m = re.match(r'/scheduled/(?:create/?|alter/(\d+)/?)$', req.path_info)
		if m:
			message = None
			ticket = None
			tid = m.group(1)

			priorities = Priority.select(self.env)

			if tid is None:
				ticket = {}
			else:
				for row in self.env.db_query("SELECT id, summary, description, priority, recurring_days, scheduled_start, enabled FROM scheduled WHERE id=%s", str(tid)):
					ticket = self.row_to_dict(row)
					# microsecond UNIX timestamp to number of days from now
					ticket['scheduled_start'] = ((ticket['scheduled_start'] / 1000000) - time.time()) / (24*3600)
				if ticket is None:
					raise TracError("The given ticket ID was not found.")

			assert ticket is not None, "ticket should be initialised by now"
			
        		if req.method == 'POST':
				try:
					# Save new fields into ticket here, so an exception will not cause
					# the fields to blank
					if 'ticket_id' in req.args:
						ticket['id'] = req.args['ticket_id']
					ticket['summary'] = req.args['field_summary']
					ticket['description'] = req.args['field_description']
					ticket['recurring_days'] = req.args['field_repeatdays']
					ticket['scheduled_start'] = req.args['field_nextdue']
					ticket['enabled'] = req.args['field_enabled'];
					ticket['priority'] = req.args['field_priority'];
					
					if ticket['enabled'] == "1":
						ticket['enabled'] = 1
					else:
						ticket['enabled'] = 0
					
					recurring = int(ticket['recurring_days'])
					if recurring < 0:
						raise Exception('Recurring days must not be negative')
					nextdue = float(ticket['scheduled_start'])
					if nextdue <= 0:
						raise Exception('Next due days must be > 0')
					
					ticket['recurring_days'] = recurring
					ticket['scheduled_start'] = (time.time() + nextdue * 3600 * 24) * 1000000
	
					with self.env.db_transaction as db:
						cursor = db.cursor()
						if 'id' in ticket:
							cursor.execute("""
							    UPDATE scheduled SET summary=%s, description=%s, recurring_days=%s,
							    scheduled_start=%s, enabled=%s, priority=%s WHERE id=%s""",
							    (ticket['summary'], ticket['description'],
							    ticket['recurring_days'], ticket['scheduled_start'], ticket['enabled'],
							    ticket['priority'], ticket['id']))
						else:
							cursor.execute("""
							    INSERT INTO scheduled (summary, description, recurring_days,
							    scheduled_start, enabled, priority) VALUES (%s, %s, %s, %s, %s, %s)""",
							    (ticket['summary'], ticket['description'],
							    ticket['recurring_days'], ticket['scheduled_start'],
							    ticket['enabled'], ticket['priority']))
							ticket['id'] = db.get_last_id(cursor, 'scheduled')
						self.log.warning("Saved into schedule, id=%s", str(ticket['id']))
					req.redirect(req.href('/scheduled'))
				except RequestDone, e:
					raise
				except Exception, e:
					message = str(e)
    def filter_stream(self, req, method, filename, stream, data):

        # this is shamelessly stollen from MasterTickets
        if data and filename in ["report_view.html", "query_results.html", "ticket.html", "query.html"]:
            self._link_parent(req, filename, data)

        # Tickets will be modified to show the child tickets as a list under the 'Description' section.
        if filename == 'ticket.html':

            # Add our own styles for the ticket lists.
            add_stylesheet(req, 'ct/css/childtickets.css')
            add_stylesheet(req, 'common/css/report.css')
            add_stylesheet(req, 'common/css/roadmap.css')
            add_script(req, 'ct/js/childtickets.js')

            # Get the ticket info.
            ticket = data.get('ticket')

            # Modify ticket.html with sub-ticket table, create button, etc...
            # As follows:
            # - If ticket has no child tickets and child tickets are NOT allowed then skip.
            # - If ticket has child tickets and child tickets are NOT allowed (ie. rules changed or ticket type changed after children were assigned),
            #   print list of tickets but do not allow any tickets to be created.
            # - If child tickets are allowed then print list of child tickets or 'No Child Tickets' if non are currently assigned.
            # 
            if ticket and ticket.exists:

                # The additional section on the ticket is built up of (potentially) three parts: header, ticket table, buttons. These
                # are all 'wrapped up' in a 'div' with the 'attachments' id (we'll just pinch this to make look and feel consistent with any
                # future changes!)
                filter = Transformer('//div[@id="ticket"]')
                snippet = tag.div()

                priorities = dict([(p.name, int(p.value)) for p in Priority.select(self.env)])
                # Are there any child tickets to display?
                childtickets = self._get_childtickets(ticket, priorities)

                # Are child tickets allowed?
                childtickets_allowed = self.config.getbool('childtickets', 'parent.%s.allow_child_tickets' % ticket['type'])

                # If there are no childtickets and the ticket should not have any child tickets, we can simply drop out here.
                if not childtickets_allowed and not childtickets:
                    return stream

                # Our 'main' display consists of two divs.
                buttondiv = tag.div()
                tablediv = tag.div()
                progresshtml = tag.div()

                # Test if the ticket has children: If so, then list in pretty table.
                if childtickets:
                    progresshtml = self._construct_progress(req, ticket)
                    tablediv = self._contruct_tickets_table(req, ticket, childtickets, priorities)

                # trac.ini : child tickets are allowed - Set up 'create new ticket' buttons.
                if childtickets_allowed and 'TICKET_CREATE' in req.perm(ticket.resource):
                    buttondiv = self._contruct_buttons(req, ticket)
            
                snippet.append(tag.h2("Child Tickets",class_="foldable"))
                snippet.append(tag.div(progresshtml, tablediv, buttondiv, id="childtickets"))

                return stream | filter.after(snippet)

        return stream