Exemplo 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
Exemplo n.º 2
0
def update_wishlist(cust_id, wishlist_id):
    # """ Update the wishlist name if it exists, otherwise returns not found """
    """
    Update a Wishlist
    This endpoint will update a Wishlist based on the customer id and Wishlist id specified in the path
    ---
    tags:
      - Wishlists
    consumes:
      - application/json
    produces:
      - application/json
    parameters:
      - name: cust_id
        in: path
        description: ID of customer who wants to update his/her wishlist
        required: true
        type: integer
      - name: wishlist_id
        in: path
        description: ID of wishlist to be updated
        required: true
        type: integer
      - in: body
        name: body
        required: true
        schema:
          type: object
          required:
            - name
          properties:
            name:
              type: string
              description: name for the Wishlist
    responses:
      200:
        description: Wishlist updated
        schema:
          id: Wishlist
          properties:
            Customer ID:
              type: integer
              description: ID of customer
            Wishlist:
              type: object
              properties:
                wishlist name:
                  type: string
                  description: the Wishlists's name
                Product list:
                  type: array
                  items:
                    type: string
                  description: the list of products in a Wishlist
      400:
        description: Bad Request (the put data was not valid)
      404:
        description: Not Found (either customer ID or wishlist ID is not valid, no record found)
    """
    # TODO add products changes as well, for now just asses the wishlists
    if Customer.check_custid(cust_id):
        message = Customer.find_by_id(cust_id, wishlist_id)
        if message:
            result = Customer.update(cust_id, wishlist_id, request.get_json())
            res = Customer.find_by_id(cust_id, wishlist_id)
            return make_response(jsonify(res), status.HTTP_200_OK)
        else:
            message = {'Error': 'Wishlist with given ID not found'}
            return make_response(jsonify(message), status.HTTP_404_NOT_FOUND)
    else:
        message = {'Invalid': 'Invalid customer ID'}
        return make_response(jsonify(message), status.HTTP_404_NOT_FOUND)