def _insert_report(self, next_id, title, author, description, query, uuid, maingroup, subgroup, version, ordering): """ Adds a row the custom_report_table """ self.log.debug("Inserting new report '%s' with uuid '%s'" % (title, uuid)) dbhelper.execute_in_trans( self.env, ("DELETE FROM custom_report WHERE uuid=%s", (uuid,)), ("INSERT INTO report (id, title, author, description, query) " \ "VALUES (%s, %s, %s, %s, %s)", (next_id, title, author, description, query)), ("INSERT INTO custom_report (id, uuid, maingroup, subgroup, version, ordering) " \ "VALUES (%s, %s, %s, %s, %s, %s)", (next_id, uuid, maingroup, subgroup, version, ordering))) if type(self.env.get_read_db().cnx ) == trac.db.postgres_backend.PostgreSQLConnection: self.log.debug( "Attempting to increment sequence (only works in postgres)") try: dbhelper.execute_in_nested_trans( self.env, "update_seq", ("SELECT nextval('report_id_seq');", [])) self.log.debug("Sequence updated") except: self.log.debug( "Sequence failed to update, perhaps you are not running postgres?" )
def _update_report (self, id, title, author, description, query, maingroup, subgroup, version): """Updates a report and its row in the custom_report table """ self.log.debug("Updating report '%s' with to version %s" % (title, version)) dbhelper.execute_in_trans( self.env, ("UPDATE report SET title=%s, author=%s, description=%s, query=%s " \ "WHERE id=%s", (title, author, description, query, id)), ("UPDATE custom_report SET version=%s, maingroup=%s, subgroup=%s " "WHERE id=%s", (version, maingroup, subgroup, id)))
def _update_report(self, id, title, author, description, query, maingroup, subgroup, version): """Updates a report and its row in the custom_report table """ self.log.debug("Updating report '%s' with to version %s" % (title, version)) dbhelper.execute_in_trans( self.env, ("UPDATE report SET title=%s, author=%s, description=%s, query=%s " \ "WHERE id=%s", (title, author, description, query, id)), ("UPDATE custom_report SET version=%s, maingroup=%s, subgroup=%s " "WHERE id=%s", (version, maingroup, subgroup, id)))
def upgrade_environment(self, db): """Actually perform an environment upgrade. Implementations of this method should not commit any database transactions. This is done implicitly after all participants have performed the upgrades they need without an error being raised. """ success = True ver = dbhelper.get_system_value(self.env, dbkey) ver = (ver and int(ver)) or 0 self.log.debug("Estimator about to upgrade from ver:%s" % ver) if ver < 1: self.log.debug("Creating Estimate and Estimate_Line_Item tables (Version 1)") success = success and dbhelper.execute_in_trans( self.env, ( """CREATE TABLE estimate( id integer PRIMARY KEY, rate DECIMAL, variability DECIMAL, communication DECIMAL, tickets VARCHAR(512), comment text )""", [], ), ( """CREATE TABLE estimate_line_item( id integer PRIMARY KEY, estimate_id integer, description VARCHAR(2048), low DECIMAL, high DECIMAL )""", [], ), ) # ver 2 might have left the database in an invalid state. if ver < 3: self.log.debug("Altering estimate adding diffcoment 2") success = success and dbhelper.execute_in_trans( self.env, (""" ALTER TABLE estimate ADD COLUMN diffcomment text ; """, []) ) if ver < 4: self.log.debug("Adding save date to estimates (Version 3)") success = success and dbhelper.execute_in_trans( self.env, (""" ALTER TABLE estimate ADD COLUMN saveepoch int ; """, []) ) # SHOULD BE LAST IN THIS FUNCTION if success: dbhelper.set_system_value(self.env, dbkey, dbversion)
def upgrade_environment(self, db): """Actually perform an environment upgrade. Implementations of this method should not commit any database transactions. This is done implicitly after all participants have performed the upgrades they need without an error being raised. """ success = True ver = dbhelper.get_system_value(self.env, dbkey) self.log.debug('Estimator about to upgrade from ver:%s' % ver) if ver < 1: self.log.debug( 'Creating Estimate and Estimate_Line_Item tables (Version 1)') success = success and dbhelper.execute_in_trans( self.env, ("""CREATE TABLE estimate( id integer PRIMARY KEY, rate DECIMAL, variability DECIMAL, communication DECIMAL, tickets VARCHAR(512), comment VARCHAR(8000) )""", []), ("""CREATE TABLE estimate_line_item( id integer PRIMARY KEY, estimate_id integer, description VARCHAR(2048), low DECIMAL, high DECIMAL )""", [])) # SHOULD BE LAST IN THIS FUNCTION if success: dbhelper.set_system_value(self.env, dbkey, dbversion)
def upgrade_environment(self, db): """Actually perform an environment upgrade. Implementations of this method should not commit any database transactions. This is done implicitly after all participants have performed the upgrades they need without an error being raised. """ success = True ver = dbhelper.get_system_value(self.env, dbkey) self.log.debug('Estimator about to upgrade from ver:%s' % ver) if ver < 1: self.log.debug('Creating Estimate and Estimate_Line_Item tables (Version 1)') success = success and dbhelper.execute_in_trans(self.env, ("""CREATE TABLE estimate( id integer PRIMARY KEY, rate DECIMAL, variability DECIMAL, communication DECIMAL, tickets VARCHAR(512), comment VARCHAR(8000) )""",[]), ("""CREATE TABLE estimate_line_item( id integer PRIMARY KEY, estimate_id integer, description VARCHAR(2048), low DECIMAL, high DECIMAL )""",[])) # SHOULD BE LAST IN THIS FUNCTION if success: dbhelper.set_system_value(self.env, dbkey, dbversion)
def _insert_report (self, next_id, title, author, description, query, uuid, maingroup, subgroup, version, ordering): """ Adds a row the custom_report_table """ self.log.debug("Inserting new report '%s' with uuid '%s'" % (title,uuid)) dbhelper.execute_in_trans( self.env, ("DELETE FROM custom_report WHERE uuid=%s", (uuid,)), ("INSERT INTO report (id, title, author, description, query) " \ "VALUES (%s, %s, %s, %s, %s)", (next_id, title, author, description, query)), ("INSERT INTO custom_report (id, uuid, maingroup, subgroup, version, ordering) " \ "VALUES (%s, %s, %s, %s, %s, %s)", (next_id, uuid, maingroup, subgroup, version, ordering))) if type(self.env.get_read_db().cnx) == trac.db.postgres_backend.PostgreSQLConnection: self.log.debug("Attempting to increment sequence (only works in postgres)") try: dbhelper.execute_in_nested_trans(self.env, "update_seq", ("SELECT nextval('report_id_seq');",[])); self.log.debug("Sequence updated"); except: self.log.debug("Sequence failed to update, perhaps you are not running postgres?");
def save_from_form (self, req, addMessage): #try: args = req.args tickets = args["tickets"] if args.has_key("id"): id = args['id'] else: id = None old_tickets = None if id == None or id == '' : self.log.debug('Saving new estimate') sql = estimateInsert id = nextEstimateId (self.env) else: self.log.debug('Saving edited estimate') old_tickets = self.notify_old_tickets(req, id, addMessage, req.authname, args['diffcomment']) sql = estimateUpdate self.log.debug('Old Tickets to Update: %r' % old_tickets) save_epoch = int(time.mktime(datetime.datetime.now().timetuple())) estimate_args = [args['rate'], args['variability'], args['communication'], tickets, args['comment'], args['diffcomment'], save_epoch, id] self.log.debug("Sql:%s\n\nArgs:%s\n\n" % (sql, estimate_args)); saveEstimate = (sql, estimate_args) saveLineItems = [] newLineItemId = nextEstimateLineItemId (self.env) # we want to delete any rows that were not included in the form request # we will not use -1 as a valid id, so this will allow us to use the same sql reguardless of anything else ids = ['-1'] lineItems = self.line_item_hash_from_args(args).items() lineItems.sort() for item in lineItems: desc, low, high = (item[1]['description'], convertfloat(item[1]['low']), convertfloat(item[1]['high'])) itemId = item[0] if int(itemId) < 400000000:# new ids on the HTML are this number and above ids.append(str(itemId)) sql = lineItemUpdate else: itemId = newLineItemId newLineItemId += 1 sql = lineItemInsert itemargs = [id, desc, low, high, itemId] saveLineItems.append((sql, itemargs)) sql = removeLineItemsNotInListSql % ','.join(ids) #addMessage("Deleting NonExistant Estimate Rows: %r - %s" % (sql , id)) sqlToRun = [saveEstimate, (sql, [id]),] sqlToRun.extend(saveLineItems) if old_tickets: sqlToRun.extend(old_tickets) result = dbhelper.execute_in_trans(self.env, *sqlToRun) #will be true or Exception if result == True: if self.notify_new_tickets( req, id, tickets, addMessage): addMessage("Estimate Saved!") if req.args.has_key('shouldRedirect') and req.args["shouldRedirect"] == "True": ticket = args["tickets"].split(',')[0] req.redirect("%s/%s" % (req.href.ticket(), ticket)) else: req.redirect(req.href.Estimate()+'?id=%s&justsaved=true'%id) else: addMessage("Failed to save! %s" % result)
def save_from_form(self, req, addMessage): #try: args = req.args tickets = args["tickets"] if args.has_key("id"): id = args['id'] else: id = None old_tickets = None if id == None or id == '': self.log.debug('Saving new estimate') sql = estimateInsert id = nextEstimateId(self.env) else: self.log.debug('Saving edited estimate') old_tickets = self.notify_old_tickets(req, id, addMessage, req.authname, args['diffcomment']) sql = estimateUpdate self.log.debug('Old Tickets to Update: %r' % old_tickets) save_epoch = int(time.mktime(datetime.datetime.now().timetuple())) estimate_args = [ args['rate'], args['variability'], args['communication'], tickets, args['comment'], args['diffcomment'], save_epoch, id ] self.log.debug("Sql:%s\n\nArgs:%s\n\n" % (sql, estimate_args)) saveEstimate = (sql, estimate_args) saveLineItems = [] newLineItemId = nextEstimateLineItemId(self.env) # we want to delete any rows that were not included in the form request # we will not use -1 as a valid id, so this will allow us to use the same sql reguardless of anything else ids = ['-1'] lineItems = self.line_item_hash_from_args(args).items() lineItems.sort() for item in lineItems: desc, low, high = (item[1]['description'], convertfloat(item[1]['low']), convertfloat(item[1]['high'])) itemId = item[0] if int( itemId ) < 400000000: # new ids on the HTML are this number and above ids.append(str(itemId)) sql = lineItemUpdate else: itemId = newLineItemId newLineItemId += 1 sql = lineItemInsert itemargs = [id, desc, low, high, itemId] saveLineItems.append((sql, itemargs)) sql = removeLineItemsNotInListSql % ','.join(ids) #addMessage("Deleting NonExistant Estimate Rows: %r - %s" % (sql , id)) sqlToRun = [ saveEstimate, (sql, [id]), ] sqlToRun.extend(saveLineItems) if old_tickets: sqlToRun.extend(old_tickets) result = dbhelper.execute_in_trans(self.env, *sqlToRun) #will be true or Exception if result == True: if self.notify_new_tickets(req, id, tickets, addMessage): addMessage("Estimate Saved!") if req.args.has_key('shouldRedirect' ) and req.args["shouldRedirect"] == "True": ticket = args["tickets"].split(',')[0] req.redirect("%s/%s" % (req.href.ticket(), ticket)) else: req.redirect(req.href.Estimate() + '?id=%s&justsaved=true' % id) else: addMessage("Failed to save! %s" % result)