示例#1
0
    def post(self,request,address_id):
        user_id = request.session['user_id']
        username = request.session['username'] 
        eaddress = EditAddressForm(request.POST)
        apayment = AddPaymentInfoForm2(request.POST)
        daddress = DeleteAddressForm(request.POST)
        address = self.cadao.get_byid(address_id)
        user_id = address.customer_id
        context = {}
        if 'edit-address' in request.POST:
            if eaddress.is_valid():
                a = CustomerAddress()
                a.address_id = address_id
                a.customer_id = user_id
                a.street = eaddress.cleaned_data['street']
                a.city = eaddress.cleaned_data['city']
                a.state_code = eaddress.cleaned_data['state_code']
                a.zip_code = eaddress.cleaned_data['zip_code']
                a.address_type = eaddress.cleaned_data['address_type']
                self.cadao.update(a)
                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username'] 
            return redirect(reverse(('customeraddress'), kwargs={'address_id': address_id}))

        elif 'add-card' in request.POST:
            if apayment.is_valid():
                p = PaymentInfo()
                p.card_number = apayment.cleaned_data['card_number']
                p.cvc = apayment.cleaned_data['cvc']
                p.expir_date = apayment.cleaned_data['expir_date']  
                p.card_issuer = apayment.cleaned_data['card_issuer']
                p.customer_id = user_id
                p.billing_address.address_id = address_id
                self.padao.create(p)
                
                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username'] 
            return redirect(reverse(('customeraddress'), kwargs={'address_id': address_id}))

        elif 'delete-address' in request.POST: 
            if daddress.is_valid():
                a = CustomerAddress()
                a.address_id = daddress.cleaned_data['address_id']
                a.customer_id = user_id
                self.cadao.delete(a)
                
                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username'] 
            return redirect(reverse('customeraccount')) 
        else:
            return redirect(reverse(('customeraddress'), kwargs={'address_id': address_id}))
示例#2
0
    def get(self,request):
        context={}
        user_id =  request.session['user_id'] 
        username = request.session['username'] 
        user = self.udao.get_byid(user_id)
        customer = self.cdao.get_byid(user_id)
        cusadd =CustomerAddress()
        cusadd.customer_id = user_id
        caddress = self.cadao.get_all_addresses_by_customer_id(user_id)
        bill_addresses = self.cadao.get_by_customer_and_type(user_id, "Billing")

        bill_address_choices = []
        for address in bill_addresses:
            address_val = (str(address.address_id), str(address.street) + " " + str(address.city) + ", " 
                    + str(address.state_code) + " " + str(address.zip_code))
            bill_address_choices.append(address_val)
        num_bill_address = len(bill_address_choices)
        aaddress = AddAddressForm2()
        addcard = AddPaymentInfoForm(bill_address_choices=bill_address_choices)
        context['addcard'] = addcard
        context['aaddress'] = aaddress
        context['user_id'] = request.session['user_id']
        context['username'] = request.session['username'] 
        context['num_bill_address'] = num_bill_address
        
        return render(request, self.template_name,context)
示例#3
0
 def post(self,request,card_id):
     user_id = request.session['user_id']
     username = request.session['username'] 
     card = self.pdao.get_byid(card_id)
     context={}
     eaddress = AddAddressForm2(request.POST)
 
     if 'update-address' in request.POST:
         if eaddress.is_valid():
             a = CustomerAddress()
             a.address_id = card.billing_address.address_id
             a.customer_id = user_id
             a.street = eaddress.cleaned_data['street']
             a.city = eaddress.cleaned_data['city']
             a.state_code = eaddress.cleaned_data['state_code']
             a.zip_code = eaddress.cleaned_data['zip_code']
             a.address_type = 'Billing'
             self.cadao.update(a)
             context['user_id'] = request.session['user_id'],
             context['username'] = request.session['username'] 
         return redirect(reverse(('customercard'),kwargs={'card_id':card_id}))
     else:
         context['user_id'] = request.session['user_id'],
         context['username'] = request.session['username'] 
         return redirect(reverse(('customercard'),kwargs={'card_id':card_id}))
    def get_by_customer_and_type(self, p_customer_id, p_address_type):
        try:
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()
            args = (p_customer_id, p_address_type)
            cursor.callproc('getAddressByCustomerAndType', args)
            all_customer_address = []

            for result in cursor.stored_results():
                customers = result.fetchall()

            for x in customers:
                currentAddress = CustomerAddress()
                currentAddress.address_id = x[0]
                currentAddress.street = x[1]
                currentAddress.city = x[2]
                currentAddress.state_code = x[3]
                currentAddress.zip_code = x[4]
                currentAddress.customer_id = x[5]
                currentAddress.address_type = x[6]
                all_customer_address.append(currentAddress)

            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)
        return all_customer_address
    def get_byid(self, id):
        try:
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()
            args = [id]
            cursor.callproc('getAddressByAddressID', args)
            currentAddress = CustomerAddress()

            for result in cursor.stored_results():
                customers = result.fetchall()

            for x in customers:

                currentAddress.address_id = x[0]
                currentAddress.street = x[1]
                currentAddress.city = x[2]
                currentAddress.state_code = x[3]
                currentAddress.zip_code = x[4]
                currentAddress.customer_id = x[5]
                currentAddress.address_type = x[6]

            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)
        return currentAddress
