def editorO(): email = dict(session).get('email', None) user = User.get_by_email(email) given_name = dict(session).get('given_name', None) if user.role == "Promotor": ofertas = Oferta.getOffers(user.organizacion) if user.role == "Administrador": ofertas = Oferta.getAllOffers() salary = get_balance(user.blockHash) s = Session() if request.method == 'POST': if 'editarO' in request.form: return redirect( url_for('editorOferta', offer_id=request.form['id'])) elif 'eliminarO' in request.form: query = s.query(Oferta) pk = request.form['id'] query = query.filter(Oferta.id == pk).first() s.delete(query) s.commit() if user.role == "Promotor": ofertas = Oferta.getOffers(user.organizacion) if user.role == "Administrador": ofertas = Oferta.getAllOffers() try: del session['accionId'] del session['offerId'] except: pass return render_template('adminofertas.html', title='Ofertas', wallet=salary, email=email, name=given_name, w3=web3, user=user, ofertas=ofertas)
def accion(): form = CrearCampForm() form2 = CrearOfertaForm() email = dict(session).get('email', None) user = User.get_by_email(email) given_name = dict(session).get('given_name', None) if user.role == "Promotor": campanyas = Campanya.getCampaigns(user.organizacion) acciones = Accion.getActions(user.organizacion) ofertas = Oferta.getOffers(user.organizacion) elif user.role == "Administrador": campanyas = Campanya.getAllCampaigns() acciones = Accion.getAllActions() ofertas = Oferta.getAllOffers() else: return redirect("/login") try: for c in campanyas: c.nombre = translator.translate(c.nombre, dest=session['lang']).text c.descripcion = translator.translate(c.descripcion, dest=session['lang']).text for a in acciones: a.nombre = translator.translate(a.nombre, dest=session['lang']).text a.descripcion = translator.translate(a.descripcion, dest=session['lang']).text a.indicadorKpi = translator.translate(a.indicadorKpi, dest=session['lang']).text for o in ofertas: o.nombre = translator.translate(o.nombre, dest=session['lang']).text o.descripcion = translator.translate(o.descripcion, dest=session['lang']).text except: pass salary = get_balance(os.environ.get('TEST_ADDRESS')) if form.validate_on_submit() and form.crearCamp.data: s = Session() if user.role == "Promotor": c = Campanya(request.form['nomCamp'], user.organizacion, request.form['desc']) elif user.role == "Administrador": c = Campanya(request.form['nomCamp'], request.form['empresa'], request.form['desc']) s.add(c) s.commit() elif form2.validate_on_submit() and form2.crearOf.data: nombre = request.form['nomOferta'] s = Session() if user.role == "Promotor": o = Oferta(request.form['nomOferta'], user.organizacion, request.form['desc'], request.form['precio']) elif user.role == "Administrador": o = Oferta(request.form['nomOferta'], request.form['empresa'], request.form['desc'], request.form['precio']) s.add(o) s.commit() if request.method == 'POST' and 'crearAccion' in request.form: nombre = request.form['nombre'] desc = request.form['desc'] recompensa = request.form['recompensa'] indKpi = request.form['kpi'] kpiObj = request.form['obj'] camp = request.form['campanya'] s = Session() a = Accion(nombre, user.organizacion, desc, recompensa, indKpi, kpiObj, camp) s.add(a) s.commit() try: del session['accionId'] del session['offerId'] except: pass # Borro las keys para evitar conflictos con cookies return render_template('accion.html', title='Acción', wallet=salary, email=email, name=given_name, w3=web3, form=form, form2=form2, user=user, acciones=acciones, campanyas=campanyas, ofertas=ofertas)