def referral(id): if request.method == 'GET': rewards = Referral.objects(itemid=id) return get_items(request, rewards) if request.method == 'POST': item = Referral.objects(itemid=id).first() if request_has_json(): item.description = request.json['description'] item.save() return 'Updated' else: form = ReferralForm(request.form) form.populate_obj(item) item.save() return render_template('list_referrals.html', items=[item])
def referrals(): if request.method == 'POST': form = ReferralForm(request.form) if request_has_json(): try: json_data = json.dumps(request.json, default=json_util.default) model = Referral.from_json(json_data) model.save() except ValidationError as e: return jsonify(item=str(e)) else: if form.validate(): form.save() else: return render_template('add_referral.html', form=form) return list_referrals() else: return list_referrals()