示例#6
0
    def get_all_CAddress(self):
        try:
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()
            cursor.callproc('getAllCustomerInfo')
            all_customer_info = []

            for result in cursor.stored_results():
                customers = result.fetchall()

            for x in customers:
                currentinfo = CustomerInfo()
                currentinfo.customer_id = x[0]
                currentinfo.work_phone = x[1]
                currentinfo.home_phone = x[2]
                a = CustomerAddress()
                a.address_id = x[3]
                a.street = x[4]
                a.city = x[5]
                a.state_code = x[6]
                a.address_type = x[8]
                currentinfo.set_address(a)
                all_customer_info.append(currentinfo)
                cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)

        return all_customer_info
示例#7
0
 def __init__(self):
     self.order_id = None
     self.date_ordered = None
     self.total_price = None
     self.discount = None
     self.customer = User()
     self.shipping_address = CustomerAddress()
     self.card = PaymentInfo()
     self.status = None
 def __init__(self):
     self.card_id = None
     self.card_number = None
     self.last_four = None
     self.cvc = None
     self.expir_date = None
     self.card_issuer = None
     self.customer_id = None
     self.billing_address = CustomerAddress()
示例#9
0
    def get_byid(self, order_id):
        try:
            # Setup connection to the DB
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()
            order = None
            args = [order_id]

            cadao = CustomerAddressDao()
            pdao = PaymentInfoDao()
            # Calls the stored procedure
            cursor.callproc('getRetailOrderByOrderID', args)

            # This loop iterates through the resultsets
            for result in cursor.stored_results():
                # This loop iterates through the rows in each resultset
                for x in result.fetchall():
                    order = RetailOrder()
                    order.order_id = x[0]
                    order.date_ordered = x[1]
                    order.discount = x[2]
                    order.total_price = x[3]
                    order.status = x[4]

                    u = User()
                    u.id = x[5]
                    u.first_name = x[6]
                    u.last_name = x[7]
                    order.customer = u

                    p = PaymentInfo()
                    p.card_id = x[8]
                    p.last_four = x[9]
                    p.card_issuer = x[10]
                    order.card = p

                    a = CustomerAddress()
                    a.address_id = x[11]
                    a.street = x[12]
                    a.city = x[13]
                    a.state_code = x[14]
                    a.zip_code = x[15]
                    order.shipping_address = a

            # Close the connection to the DB
            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)

        return order
示例#10
0
class CustomerAddressIndexView(TemplateView):
    template_name = 'Store/customer/caddressindex.html'
    cusadd = CustomerAddress()
    cadao = CustomerAddressDao()
    

    @never_cache
    def get(self,request):
        user_id = request.session['user_id']
        username = request.session['username'] 
        caddress = self.cadao.get_all_addresses_by_customer_id(user_id)
        
        
        aaddress = AddAddressForm()
        eaddress = EditAddressForm()
        context = {
            'caddress': caddress,
            'aaddress': aaddress,
            'eaddress': eaddress
            
        }
        context['user_id'] = request.session['user_id'],
        context['username'] = request.session['username']

        return render(request, self.template_name,context)
    
    @never_cache
    def post(self,request):
        user_id = request.session['user_id']
        username = request.session['username'] 
        daddress = DeleteAddressForm(request.POST)
        aaddress = AddAddressForm(request.POST)
        context = {}
        if 'add-address' in request.POST:
            if aaddress.is_valid():
                a = CustomerAddress()
                a.customer_id = user_id
                a.street = aaddress.cleaned_data['street']
                a.city = aaddress.cleaned_data['city']
                a.state_code = aaddress.cleaned_data['state_code']
                a.zip_code = aaddress.cleaned_data['zip_code']
                a.address_type = aaddress.cleaned_data['address_type']
                self.cadao.create(a)

                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username'] 
                return redirect(reverse('customeraccount'))
        else:
            return redirect(reverse('caddpayindex'))
