Example #1
0
def editposproduct(posproduct_id):
    form = request.json

    pos = Key("PosProduct", posproduct_id,
              parent=TypeGroup.product_ancestor()).get()

    if pos is None:
        return abort(404)

    if request.method == "POST":
        try:
            if "product" in form:
                pos.product = Key("Product",
                                  form['product'],
                                  parent=TypeGroup.product_ancestor())
                prd = pos.product.get()
                if prd is None:
                    raise BadValueError("Product does not exist.")
                pos.name = prd.contenttype
            elif 'name' in form:
                if len(form['name']) < 1:
                    raise BadValueError("Name too short!")
                pos.name = form['name']
                pos.product = None
            pos.price = form.get('price', pos.price)
            pos.scan_id = form.get('scan_id', pos.scan_id)
            pos.keycode = form.get('keycode', pos.keycode)
            pos.put()
        except BadValueError as e:
            return jsonify({"messages": [e.message]}, 400)
        return jsonify(pos)

    return render_template('tantalus_posproduct.html', pos=pos)
Example #2
0
def editmod(mod_id):
    form = request.json

    mod = Key("Mod", mod_id, parent=TypeGroup.product_ancestor()).get()
    if mod is None:
        abort(404)

    if request.method == "POST":
        try:
            mod.name = form.get('name', mod.name)
            mod.tag = form.get('tag', mod.tag)
            mod.description = form.get('description', mod.description)
            mod.pre_add = form.get('pre_add', mod.pre_add)
            mod.multiplier = form.get('multiplier', mod.multiplier)
            mod.post_add = form.get('post_add', mod.post_add)
            mod.modifies = form.get('modifies', mod.modifies)
            mod.divides = form.get('divides', mod.divides)
            mod.rounding = form.get('rounding', mod.rounding)
        except:
            return jsonify({"messsages": ["Improper datafields"]}, 402)

        try:
            mod.put()
        except BadValueError as e:
            return jsonify({"messages": [e.message]}, 400)
        return jsonify(mod)

    return render_template('tantalus_mod.html', mod=mod)
Example #3
0
def editrelation(relation_id):
    form = request.json or request.form

    relation = Key("Relation",
                   relation_id,
                   parent=TypeGroup.relation_ancestor()).get()

    if request.method == "POST":
        relation.name = form.get('name', relation.name)
        relation.email = form.get('email', relation.email)
        relation.budget = form.get('budget', relation.budget)
        relation.has_budget = form.get('has_budget', relation.has_budget)
        relation.send_mail = form.get('send_mail', relation.send_mail)
        relation.put()
        return jsonify(relation)

    return render_template('tantalus_relation.html', relation=relation)