Пример #1
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)
Пример #2
0
 def test_see_other_headers(self):
     r = http.see_other('/', [('Set-Cookie', 'name=value')])
     # Pass through WebTest for lint-like checks
     webtest.TestApp(app.RestishApp(r)).get('/')
     # Test response details.
     assert r.headers['Location'] == '/'
     assert r.headers['Set-Cookie'] == 'name=value'
Пример #3
0
 def test_see_other_headers(self):
     r = http.see_other("/", [("Set-Cookie", "name=value")])
     # Pass through WebTest for lint-like checks
     webtest.TestApp(app.RestishApp(r)).get("/")
     # Test response details.
     assert r.headers["Location"] == "/"
     assert r.headers["Set-Cookie"] == "name=value"
Пример #4
0
 def update_item(self, request, form):
     C = _store(request)
     try:
         data = form.validate(request)
     except formish.FormError:
         return self.render_page(request, form)
     with C.session() as S:
         doc = S.doc_by_id(self.id)
         # XXX Capture the error and display a useful page.
         confirm_doc_and_rev(doc, data)
         doc.update(data)
     flash.add_message(request.environ, 'item updated.', 'success')
     came_from = request.GET.get('came_from')
     if came_from:
         return http.see_other(request.application_url + came_from)
     return http.see_other(request.url.parent())
Пример #5
0
 def update_item(self, request, form):
     C = _store(request)
     try:
         data = form.validate(request)
     except formish.FormError:
         return self.render_page(request, form)
     with C.session() as S:
         doc = S.doc_by_id(self.id)
         # XXX Capture the error and display a useful page.
         confirm_doc_and_rev(doc, data)
         doc.update(data)
     flash.add_message(request.environ, 'item updated.', 'success')
     came_from = request.GET.get('came_from')
     if came_from:
         return http.see_other(request.application_url+came_from)
     return http.see_other(request.url.parent())
Пример #6
0
 def test_see_other_headers(self):
     r = http.see_other('/', [('Set-Cookie', 'name=value')])
     # Pass through WebTest for lint-like checks
     webtest.TestApp(app.RestishApp(r)).get('/')
     # Test response details.
     assert r.headers['Location'] == '/'
     assert r.headers['Set-Cookie'] == 'name=value'
Пример #7
0
 def POST(self, request):
     C = _store(request)
     type_config = C.config.types[self.model_type]
     form = category_form(C, self.path, self.referenced_type, request)
     try:
         data = form.validate(request)
     except formish.FormError:
         return self.html(request, form)
     with C.session() as S:
         facet_docs = S.docs_by_type(self.model_type)
         facet_docs = list(facet_docs)
         assert len(facet_docs) == 1
         facet = list(facet_docs)[0]
         # facet is the couch document for 'facet_%s'%path where the docs has a key 'category'
         # which is a list of dicts =
         # [{'path': 'scotland.argyll', 
         #   'data': ref_to_category whose keys= 'keywords','model_type','_ref','label',
         #   'id': couchuuid},]
         cats, changelog = categories.apply_changes(facet['category'], data['category'], self.category_path, create_category(S))
         view = type_config.get('metadata', {}).get('categorypath-rev')
         if view is None:
             view = '%s/categorypath-rev'%self.model_type
         for old,new in changelog:
             items = list(S.view(view,include_docs=True,startkey=old, endkey=old))
             for item in items:
                 _set(item.doc, item.value, new)
         # Get the results of the view that matches each change
         facet['category'] = cats
     return http.see_other(request.url.path)
Пример #8
0
 def post(self, request):
     C = _store(request)
     defn = C.config.types[self.type]
     form = _form_for_type(request, C, defn)
     try:
         data = form.validate(request)
     except formish.FormError:
         return self._html(request, form)
     C = _store(request)
     with C.session() as S:
         S.create(_doc_create(self.type, data))
     flash.add_message(request.environ, 'item created.', 'success')
     came_from = request.GET.get('came_from')
     if came_from:
         return http.see_other(request.application_url + came_from)
     return http.see_other(request.url.parent())
Пример #9
0
 def delete_item(self, request, form):
     C = _store(request)
     with C.session() as S:
         doc = S.doc_by_id(self.id)
         S.delete(doc)
     flash.add_message(request.environ, 'item deleted.', 'success')
     return http.see_other(request.url.parent())
