示例#1
0
def process_request(request):
    params = {}

    try:
        user = hmod.User.objects.get(id=request.urlparams[0])
    except hmod.User.DoesNotExist:
        return HttpResponseRedirect('/homepage/')

    if request.urlparams[1] != "None":
        try:
            address = hmod.Address.objects.get(id=request.urlparams[1])
        except hmod.Address.DoesNotExist:
            return HttpResponseRedirect('/homepage/')
    else:
        address = hmod.Address()
        address.street1 = ''
        address.street2 = ''
        address.city = ''
        address.state = ''
        address.zip_code = ''
        address.country = ''
        address.save()
        user.address_id = address.id
        user.save()

    params['user'] = user
    return templater.render_to_response(request, 'account.html', params)
def create(request):
    params = {}

    form = UserCreateForm(initial={
        'first_name': '',
        'last_name': '',
        'username': '',
        'password': '',
        'confirm': '',
        'email': '',
        'phone': '',
        'address1': '',
        'address2': '',
        'city': '',
        'state': '',
        'zip': '',
        'securityQuestion': '',
        'securityAnswer': ''
    })
    if request.method == 'POST':
        form = UserCreateForm(request.POST)
        form.userid = -1
        if form.is_valid():
            user = hmod.User()
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.username = form.cleaned_data['username']
            user.set_password(form.cleaned_data['password'])
            user.email = form.cleaned_data['email']
            address = hmod.Address()
            address.address1 = form.cleaned_data['address1']
            address.address2 = form.cleaned_data['address2']
            address.city = form.cleaned_data['city']
            address.state = form.cleaned_data['state']
            address.zip = form.cleaned_data['zip']
            address.email = '*****@*****.**'
            address.save()
            user.address = address
            user.phone = form.cleaned_data['phone']
            user.securityQuestion = form.cleaned_data['securityQuestion']
            user.securityAnswer = form.cleaned_data['securityAnswer']
            user.photograph = hmod.Photograph.objects.all()[0]
            group = Group.objects.get(name='User')
            user.group = group
            user.save()
            user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password'])
            login(request, user)
            request.session['user_id'] = user.id
            return HttpResponseRedirect('/homepage/account/')

    params['form'] = form

    return templater.render_to_response(request, 'account_create.html', params)
示例#3
0
文件: test.py 项目: danmo91/INTEX
def enter_payment(request):
    '''
        enter_payment: Collects and verifies shipping and payment info
    '''
    params = {}

    form = CheckoutForm(
        initial={
            'creditcard': '4732817300654',
            'exp_month': '10',
            'exp_year': '15',
            'cvc': '411',
        })

    if request.method == 'POST':
        # get form
        form = CheckoutForm(request.POST)
        if form.is_valid():
            request.session['credit_card'] = {
                'creditcard': '4732817300654',
                'exp_month': '10',
                'exp_year': '15',
                'cvc': '411',
            }

            # check if user has an address
            user = hmod.User.objects.get(id=request.user.id)
            has_address = hmod.Address.objects.filter(user=user)

            if has_address.count() == 0:

                # save address information
                address = hmod.Address()

                address.street = form.cleaned_data['street']
                address.city = form.cleaned_data['city']
                address.state = form.cleaned_data['state']
                address.zip_code = form.cleaned_data['zip_code']
                address.save()

                # associate user with address
                address.user = user
                address.save()

            return HttpResponseRedirect('/shop/checkout.charge_card')

    params['form'] = form

    return templater.render_to_response(request, 'enter_payment.html', params)
 def clean(self):
     user = authenticate(username=self.cleaned_data['username'],
                         password=self.cleaned_data['password'])
     if user == None:
         s = Server('www.colonialheritagefoundation.co',
                    port=3890,
                    get_info=GET_ALL_INFO)
         c = Connection(s,
                        auto_bind=True,
                        user=self.cleaned_data['username'] +
                        '@colonialheritagefoundation.local',
                        password=self.cleaned_data['password'],
                        authentication=AUTH_SIMPLE,
                        client_strategy=STRATEGY_SYNC,
                        raise_exceptions=False)
         if c.response is None:
             search_results = c.search(
                 search_base=
                 'CN=Users,DC=colonialheritagefoundation,DC=local',
                 search_filter='(samAccountName=Dennis)',
                 attributes=[
                     'givenName',
                     'sn',
                     'mail',
                 ])
             user = hmod.User()
             address = hmod.Address()
             address.zip = 0
             address.save()
             user.username = self.cleaned_data['username']
             user.password = make_password(self.cleaned_data['password'])
             user.first_name = c.response[0]['attributes']['givenName']
             user.last_name = c.response[0]['attributes']['sn']
             user.email = self.cleaned_data[
                 'username'] + '@colonialheritagefoundation.co'
             user.address = address
             user.save()
         else:
             raise forms.ValidationError(
                 'Your username and password do not match.')
     return self.cleaned_data
