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)
def editproduct(product_id): form = request.json product = Key("Product", product_id, parent=TypeGroup.product_ancestor()).get() if product is None: return abort(404) if request.method == "POST": if 'group' in form: group = Group.query(Group.name == form.get('group')).fetch(1) if len(group) == 0: if form.get('group', '') != '': group = Group(name=form['group']) group.put() else: return abort(400) else: group = group[0] else: group = product.group.get() try: losemods = product.losemods if 'losemods' in form: losemods = [Key("Mod", id, parent=TypeGroup.product_ancestor()) for id in form.get('losemods')] for mod in losemods: if mod.get() is None: raise BadValueError("Mod {} does not exists.".format(mod)) gainmods = product.gainmods if 'gainmods' in form: gainmods = [Key("Mod", id, parent=TypeGroup.product_ancestor()) for id in form.get('gainmods')] for mod in gainmods: if mod.get() is None: raise BadValueError("Mod {} does not exists.".format(mod)) product.contenttype = form.get('name', form.get('contenttype', product.contenttype)) product.tag = form.get('tag', '') product.group = group.key product.amount = form.get('amount', product.amount) product.value = form.get('value', product.value) product.losemods = losemods product.gainmods = gainmods product.put() except BadValueError as e: return jsonify({"messages": [e.message]}, 400) return jsonify(product) return render_template('tantalus_product.html', product=product, mods=Mod.query().fetch())