예제 #1
0
    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 ; """, []))
        if ver < 5:
            self.log.debug(
                "Adding ordinal column to estimate_line_item table.")
            success = success and dbhelper.execute_in_trans(
                self.env,
                (""" ALTER TABLE estimate_line_item ADD COLUMN ordinal integer;""",
                 []))

        if ver < 6:
            self.log.debug("Adding summary column to estimate table.")
            success = success and dbhelper.execute_in_trans(
                self.env,
                (""" ALTER TABLE estimate ADD COLUMN summary varchar(512);""",
                 []))

        # SHOULD BE LAST IN THIS FUNCTION
        if success:
            dbhelper.set_system_value(self.env, dbkey, dbversion)
예제 #2
0
        def line_item_saver():
            saveLineItems = []
            for item in lineItems:
                saveLineItems.append(item.get_sql_pair())
            remSql = removeLineItemsNotInListSql % ','.join(ids)

            sqls = [(remSql, (id, ))]
            sqls.extend(saveLineItems)
            self.env.log.debug("%r" % sqls)
            dbhelper.execute_in_trans( self.env, *sqls)
예제 #3
0
파일: api.py 프로젝트: nyuhuhuu/trachacks
    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 ; """,[]))
        if ver < 5:
            self.log.debug("Adding ordinal column to estimate_line_item table.")
            success = success and dbhelper.execute_in_trans(self.env,
                                                            (""" ALTER TABLE estimate_line_item ADD COLUMN ordinal integer;""", []))

        if ver < 6:
            self.log.debug("Adding summary column to estimate table.")
            success = success and dbhelper.execute_in_trans(self.env,
                                                            (""" ALTER TABLE estimate ADD COLUMN summary varchar(512);""", []))



        # SHOULD BE LAST IN THIS FUNCTION
        if success:
            dbhelper.set_system_value(self.env, dbkey, dbversion)
예제 #4
0
    def save_from_form (self, req, addMessage, estData):

        args = req.args
        tickets = args["tickets"]
        self.log.debug('estimate request-args: %s, %r ' % (args.get("id"), args, ))
        id = args.get("id")
        new_estimate = id == None or id == ''
        if  new_estimate:
            self.log.debug('Saving new estimate')
            sql = estimateInsert
            id = nextEstimateId (self.env)
        else:
            self.log.debug('Saving edited estimate')
            save_diffs = True
            sql = estimateUpdate
        summary = args.get('summary', '').strip()
        save_epoch = to_timestamp(to_datetime(None))
        estimate_args = [args['rate'], args['variability'],
                         args['communication'], tickets,
                         args['comment'], args['diffcomment'], save_epoch, summary, id, ]
        #self.log.debug("Sql:%s\n\nArgs:%s\n\n" % (sql, estimate_args));

        saveEstimate = (sql, estimate_args)

        # 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.  Do this as a function so that if we 
        # create tickets, that change is reflected
        lineItems = self.line_items_from_args(id, args)
        ids = ['-1'] 
        newLineItemId = nextEstimateLineItemId (self.env)
        for item in lineItems:
            if item.is_new(): 
                item.id = newLineItemId
                newLineItemId += 1
            else: 
                ids.append(str(item.id))

        def line_item_saver():
            saveLineItems = []
            for item in lineItems:
                saveLineItems.append(item.get_sql_pair())
            remSql = removeLineItemsNotInListSql % ','.join(ids)

            sqls = [(remSql, (id, ))]
            sqls.extend(saveLineItems)
            self.env.log.debug("%r" % sqls)
            dbhelper.execute_in_trans( self.env, *sqls)

        #addMessage("Deleting NonExistant Estimate Rows: %r - %s" % (sql , id))

        sqlToRun=[]
        if new_estimate:
            sqlToRun.append(lambda: self.notify_new_tickets( req, id, tickets, addMessage))
        else:
            # must be before saving the estimate to get diffs right
            sqlToRun.append(lambda: self.notify_old_tickets(req, id, tickets, addMessage,
                                                            args['diffcomment']))
        sqlToRun.append(saveEstimate)
        if arg_is_true(req, "splitIntoTickets"):
            self.log.debug('Setting saveImmediately for estimate %s' % id)
            estData['saveImmediately'] = 'true';
            sqlToRun.append(lambda:self.create_tickets_for_lineitems (req, id, addMessage, lineItems, summary))
        sqlToRun.append(line_item_saver)

        result = dbhelper.execute_in_trans(self.env, *sqlToRun)
        #will be true or Exception
        if result == True:
            addMessage("Estimate Saved!")
            # if we split our preview is out of date, so we will need
            # to save again immediately, so dont do the redirect
            if arg_is_true(req, "splitIntoTickets"): 
                return id 
            if arg_is_true(req, "shouldRedirect"):
                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)