def process_request(request):
    params = {}

    #################### How do you pass more than one set of params??
    try:
        user = hmod.User.objects.get(id=request.urlparams[0])
    except hmod.User.DoesNotExist:
        return HttpResponseRedirect('/homepage/')

    if request.urlparams[1] != "None":
        try:
            address = hmod.Address.objects.get(id=request.urlparams[1])
        except hmod.Address.DoesNotExist:
            return HttpResponseRedirect('/homepage/')
    else:
        address = hmod.Address()
        address.street1 = ''
        address.street2 = ''
        address.city = ''
        address.state = ''
        address.zip_code = ''
        address.country = ''
        address.save()

    class userEditForm(forms.Form):
        first_name = forms.CharField(required=True, max_length=100)
        last_name = forms.CharField(required=True, max_length=100)
        email = forms.CharField(required=True, max_length=100)
        security_question = forms.CharField(required=True, max_length=100)
        security_answer = forms.CharField(required=True, max_length=100)
        phone = forms.CharField(required=True, max_length=100)
        street1 = forms.CharField(required=True, max_length=100)
        street2 = forms.CharField(required=False, max_length=100)
        city = forms.CharField(required=True, max_length=100)
        state = forms.CharField(required=True, max_length=100)
        zip_code = forms.CharField(required=True, max_length=100)
        country = forms.CharField(required=True, max_length=100)

        #def clean_start_date(self):
        #    if self.cleaned_data['start_date'] != "????-??-??":
        #        raise forms.ValidationError("Type in a date with this format: YYYY-MM-DD")

    form = userEditForm(
        initial={
            'first_name': user.first_name,
            'last_name': user.last_name,
            'email': user.email,
            'security_question': user.security_question,
            'security_answer': user.security_answer,
            'phone': user.phone,
            'street1': address.street1,
            'street2': address.street2,
            'city': address.city,
            'state': address.state,
            'zip_code': address.zip_code,
            'country': address.country,
        })

    if request.method == 'POST':
        form = userEditForm(request.POST)
        if form.is_valid():
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.email = form.cleaned_data['email']
            user.security_question = form.cleaned_data['security_question']
            user.security_answer = form.cleaned_data['security_answer']
            user.phone = form.cleaned_data['phone']
            address.street1 = form.cleaned_data['street1']
            address.street2 = form.cleaned_data['street2']
            address.city = form.cleaned_data['city']
            address.state = form.cleaned_data['state']
            address.zip_code = form.cleaned_data['zip_code']
            address.country = form.cleaned_data['country']

            address.save()

            user.address_id = address.id

            user.save()
            return HttpResponseRedirect('/homepage/')

    params['user'] = user
    params['form'] = form
    return templater.render_to_response(request, 'EditAccount.html', params)
group.save()
group.permissions.add(permission)

