Exemplo n.º 1
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())
Exemplo n.º 2
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())
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 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())
Exemplo n.º 6
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())
Exemplo n.º 7
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())
Exemplo n.º 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())
Exemplo n.º 9
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)
Exemplo n.º 10
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)