示例#1
0
    def get(self,id):
        customer = Customers.get_by_id(id)
        if customer is None:
            raise ObjectNotFound("Customer not found")
        resp = customerSchema.dump(customer)
        print(f"Customer by id: {resp}")

        return resp
示例#2
0
    def delete(self,id):
        #customer = Customers.simple_filter(id)
        customer = Customers.get_by_id(id)

        if customer is None:
            raise ObjectNotFound("Customer not found")
        else:
            customer.delete()
            resp = customerSchema.dump(customer)
            print(f"Preparing delete for Customer:{resp}")

            return resp
示例#3
0
def customers_modify(request, id):

    user = users.get_current_user()

    if request.method == 'GET':
        customer = ndb.Key('Customers', int(id)).get()

        user = {
            'admin': True if (users.is_current_user_admin() == True) else False,
            'userName': user.nickname(),
            'logoutUrl': users.create_logout_url('/')
        }

        resp_data = {
            'customer': customer,
            'action': '修改',
            'clientType': {1: '政府', 2: '企業', 3: '個人'}
        }
        return render(request, "customers/customers-data-handle.html", locals())

    elif request.method == 'POST':

        clientName = request.POST['clientName']
        type = int(request.POST['type'])
        clientAddress = request.POST['clientAddress']
        clientTel = request.POST['clientTel']

        _c = Customers()
        customer = _c.get_by_id(int(id))

        customer.clientName = clientName
        customer.type = type
        customer.clientAddress = clientAddress
        customer.clientTel = clientTel
        customer.put()

        resp_data = {
            'title': '客戶資料',
            'message': '修改成功。 (三秒後自動返回)'
        }

        response = render_to_response('success.html', locals())
        response['refresh'] = '3;URL=/customers/'
        return response
示例#4
0
    def put(self, id):
        customer = Customers.get_by_id(id)
        print(f"Customer id to Update is:{id}")

        if customer is None:
            raise ObjectNotFound("Customer not found")
        else:
            print(f"The original record has:{customer}")

            name = request.json['name']
            lastname = request.json['lastname']
            email = request.json['email']

            customer.name = name
            customer.lastname = lastname
            customer.email = email

            customer.update()

            resp = customerSchema.dump(customer)
            print(f"Updated Customer:{resp}")

            return resp, 201