'''

#Create Addresses
#Address_1, Address_2, City, State, ZIP
for data in [
    ['1234 Colonial Dr.', '', 'Provo', 'UT', 84606],
    ['7894 Eagle Dr.', '', 'Provo', 'UT', 84606],
    ['4512 State St.', '', 'Provo', 'UT', 84604],
    ['1478 Retail Dr.', '', 'Provo', 'UT', 84606],
    ['148 Agent Dr.', '', 'Provo', 'UT', 84606],
    ['1234 Venue St.', '', 'Provo', 'UT', 84604],
]:
    address = hmod.Address()
    address.address_1 = data[0]
    address.address_2 = data[1]
    address.city = data[2]
    address.state = data[3]
    address.zip = data[4]
    address.save()

#Create Photographs
#date_taken, place_taken, image, caption
for data in [
    ['2014-11-12', '', 'SockPhotoPath', 'A picture of some socks'],
    ['2014-08-23', 'Event', 'EventPhotoPath', 'A picture of Event Location'],
]:
    photo = hmod.Photograph()
    photo.date_taken = data[0]
示例#7
0
    p = hmod.Photograph()
    p.date_taken = data[0]
    p.place_taken = data[1]
    p.description = data[2]
    p.image = data[3]
    p.save()

##########################       ADDRESSES
for data in [
    ["1432 Wallaby Way", "Sydney", "SydneyState", "49830", "Australia"],
    ["1782 S. Ashland Ridge dr.", "Herriman", "UT", "47483", "USA"],
    ["4484 W. 344 S.", "Salt Lake", "UT", "84848", "USA"],
    ["4555 W. 566 S.", "hahaha", "NY", "44555", "USA"],
    ["34343 W. 884444 S.", "Provo", "UT", "84333", "USA"],
]:
    a = hmod.Address()
    a.street1 = data[0]
    a.city = data[1]
    a.state = data[2]
    a.zip_code = data[3]
    a.country = data[4]
    a.save()

###################################      CREATE PERMISSIONS/GROUPS
g1 = Group()
g1.name = "Admin"
g1.save()

g2 = Group()
g2.name = 'Manager'
g2.save()
def process_request(request):
    template_vars = {}
    current_time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    user = request.user  #hmod.User.objects.get(id=request.urlparams[0])
    form = OrderForm()
    prod_cart_objects = []
    item_cart_objects = []

    cart_products = request.session.get('shopping_cart')

    rent_total = 0
    pur_total = 0

    if not cart_products:
        pass
    else:
        for product in cart_products:
            qty = request.session['shopping_cart'][product]
            citem = hmod.Product.objects.get(id=product)
            print(citem)
            prod_cart_objects.append([citem.id, qty])
        for item in prod_cart_objects:
            citem = hmod.Product.objects.get(id=item[0])
            quant = item[1]
            pur_total = pur_total + (citem.current_price * quant)

    cart_items = request.session.get('shopping_cart_items')
    if not cart_items:
        pass
    else:
        for item in cart_items:
            qty = request.session['shopping_cart_items'][item]
            citem = hmod.Item.objects.get(id=item)
            print(citem)
            item_cart_objects.append([citem.id, qty])

        for item in item_cart_objects:
            citem = hmod.Item.objects.get(id=item[0])
            rent_total = rent_total + citem.standard_rental_price

    total = rent_total + pur_total

    print(prod_cart_objects)
    print(item_cart_objects)

    prod_cart_size = len(prod_cart_objects)
    item_cart_size = len(item_cart_objects)

    print(prod_cart_size)
    print(item_cart_size)

    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            print('Form data cleaned')
            print('Charge ID: ' + form.cleaned_data['charge'])

            address = hmod.Address()
            address.address_1 = form.cleaned_data['address_1']
            address.address_2 = form.cleaned_data['address_2']
            address.city = form.cleaned_data['city']
            address.state = form.cleaned_data['state']
            address.zip = form.cleaned_data['zip']
            address.save()

            pur_total = 0
            rent_total = 0
            new_opo_id = 0
            new_rent_id = 0

            if not prod_cart_objects:
                pass
            else:

                opo = hmod.OnlinePurchaseOrder()
                opo.save()
                new_opo_id = opo.id
                for item in prod_cart_objects:
                    citem = hmod.Product.objects.get(id=item[0])
                    quant = item[1]
                    pur_total = pur_total + (citem.current_price * quant)

                    opp = hmod.OnlinePurchaseProduct()
                    opp.product_id = citem.id
                    opp.onlinepurchaseorder = hmod.OnlinePurchaseOrder(
                        id=opo.id)
                    opp.quantity = quant
                    opp.save()
                opo.total = pur_total
                opo.save()

                print(
                    '########################################################################'
                )
            if not item_cart_objects:
                pass
            else:
                rental = hmod.Rental()
                rental.rental_time = current_time
                mytime = datetime.strptime(current_time, "%Y-%m-%d %H:%M:%S")
                mytime += timedelta(hours=6)
                due_date = mytime.strftime("%Y-%m-%d %H:%M:%S")
                rental.due_date = due_date
                rental.save()
                print(
                    '1111111111111111111111111111111111111111111111111111111111111'
                )
                new_rent_id = rental.id
                for item in item_cart_objects:
                    citem = hmod.Item.objects.get(id=item[0])
                    rent_total = rent_total + citem.standard_rental_price

                    rentitem = hmod.RentalItem()
                    rentitem.item_id_id = citem.id
                    rentitem.rental_id_id = rental.id
                    rentitem.returns = None
                    rentitem.save()
                rental.total = rent_total
                rental.save()
                print(
                    '########################################################################'
                )

            total = rent_total + pur_total
            #print(customer)
            print(
                '1111111111111111111111111111111111111111111111111111111111111'
            )
            order = hmod.Order()
            print('1')
            order.customer = hmod.User.objects.get(id=user.id)
            print('2')
            order.ships_to = hmod.Address.objects.get(id=address.id)
            print('3')
            #order.payment = form.cleaned_data['charge']
            print('4')
            order.order_date = current_time
            print('5')
            order.save()
            if new_opo_id != 0:
                new_opo = hmod.OnlinePurchaseOrder.objects.get(id=new_opo_id)
                new_opo.order = order
                new_opo.save()
            if new_rent_id != 0:
                new_rental = hmod.Rental.objects.get(id=new_rent_id)
                new_rental.order = order
                new_rental.save()

            url = '/homepage/receipt/' + str(user.id) + '/' + str(
                order.id) + '/' + str(total) + '/'

            try:
                del request.session['shopping_cart']
            except:
                pass

            try:
                del request.session['shopping_cart_items']
            except:
                pass

            return HttpResponseRedirect(url)
    form = OrderForm(
        initial={
            'total': total,
            'Card_Holder_Name': user.first_name + ' ' + user.last_name,
        })
    template_vars['form'] = form
    template_vars['total'] = total
    return templater.render_to_response(request, 'checkout.html',
                                        template_vars)
示例#9
0
def process_request(request):
    params = {}

    try:
        user = hmod.User.objects.get(id=request.urlparams[0])
    except hmod.User.DoesNotExist:
        return HttpResponseRedirect('/homepage/')

    if request.urlparams[1] != "None":
        try:
            address = hmod.Address.objects.get(id=request.urlparams[1])
        except hmod.Address.DoesNotExist:
            return HttpResponseRedirect('/homepage/')
    else:
        address = hmod.Address()
        address.street1 = ''
        address.street2 = ''
        address.city = ''
        address.state = ''
        address.zip_code = ''
        address.country = ''
        address.save()


    class userEditForm(forms.Form):
        first_name = forms.CharField(required=True, max_length=100, widget=forms.TextInput(attrs={'class': 'form-control'}))
        last_name = forms.CharField(required=True, max_length=100, widget=forms.TextInput(attrs={'class': 'form-control'}))
        email = forms.CharField(required=True, max_length=100, widget=forms.TextInput(attrs={'class': 'form-control'}))
        phone = forms.CharField(required=False, max_length=100, widget=forms.TextInput(attrs={'class': 'form-control'}))
        street1 = forms.CharField(required=False, max_length=100, widget=forms.TextInput(attrs={'class': 'form-control'}))
        street2 = forms.CharField(required=False, max_length=100, widget=forms.TextInput(attrs={'class': 'form-control'}))
        city = forms.CharField(required=False, max_length=100, widget=forms.TextInput(attrs={'class': 'form-control'}))
        state = forms.CharField(required=False, max_length=100, widget=forms.TextInput(attrs={'class': 'form-control'}))
        zip_code = forms.CharField(required=False, max_length=100, widget=forms.TextInput(attrs={'class': 'form-control'}))
        country = forms.CharField(required=False, max_length=100, widget=forms.TextInput(attrs={'class': 'form-control'}))

    form = userEditForm(initial={
        'first_name': user.first_name,
        'last_name': user.last_name,
        'email': user.email,
        'phone': user.phone,
        'street1': address.street1,
        'street2': address.street2,
        'city': address.city,
        'state': address.state,
        'zip_code': address.zip_code,
        'country': address.country,

    })

    if request.method == 'POST':
        form = userEditForm(request.POST)
        if form.is_valid():
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.email = form.cleaned_data['email']
            user.phone = form.cleaned_data['phone']
            address.street1 = form.cleaned_data['street1']
            address.street2 = form.cleaned_data['street2']
            address.city = form.cleaned_data['city']
            address.state = form.cleaned_data['state']
            address.zip_code = form.cleaned_data['zip_code']
            address.country = form.cleaned_data['country']

            address.save()

            user.address_id = address.id

            user.save()
            return HttpResponseRedirect('/homepage/account/{}/'.format(user.id) + '{}/'.format(user.address_id))
        else:
            params['error'] = "<p class='bg-danger'>first_name, last_name, and email are required fields</p>"
            params['user'] = user
            params['form'] = form
            return templater.render_to_response(request, 'edit_account.html', params)

    params['error'] = ""
    params['user'] = user
    params['form'] = form
    return templater.render_to_response(request, 'edit_account.html', params)
示例#10
0
def process_request(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/accounts/login.logincheckoutptone/')
    params = {}

    # this is where we add the shipping address to the database

    class AddressForm(forms.Form):

        street1 = forms.CharField(
            required=True,
            max_length=100,
            widget=forms.TextInput(attrs={'class': 'form-control'}))
        street2 = forms.CharField(
            required=False,
            max_length=100,
            widget=forms.TextInput(attrs={'class': 'form-control'}))
        city = forms.CharField(
            required=True,
            max_length=100,
            widget=forms.TextInput(attrs={'class': 'form-control'}))
        state = forms.CharField(
            required=True,
            max_length=100,
            widget=forms.TextInput(attrs={'class': 'form-control'}))
        zip_code = forms.CharField(
            required=True,
            max_length=100,
            widget=forms.TextInput(attrs={'class': 'form-control'}))
        country = forms.CharField(
            required=True,
            max_length=100,
            widget=forms.TextInput(attrs={'class': 'form-control'}))

    form = AddressForm()

    if request.method == 'POST':
        form = AddressForm(request.POST)
        if form.is_valid():
            address = hmod.Address()
            address.street1 = form.cleaned_data['street1']
            address.street2 = form.cleaned_data['street2']
            address.city = form.cleaned_data['city']
            address.state = form.cleaned_data['state']
            address.zip_code = form.cleaned_data['zip_code']
            address.country = form.cleaned_data['country']
            address.save()

            params['address_id'] = address.id
            params['error'] = ''
            params['form'] = form
            return templater.render_to_response(request,
                                                'checkout.payment_info.html',
                                                params)

        else:
            params[
                'error'] = "<p class='bg-danger'>All fields except street2 are required</p>"
            params['form'] = form
            return templater.render_to_response(request,
                                                'checkout.ship_address.html',
                                                params)

    # return templater.render_to_response(request, 'checkout.payment_info.html', params)
    params['error'] = ''
    params['form'] = form
    return templater.render_to_response(request, 'checkout.ship_address.html',
                                        params)