Пример #10
0
 def POST(self, request):
     C = _store(request)
     type_config = C.config.types[self.model_type]
     form = category_form(C, self.path, self.referenced_type, request)
     try:
         data = form.validate(request)
     except formish.FormError:
         return self.html(request, form)
     with C.session() as S:
         facet_docs = S.docs_by_type(self.model_type)
         facet_docs = list(facet_docs)
         assert len(facet_docs) == 1
         facet = list(facet_docs)[0]
         # facet is the couch document for 'facet_%s'%path where the docs has a key 'category'
         # which is a list of dicts =
         # [{'path': 'scotland.argyll',
         #   'data': ref_to_category whose keys= 'keywords','model_type','_ref','label',
         #   'id': couchuuid},]
         cats, changelog = categories.apply_changes(facet['category'],
                                                    data['category'],
                                                    self.category_path,
                                                    create_category(S))
         view = type_config.get('metadata', {}).get('categorypath-rev')
         if view is None:
             view = '%s/categorypath-rev' % self.model_type
         for old, new in changelog:
             items = list(
                 S.view(view, include_docs=True, startkey=old, endkey=old))
             for item in items:
                 _set(item.doc, item.value, new)
         # Get the results of the view that matches each change
         facet['category'] = cats
     return http.see_other(request.url.path)
Пример #11
0
 def post(self, request):
     C = _store(request)
     defn = C.config.types[self.type]
     form = _form_for_type(request, C, defn)
     try:
         data = form.validate(request)
     except formish.FormError:
         return self._html(request, form)
     C = _store(request)
     with C.session() as S:
         S.create(_doc_create(self.type, data))
     flash.add_message(request.environ, 'item created.', 'success')
     came_from = request.GET.get('came_from')
     if came_from:
         return http.see_other(request.application_url+came_from)
     return http.see_other(request.url.parent())
Пример #12
0
 def delete_item(self, request, form):
     C = _store(request)
     with C.session() as S:
         doc = S.doc_by_id(self.id)
         S.delete(doc)
     flash.add_message(request.environ, 'item deleted.', 'success')
     return http.see_other(request.url.parent())
Пример #13
0
    def post(self, request):
        form = get_form(request)
        try:
            data = form.validate(request)
        except formish.FormError:
            return self.html(request, form)

        username, password = data['username'], data['password']
        return http.see_other('/thanks')
Пример #14
0
 def test_see_other(self):
     location = 'http://localhost/abc?a=1&b=2'
     r = http.see_other(location)
     # Pass through WebTest for lint-like checks
     webtest.TestApp(app.RestishApp(r)).get('/')
     # Test response details.
     assert r.status.startswith('303')
     assert r.headers['Location'] == location
     assert r.headers['Content-Length']
     assert '303 See Other' in r.body
     assert cgi.escape(location) in r.body
Пример #15
0
 def test_see_other(self):
     location = "http://localhost/abc?a=1&b=2"
     r = http.see_other(location)
     # Pass through WebTest for lint-like checks
     webtest.TestApp(app.RestishApp(r)).get("/")
     # Test response details.
     assert r.status.startswith("303")
     assert r.headers["Location"] == location
     assert r.headers["Content-Length"]
     assert "303 See Other" in r.body
     assert cgi.escape(location) in r.body
Пример #16
0
 def test_see_other(self):
     location = 'http://localhost/abc?a=1&b=2'
     r = http.see_other(location)
     # Pass through WebTest for lint-like checks
     webtest.TestApp(app.RestishApp(r)).get('/')
     # Test response details.
     assert r.status.startswith('303')
     assert r.headers['Location'] == location
     assert r.headers['Content-Length']
     assert '303 See Other' in r.body
     assert cgi.escape(location) in r.body
Пример #17
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)
Пример #18
0
    def post(self, request):
        form = get_form(request)
        try:
            data = form.validate(request)
        except formish.FormError:
            return self.html(request, form)

        data.pop('username')
        data.pop('password')
        for k,v in data.items():
            save_answer(request, k, v)
        return http.see_other('/thanks')
Пример #19
0
 def POST(self, request):
     C = _store(request)
     defn = C.config.types[self.type]
     form = _form_for_type(request, C, defn)
     try:
         data = form.validate(request)
     except formish.FormError:
         return self.render_page(request, form)
     with C.session() as S:
         S.create(_doc_create(self.type, data))
     flash.add_message(request.environ, 'item created.', 'success')
     return http.see_other(request.url)
Пример #20
0
 def POST(self, request):
     C = _store(request)
     defn = C.config.types[self.type]
     form = _form_for_type(request, C, defn)
     try:
         data = form.validate(request)
     except formish.FormError:
         return self.render_page(request, form)
     with C.session() as S:
         S.create(_doc_create(self.type, data))
     flash.add_message(request.environ, 'item created.', 'success')
     return http.see_other(request.url)
Пример #21
0
    def POST(self, request):
        form = make_registration_form(request)
        try:
            data = form.validate(request)
        except formish.FormError:
            return self.html(request, form)
        C = request.environ['couchish']
        try:
            with C.session() as S:
                customer = S.doc_by_view('user/by_identifiers', key=data['email'])
            form.errors['email'] = 'already exists'
            return self.html(request, form)
        except errors.NotFound:
            pass

        customer = {
            'model_type': 'user',
            'ctime': datetime.now().isoformat(),
            'mtime': datetime.now().isoformat(),
            'title': data['title'],
            'first_names': data['first_names'],
            'last_name': data['last_name'],
            'email': data['email'],
            'username': data['email'],
            'telephone': data['telephone'],
            'credentials': {
                'password': data['password'].decode('utf8')
            },
            'address': {
                'street1': data['address']['street1'],
                'street2': data['address']['street2'],
                'street3': data['address']['street3'],
                'street4': '',
                'city': data['address']['city'],
                'county': data['address']['county'],
                'postcode': data['address']['postcode'],
                'country': data['address']['country'],
            },
           'roles': [ "_system/customer" ]
        }

        with C.session() as S:
            id = S.create(customer)
        auth.set_authenticated_username(request, data['email'])
        return http.see_other('/checkout')
