示例#1
0
    def put(self, customer_id):
        '''
        Update an existing customer.
        It is not possible to update the email address or the
        password using this service.

        TODO: Use patch when wtf-forms will be ready

        :param customer_id:
            The id of the customer to update

        Returns a json representation of a customer.
        '''
        form = CustomerForm.from_json(request.get_json())

        if not form.validate_on_submit():
            return jsonify(errors=form.errors)

        customer = CustomerService.get_customer_by_id(customer_id)

        if customer is None:
            return jsonify(msg="Could not find customer")

        customer.data.cellphone = form.cellphone.data
        customer.data.first_name = form.first_name.data
        customer.data.last_name = form.last_name.data
        customer.data.newsletter = form.newsletter.data

        CustomerService.update_customer(customer)

        return jsonify(customer=customer.json)
示例#2
0
    def put(self, customer_id):
        '''
        Update an existing customer.
        It is not possible to update the email address or the
        password using this service.

        TODO: Use patch when wtf-forms will be ready

        :param customer_id:
            The id of the customer to update

        Returns a json representation of a customer.
        '''
        form = CustomerForm.from_json(request.get_json())

        if not form.validate_on_submit():
            return jsonify(errors=form.errors)

        customer = CustomerService.get_customer_by_id(customer_id)

        if customer is None:
            return jsonify(msg="Could not find customer")

        customer.data.cellphone = form.cellphone.data
        customer.data.first_name = form.first_name.data
        customer.data.last_name = form.last_name.data
        customer.data.newsletter = form.newsletter.data

        CustomerService.update_customer(customer)

        return jsonify(customer=customer.json)
示例#3
0
    def put(self):
        '''
        Update the Customer profile

        TODO: when this get merged and available on pypi :
        https://github.com/wtforms/wtforms/pull/147/files

        Sample::

            form.populate_obj(g.customer.data, partial=False)

        Also, consider::

            form.patch_data

        Returns the Customer profile
        '''
        form = ProfileForm.from_json(request.get_json())

        if not form.validate_on_submit():
            return jsonify(errors=form.errors)

        form.populate_obj(g.customer.data)

        CustomerService.update_customer(g.customer)

        return jsonify(customer=g.customer.json)
示例#4
0
    def put(self):
        '''
        Update the Customer profile

        TODO: when this get merged and available on pypi :
        https://github.com/wtforms/wtforms/pull/147/files

        Sample::

            form.populate_obj(g.customer.data, partial=False)

        Also, consider::

            form.patch_data

        Returns the Customer profile
        '''
        form = ProfileForm.from_json(request.get_json())

        if not form.validate_on_submit():
            return jsonify(errors=form.errors)

        form.populate_obj(g.customer.data)

        CustomerService.update_customer(g.customer)

        return jsonify(customer=g.customer.json)
示例#5
0
    def patch(self):
        '''
        Change the password of a customer, requires the old password.

        Returns a success message.
        '''
        form = PasswordForm.from_json(request.get_json())

        #Here we are not using form.validate_on_submit because it
        # will only work for PUT and POST request methods.
        if not form.validate() or not request.method == "PATCH":
            return jsonify(errors=form.errors)

        g.customer.set_password(form.password.data)

        CustomerService.update_customer(g.customer)

        return jsonify(msg="OK")
示例#6
0
    def patch(self):
        '''
        Change the password of a customer, requires the old password.

        Returns a success message.
        '''
        form = PasswordForm.from_json(request.get_json())

        #Here we are not using form.validate_on_submit because it
        # will only work for PUT and POST request methods.
        if not form.validate() or not request.method == "PATCH":
            return jsonify(errors=form.errors)

        g.customer.set_password(form.password.data)

        CustomerService.update_customer(g.customer)

        return jsonify(msg="OK")