Ejemplo n.º 1
0
    def process_request(self, req):

        db = self.env.get_db_cnx()

        if req.method == 'POST':
            if not req.args.get('name') or not req.args.get('mininame'):
                raise TracError(_('Name and Label are required fields.'))

            cust = Customer(self.env, req.args.get('id')) 
            cust.name = req.args.get('name')
            cust.mininame = req.args.get('mininame')
            cust.curmilestone = req.args.get('curmilestone')

            if req.args.get('submit') == "add":
                cust.insert(db)
                add_notice(req, _('The customer %(name)s has been added.', name=cust.name))

            elif req.args.get('submit') == "update":
                cust.update(db)
                add_notice(req, _('The customer %(name)s has been updated.', name=cust.name))
              
            req.redirect(req.href.customers(None))
        else:
            data = {}
            cursor = db.cursor()
            cursor.execute('select id, name, mininame, curmilestone from customer order by mininame')
            customers = []
            for id, name, mininame, curmilestone in cursor:
                cust = Customer(self.env)
                cust.id = id
                cust.name = name
                cust.mininame = mininame
                cust.curmilestone = curmilestone
                customers.append(cust)

            data.update({'customers': customers})
            data.update({'milestones': model.Milestone.select(self.env, db=db)})

            if req.args.get('id'):
                data.update({'customer': Customer(self.env, req.args.get('id'))})
            else:
                data.update({'customer': None})

            return 'customers.html', data, None
Ejemplo n.º 2
0
def main():
    customers = []
    # Manually Generate The first 'Customer' with completely random values.
    customers.append(Customer())
    customers[0].interArrival = None
    customers[0].state = "In Service"

    # this loop generates 4 other 'Customers' and appends them to 'customers' list.
    for i in range(1, 8):
        new = Customer()
        _arrivalTime = customers[i - 1].arrivalTime + new.interArrival
        _serviceBegin = max(customers[i - 1].serviceEnds, _arrivalTime)
        _serviceEnd = _serviceBegin + new.serviceDuration

        new.arrivalTime = _arrivalTime
        new.serviceBegin = _serviceBegin
        new.serviceEnds = _serviceEnd
        new.id = i + 1

        # check for the customer state.
        if new.arrivalTime < new.serviceBegin:
            new.state = new.serviceBegin - new.arrivalTime
        else:
            new.state = 0

        customers.append(new)
        """
        for customer in customers:
            print "interArrival => " + str(customer.interArrival) + \
             "\t| arrivalTime => " + str(customer.arrivalTime) +\
             "\t| Service Begin => " + str(customer.serviceBegin) +\
             "\t| Service Duration => " + str(customer.serviceDuration) +\
             "\t| Service End => " + str(customer.serviceEnds)
        """
    for cust in customers:
        cust.points = []
        start = cust.arrivalTime
        end = cust.serviceEnds
        for i in range(start, end):
            obj = {"x": i + 1, "y": 1}
            cust.points.append(obj)

    return render_template('index.html', customers=customers)