Beispiel #1
0
    def auto_submit_form(self, request, data):
        identity = who.get_identity(request)
        C = request.environ['couchish']
        order_timestamp = datetime.now().isoformat()
        data['order_timestamp'] = order_timestamp
        data['checkcode'] = '108088'
        data['callbackurl'] = 'http://jc.timparkin.co.uk/_callback'
        data['callbackdata'] = 'username|%s|order_timestamp|%s'%(identity.username, order_timestamp)
        b = basket.Basket(request)
        b.load()
        # Clear basket
        form = make_autosubmit_form(request)
        form.defaults = data
        order_items = []
        for item in b._items:
            order_items.append( {'id': str(item.id), 'code': str(item.item.code), 'description': str(item.description), 'price': float(item.unit_price),'quantity': int(item.quantity), 'postage': float(item.unit_postage)} )
        with C.session() as S:
            customer = S.doc_by_view('user/by_identifiers', key=unicode(identity.username))
            if 'attempted_orders' not in customer:
                customer['attempted_orders'] = []
            customer['attempted_orders'].append( {
                    'order_timestamp': order_timestamp,
                    'items': order_items,
                    'postage': float(b.postage_price),
                    'total_price': float(b.total_price),
                    } )

        b.empty()
        return {'form': form}
Beispiel #2
0
 def args(self, request):
     # Call the super class to get the basic set of args.
     args = super(Templating, self).args(request)
     # Push to the args and return them.
     args['identity'] = who.get_identity(request)
     args['request'] = request
     return args
Beispiel #3
0
    def GET(self, request):
        identity = who.get_identity(request)
        if not identity.has_permission('purchase'):
            return http.see_other('/checkout/login')

        # Store the basket on the persons user account
        return self.html(request)
Beispiel #4
0
    def POST(self, request):
        identity = who.get_identity(request)
        if not identity.has_permission('purchase'):
            return http.see_other('/basket/login')

        form = make_card_form(request)
        try:
            data = form.validate(request)
        except formish.FormError:
            return self.html(request, form)
        return self.html(request)
Beispiel #5
0
 def html(self, request, form=None):
     b = basket.Basket(request)
     b.load()
     if form is None:
         secuitems = ''
         for item in b._items:
             secuitems += '[%s||%s|%0.2f|%s|%0.2f]'%(item.id, item.description, item.unit_price, item.quantity,item.unit_price*item.quantity)
         form = make_checkout_form(request)
         identity = who.get_identity(request)
         form.defaults = {
             'billing_street1': identity.address['street1'], 
             'billing_street2': identity.address['street2'], 
             'billing_street3': identity.address['street3'], 
             'billing_city': identity.address['city'], 
             'billing_county': identity.address['county'], 
             'billing_postcode': identity.address['postcode'], 
             'billing_country': identity.address['country'], 
             'delivery_street1': identity.address['street1'], 
             'delivery_street2': identity.address['street2'], 
             'delivery_street3': identity.address['street3'], 
             'delivery_city': identity.address['city'], 
             'delivery_county': identity.address['county'], 
             'delivery_postcode': identity.address['postcode'], 
             'delivery_country': identity.address['country'], 
             'filename': 'sh210209/template.html',
             'secuitems': secuitems,
             'shreference': 'sh210209',
             'cardholdersname': identity.full_name,
             'cardholdersemail': identity.email,
             'cardholdersphonenumber': identity.telephone,
             'deliveryname': identity.full_name,
             'transactioncurrency': 'GBP',
             'products_price': '%0.2f'%b.products_price,
             'shippingcharge': '%0.2f'%b.postage_price,
             'transactiontax': '%0.2f'%((b.total_price*0.175)/1.175),
             'transactionamount': '%0.2f'%b.total_price,
         }
     return {'form': form, 'request': request}
Beispiel #6
0
    def POST(self, request):
        identity = who.get_identity(request)
        if not identity.has_permission('purchase'):
            return http.see_other('/checkout/login')

        form = make_checkout_form(request)
        try:
            data = form.validate(request)
        except formish.FormError:
            return self.html(request, form)
        C = request.environ['couchish']
        with C.session() as S:
            customer = S.doc_by_view('user/by_identifiers', key=identity.email)
            customer['address'] = {
                'street1': data['billing_street1'],
                'street2': data['billing_street2'],
                'street3': data['billing_street3'],
                'city': data['billing_city'],
                'county': data['billing_county'],
                'postcode': data['billing_postcode'],
                'country': data['billing_country'],
                    }
        # send an auto submitting form... 
        return self.auto_submit_form(request, data)
Beispiel #7
0
 def checker(request, obj):
     identity = who.get_identity(request)
     if not identity or not identity.is_admin():
         raise GuardError("Need admin permissions")
Beispiel #8
0
 def checker(request, obj):
     if who.get_identity(request) is None:
         raise GuardError("Not logged in")
Beispiel #9
0
 def GET(self, request):
     identity = who.get_identity(request)
     if identity.has_permission('purchase'):
         return http.see_other('/basket/checkout')
     form = login.login_form(request, came_from=request.url)
     return {'form': form, 'request':request}
Beispiel #10
0
 def get(self, request):
     identity = who.get_identity(request)
     if not identity.has_permission('purchase'):        
         return http.see_other('/basket/login')
     return self.html(request)
Beispiel #11
0
 def GET(self, request):
     identity = who.get_identity(request)
     if identity.has_permission('purchase'):
         return http.see_other('/checkout')
     return self.html(request)