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