Example #1
0
def novo_tamagotchi():
    sessao = Session()
    user = sessao.get_logged_user()
    if not user:
        return redirect('.index')

    if request.method == 'GET':
        sessao = Session()
        return render_template('cadastro_tamagotchi.html',
                               pokemons=list(
                                   map(lambda x: x.pokemon,
                                       sessao.get_my_pokemons())),
                               titulo='Criar Tamagotchi')
    elif request.method == 'POST':
        POST_NOME = request.form['nome']
        IMAGEM = request.form['poke']
        error = False

        sessao = Session()
        if sessao.verify_if_exist(POST_NOME):
            flash("Ja existe um tamagotchi com este nome")
            error = True

        if not error:
            sessao = Session()
            user = sessao.get_logged_user()

            tamagotchi.ListTamagotchi().saveDatabase(name=POST_NOME,
                                                     user_id=user.id,
                                                     imagem=IMAGEM)

            return redirect(url_for('.index'))
        else:
            return redirect(url_for('.novo_tamagotchi'))
Example #2
0
def actions():
    if request.method == 'POST':
        list = tamagotchi.ListTamagotchi()

        id = int(request.form['id'])
        value = int(request.form['value'])
        action = str(request.form['action'])

        if action == 'health':
            list.update(id=id, health=value)

        if action == 'hunger':
            list.update(id=id, hunger=value)

        if action == 'happy':
            list.update(id=id, happy=value)
        return jsonify({'action': action, 'value': value, 'id': id})
    return jsonify({'error': 'metodo invalido'})
Example #3
0
 def verify_if_exist(self, nome):
     tama = tamagotchi.ListTamagotchi()
     return tama.verify_if_exist(nome)
Example #4
0
 def load_tamagotchi(self, by=None, value=None):
     tama = tamagotchi.ListTamagotchi()
     if by:
         return tama.load(by, value)
     else:
         return tama.load_all()