Пример #22
0
    def POST(self, request):
        form = self._csvuploadform(request)
        try:
            data = form.validate(request)
        except formish.FormError:
            return self._html(request, form=form)
        f = StringIO()
        f.write(data["csv"].file.read())
        f.seek(0)

        rows = []
        try:
            reader = UnicodeDictReader(f)
            for row in reader:
                rows.append(row)
        finally:
            f.close()

        C = request.environ["couchish"]
        with C.session() as S:
            photos = list(S.docs_by_view("photo/all"))
            photos_by_code = {}
            for photo in photos:
                photos_by_code[photo["code"]] = photo
            changes = {}
            for row in rows:
                if row["change"] == "y":
                    for key in CSVPHOTOKEYS:
                        if str(photos_by_code[row["code"]][key]) != str(row[key]):
                            print "setting", photos_by_code[row["code"]]["code"], "key", key, "from", photos_by_code[
                                row["code"]
                            ][key], "to", row[key]
                            photos_by_code[row["code"]][key] = row[key]

        flash.add_message(request.environ, "csv uploaded.", "success")
        return http.see_other(request.url)
Пример #23
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)
Пример #24
0
 def POST(self, request):
     args = request.POST
     command = args.pop('command')
     func = getattr(self, 'command_%s'%command)
     basket = func(request, args)
     return http.see_other('/basket')
Пример #25
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)
Пример #26
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}
Пример #27
0
 def test_see_other(self):
     location = 'http://localhost/abc'
     r = http.see_other(location)
     assert r.status.startswith('303')
     assert r.headers['Location'] == location
Пример #28
0
 def GET(self, request):
     identity = who.get_identity(request)
     if identity.has_permission('purchase'):
         return http.see_other('/checkout')
     return self.html(request)
Пример #29
0
    def POST(self, request):
        form = self._csvuploadform(request)
        try:
            data = form.validate(request)
        except formish.FormError:
            return self._html(request, form=form)

        replaceoptions = data["replaceoptions"]
        deletemissing = data["deletemissing"]
        updateall = data["updateall"]
        f = StringIO()
        f.write(data["csv"].file.read())
        f.seek(0)

        changed_products = []
        try:
            reader = UnicodeReader(f)
            for row in reader:
                if row[0] == "change":
                    continue

                if row[0] != "#":
                    product = dict([(k, row[n]) for n, k in enumerate(CSVPRODUCTKEYS)])
                    product["pricing"] = []
                    changed_products.append(product)
                else:
                    option = dict([(k, row[n]) for n, k in enumerate(CSVOPTIONKEYS)])
                    del option["marker"]
                    product["pricing"].append(option)
        finally:
            f.close()

        C = request.environ["couchish"]
        with C.session() as S:
            products = list(S.docs_by_view("product/all"))
            products_by_code = {}
            for product in products:
                products_by_code[product["code"]] = product
            original = set(products_by_code.keys())
            new = set([p["code"] for p in changed_products])
            deleted = original.difference(new)
            changes = {}
            for product in changed_products:
                if product["change"] == "y" or updateall:
                    if replaceoptions:
                        print "code", product["code"]
                        if products_by_code[product["code"]]["pricing"] != product["pricing"]:
                            print "old options", products_by_code[product["code"]]["pricing"]
                            print "new options", product["pricing"]
                            print "==========="
                        products_by_code[product["code"]]["pricing"] = product["pricing"]
                    else:
                        for key in ["title", "show", "available", "type"]:
                            if str(products_by_code[product["code"]].get(key, "")) != str(product.get(key, "")):
                                print "setting", products_by_code[product["code"]][
                                    "code"
                                ], "key", key, "from", products_by_code[product["code"]][key], "to", product[key]
                                # CSVPRODUCTKEYS = ['change','code','title', 'show', 'available', 'type']
                                if key == "show" or key == "available":
                                    products_by_code[product["code"]][key] = product[key] == "True"
                                    pass
                                else:
                                    products_by_code[product["code"]][key] = product[key]
                                    pass
        with C.session() as S:
            if deletemissing:
                for d in deleted:
                    product = products_by_code[d]
                    doc = S.doc_by_id(product["_id"])
                    print "deleteing", d
                    S.delete(doc)

        flash.add_message(request.environ, "csv uploaded.", "success")
        return http.see_other(request.url)