示例#11
0
    def post(self,request):
        context={}
        user_id = request.session['user_id']
        username = request.session['username'] 
        bill_addresses = self.cadao.get_by_customer_and_type(user_id, "Billing")
        bill_address_choices = []
        for address in bill_addresses:
            address_val = (str(address.address_id), str(address.street) + " " + str(address.city) + ", " 
                    + str(address.state_code) + " " + str(address.zip_code))
            bill_address_choices.append(address_val)
        addcard = AddPaymentInfoForm(request.POST,bill_address_choices=bill_address_choices)
        aaddress = AddAddressForm2(request.POST)

        if 'add-card' in request.POST:
            if addcard.is_valid():
                p = PaymentInfo()
                p.customer_id = user_id 
                p.card_number = addcard.cleaned_data['card_number']
                p.cvc = addcard.cleaned_data['cvc']
                p.expir_date = addcard.cleaned_data['expir_date']
                p.card_issuer = addcard.cleaned_data['card_issuer']
                p.billing_address.address_id = addcard.cleaned_data['billing_addresses']
                self.pdao.create(p)
                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username'] 
            return redirect(reverse('customeraccount'))

        elif 'add-address' in request.POST:
            if aaddress.is_valid():
                a = CustomerAddress()
                a.customer_id = user_id
                a.street = aaddress.cleaned_data['street']
                a.city = aaddress.cleaned_data['city']
                a.state_code = aaddress.cleaned_data['state_code']
                a.zip_code = aaddress.cleaned_data['zip_code']
                a.address_type = 'Billing'
                self.cadao.create(a)

                context['user_id'] = request.session['user_id']
                context['username'] = request.session['username'] 
                return redirect(reverse('customeraddcard'))
        else:
            return redirect(reverse('customeraccount'))
示例#12
0
    def post(self,request):
        user_id = request.session['user_id']
        username = request.session['username'] 
        daddress = DeleteAddressForm(request.POST)
        aaddress = AddAddressForm(request.POST)
        context = {}
        if 'add-address' in request.POST:
            if aaddress.is_valid():
                a = CustomerAddress()
                a.customer_id = user_id
                a.street = aaddress.cleaned_data['street']
                a.city = aaddress.cleaned_data['city']
                a.state_code = aaddress.cleaned_data['state_code']
                a.zip_code = aaddress.cleaned_data['zip_code']
                a.address_type = aaddress.cleaned_data['address_type']
                self.cadao.create(a)

                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username'] 
                return redirect(reverse('customeraccount'))
        else:
            return redirect(reverse('caddpayindex'))
示例#13
0
class CustomerAddCardView(TemplateView):
    template_name = 'Store/customer/addcard.html'
    user = User()
    udao = UserDao()
    customer = CustomerInfo()
    cdao = CustomerInfoDAO()
    cusadd = CustomerAddress()
    cadao = CustomerAddressDao()
    payment = PaymentInfo()
    pdao = PaymentInfoDao()
    @never_cache
    def get(self,request):
        context={}
        user_id =  request.session['user_id'] 
        username = request.session['username'] 
        user = self.udao.get_byid(user_id)
        customer = self.cdao.get_byid(user_id)
        cusadd =CustomerAddress()
        cusadd.customer_id = user_id
        caddress = self.cadao.get_all_addresses_by_customer_id(user_id)
        bill_addresses = self.cadao.get_by_customer_and_type(user_id, "Billing")

        bill_address_choices = []
        for address in bill_addresses:
            address_val = (str(address.address_id), str(address.street) + " " + str(address.city) + ", " 
                    + str(address.state_code) + " " + str(address.zip_code))
            bill_address_choices.append(address_val)
        num_bill_address = len(bill_address_choices)
        aaddress = AddAddressForm2()
        addcard = AddPaymentInfoForm(bill_address_choices=bill_address_choices)
        context['addcard'] = addcard
        context['aaddress'] = aaddress
        context['user_id'] = request.session['user_id']
        context['username'] = request.session['username'] 
        context['num_bill_address'] = num_bill_address
        
        return render(request, self.template_name,context)

    @never_cache
    def post(self,request):
        context={}
        user_id = request.session['user_id']
        username = request.session['username'] 
        bill_addresses = self.cadao.get_by_customer_and_type(user_id, "Billing")
        bill_address_choices = []
        for address in bill_addresses:
            address_val = (str(address.address_id), str(address.street) + " " + str(address.city) + ", " 
                    + str(address.state_code) + " " + str(address.zip_code))
            bill_address_choices.append(address_val)
        addcard = AddPaymentInfoForm(request.POST,bill_address_choices=bill_address_choices)
        aaddress = AddAddressForm2(request.POST)

        if 'add-card' in request.POST:
            if addcard.is_valid():
                p = PaymentInfo()
                p.customer_id = user_id 
                p.card_number = addcard.cleaned_data['card_number']
                p.cvc = addcard.cleaned_data['cvc']
                p.expir_date = addcard.cleaned_data['expir_date']
                p.card_issuer = addcard.cleaned_data['card_issuer']
                p.billing_address.address_id = addcard.cleaned_data['billing_addresses']
                self.pdao.create(p)
                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username'] 
            return redirect(reverse('customeraccount'))

        elif 'add-address' in request.POST:
            if aaddress.is_valid():
                a = CustomerAddress()
                a.customer_id = user_id
                a.street = aaddress.cleaned_data['street']
                a.city = aaddress.cleaned_data['city']
                a.state_code = aaddress.cleaned_data['state_code']
                a.zip_code = aaddress.cleaned_data['zip_code']
                a.address_type = 'Billing'
                self.cadao.create(a)

                context['user_id'] = request.session['user_id']
                context['username'] = request.session['username'] 
                return redirect(reverse('customeraddcard'))
        else:
            return redirect(reverse('customeraccount'))
示例#14
0
class CAddressAccountView(TemplateView):
    udao = UserDao()
    user = User()
    cadao = CustomerAddressDao()
    customer = CustomerAddress()
    padao = PaymentInfoDao()
    rdao = RetailOrderDao()
    template_name = 'Store/customer/caddressaccount.html' 
    @never_cache
    def get(self,request,address_id):
        user_id = request.session['user_id']
        username = request.session['username'] 
        address = self.cadao.get_byid(address_id) 
        payment = self.padao.get_by_address_id(address_id,user_id)
        orders = self.rdao.getOrdersByCardID(address_id)
        initial_data = {
            'street': address.street,
            'city': address.city,
            'state_code': address.state_code,
            'zip_code': address.zip_code,
            'address_type': address.address_type
        }

        eaddress = EditAddressForm(initial_data)
        daddress = DeleteAddressForm()
        apayment = AddPaymentInfoForm2()
        context = {
            'address':address,
            'eaddress': eaddress,
            'payment': payment,
            'apayment': apayment,
            'daddress': daddress,
            'orders': orders
        }

        context['user_id'] = request.session['user_id'],
        context['username'] = request.session['username'] 
        return render(request,self.template_name,context) 

    @never_cache
    def post(self,request,address_id):
        user_id = request.session['user_id']
        username = request.session['username'] 
        eaddress = EditAddressForm(request.POST)
        apayment = AddPaymentInfoForm2(request.POST)
        daddress = DeleteAddressForm(request.POST)
        address = self.cadao.get_byid(address_id)
        user_id = address.customer_id
        context = {}
        if 'edit-address' in request.POST:
            if eaddress.is_valid():
                a = CustomerAddress()
                a.address_id = address_id
                a.customer_id = user_id
                a.street = eaddress.cleaned_data['street']
                a.city = eaddress.cleaned_data['city']
                a.state_code = eaddress.cleaned_data['state_code']
                a.zip_code = eaddress.cleaned_data['zip_code']
                a.address_type = eaddress.cleaned_data['address_type']
                self.cadao.update(a)
                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username'] 
            return redirect(reverse(('customeraddress'), kwargs={'address_id': address_id}))

        elif 'add-card' in request.POST:
            if apayment.is_valid():
                p = PaymentInfo()
                p.card_number = apayment.cleaned_data['card_number']
                p.cvc = apayment.cleaned_data['cvc']
                p.expir_date = apayment.cleaned_data['expir_date']  
                p.card_issuer = apayment.cleaned_data['card_issuer']
                p.customer_id = user_id
                p.billing_address.address_id = address_id
                self.padao.create(p)
                
                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username'] 
            return redirect(reverse(('customeraddress'), kwargs={'address_id': address_id}))

        elif 'delete-address' in request.POST: 
            if daddress.is_valid():
                a = CustomerAddress()
                a.address_id = daddress.cleaned_data['address_id']
                a.customer_id = user_id
                self.cadao.delete(a)
                
                context['user_id'] = request.session['user_id'],
                context['username'] = request.session['username'] 
            return redirect(reverse('customeraccount')) 
        else:
            return redirect(reverse(('customeraddress'), kwargs={'address_id': address_id}))