示例#1
0
def newPokemon():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        if 'file' not in request.files:
            filename = ''
            print('No file part')
        else:
            file = request.files['file']
            if file.filename == '':
                filename = ''
                print('No selected file')
            if file and allowed_file(file.filename):
                filename = str(datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
                               ) + '_' + secure_filename(file.filename)
                file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        newPokemon = Pokemon(name=request.form['name'],
                             number=request.form['number'],
                             picture=filename,
                             type1=request.form['type1'],
                             type2=request.form['type2'],
                             description=request.form['description'],
                             user_id=login_session['user_id'])
        session.add(newPokemon)
        session.commit()
        flash('New pokemon %s successfully created.' % newPokemon.name)
        return redirect(url_for('showPokemon'))
    else:
        return render_template('newpokemon.html')
def add():
    if 'username' not in login_session:
        return redirect('/pokemons_Catalogue/')

    if request.method == 'POST':
        category = str((request.form['type'])).title()
        category = session.query(Pokemon_Category).filter_by(
            category=category).one_or_none()
        # cate= Pokemon_Category(category=category)
        newPokemon = Pokemon(name=str(request.form['name']),
                             img=str(request.form['image']),
                             description=str(request.form['comment']),
                             created_by=login_session['email'],
                             pokemon_category=category)
        session.add(newPokemon)
        return redirect(url_for('pokemonMenu'))
    else:
        return render_template('add.html')
示例#3
0
def addPokemon():
    pokemons = session.query(Pokemon).all()
    if 'username' not in login_session:
        return redirect('/login')
    pokemoname = []
    for pokemon in pokemons:
        pokemoname.append((pokemon.name).upper())
    if request.method == 'POST':
        name = request.form['name']
        if name.upper() not in pokemoname:
            newPokemon = Pokemon(name=name)
            session.add(newPokemon)
            session.commit()
        else:
            flash('Pokemon Already Exists!')
        flash("Pokemon Added Successfully!")
        return redirect(url_for('showTrainers'))
    else:
        return render_template('addPokemon.html')
示例#4
0
def addPokemon(userid):
    '''this method allows for addition of Pokemon for a specific user'''
    if 'username' not in login_session:
        return redirect('/login')
    if userid != login_session['user_id']:
        return "<script>function myFunction() {alert('You are not authorized to\
 add. Please add Pokemon under own username.');}</script>\
    <body onload='myFunction()'>"

    user = session.query(User).filter_by(userid=userid).one()
    if request.method == 'POST':
        newPokemon = Pokemon(pokemonname=request.form['name'],
                             user_id=login_session['user_id'],
                             picture=request.form['picture'],
                             gender=request.form['gender'])
        session.add(newPokemon)
        session.commit()
        return redirect(url_for('viewPokemons', userid=userid))
    else:
        return render_template('newPokemon.html', user=user)
示例#5
0
def newPkmn(generation_id):
    # check if user is logged in in order to create pkmn
    if 'username' not in login_session:
        return redirect('/login')
    generation = session.query(Generation).filter_by(id=generation_id).one()
    generations = session.query(Generation)
    if request.method == 'POST':
        session.add(
            Pokemon(pkmn_id=request.form['pkmn_id'],
                    pkmn_picture=request.form['pkmn_picture'],
                    pkmn_name=request.form['pkmn_name'],
                    pkmn_type=request.form['pkmn_type'],
                    user_id=login_session['user_id'],
                    generation_id=generation_id))
        session.commit()
        flash("A new pokemon has been created.")
        return redirect(url_for('generations', generation_id=generation_id))
    else:
        return render_template('newPkmn.html',
                               generation_id=generation_id,
                               generations=generations,
                               generation=generation)
示例#6
0
session.add(gen2)
gen3 = Generation(generation_name='Generation III')
session.add(gen3)
gen4 = Generation(generation_name='Generation IV')
session.add(gen4)
gen5 = Generation(generation_name='Generation V')
session.add(gen5)
gen6 = Generation(generation_name='Generation VI')
session.add(gen6)
session.commit()

# add pokemon of gen 1
session.add(
    Pokemon(pkmn_id="#001",
            pkmn_picture="https://cdn.bulbagarden.net/upload/e/ec/001MS.png",
            pkmn_name="Bulbasaur",
            pkmn_type="Grass, Poison",
            generation_relationship=gen1,
            user_id=1))
session.add(
    Pokemon(pkmn_id="#002",
            pkmn_picture="https://cdn.bulbagarden.net/upload/6/6b/002MS.png",
            pkmn_name="Ivysaur",
            pkmn_type="Grass, Poison",
            generation_relationship=gen1,
            user_id=1))
session.add(
    Pokemon(pkmn_id="#003",
            pkmn_picture="https://cdn.bulbagarden.net/upload/d/df/003MS.png",
            pkmn_name="Venusaur",
            pkmn_type="Grass, Poison",
            generation_relationship=gen1,
示例#7
0
bulbasur_move_id_list.append(get_move_id('Synthesis', session))
bulbasur_move_id_list.append(get_move_id('Seed Bomb', session))

bulbasaur_evolution_id_list = []
bulbasaur_evolution_id_list.append(2)

bulbasaur = Pokemon(pokedex_id=1,
                    name='Bulbasaur',
                    description=('Bulbasaur can be seen napping in bright '
                                 'sunlight. There is a seed on its back. By '
                                 'soaking up the sun\'s rays, the seed grows '
                                 'progressively larger.'),
                    image=('https://assets.pokemon.com/assets/cms2/img/'
                           'pokedex/full/001.png'),
                    height=28,
                    weight=15.2,
                    is_mythical=False,
                    is_legendary=False,
                    evolution_before=None,
                    evolution_after_list=bulbasaur_evolution_id_list,
                    type_list=bulbasaur_type_id_list,
                    weakness_list=bulbasaur_weakness_id_list,
                    move_list=bulbasur_move_id_list,
                    category=category_seed,
                    user=user_kanto_admin)

# CHARMANDER
charmander_type_id_list = []
charmander_type_id_list.append(get_type_id('Fire', session))

charmander_weakness_id_list = []
示例#8
0
User1 = User(name="Arpan Badeka",
             email="*****@*****.**",
             hometown="Ujjain")
session.add(User1)
session.commit()

#Create Dummy Users2

User2 = User(name="Ankur Khemani", email="*****@*****.**", hometown="Delhi")
session.add(User2)
session.commit()

#Add Pokemons to PokemonDB

Pokemon1 = Pokemon(name="Pikachu")
session.add(Pokemon1)
session.commit()

Pokemon2 = Pokemon(name="Raichu")
session.add(Pokemon2)
session.commit()

Pokemon3 = Pokemon(name="Squirtle")
session.add(Pokemon3)
session.commit()

#Link users to Pokemons

pokemonuser1 = PokemonUser(user_id=1, pokemon_id=1)
session.add(pokemonuser1)
示例#9
0
def newPokemon():
    """Page for creating a new pokemon entry"""

    # Only logged-in users may add new pokemon
    if 'email' not in login_session:
        return redirect(url_for('showLogin'))

    if request.method == 'POST':
        # Get the values inputted by the user in the form
        if request.form.get('mythical'):
            is_mythical = True
        else:
            is_mythical = False

        if request.form.get('legendary'):
            is_legendary = True
        else:
            is_legendary = False

        newPokemon = Pokemon(pokedex_id=request.form['pokedex_id'],
                             name=request.form['name'],
                             description=request.form['description'],
                             image=request.form['image'],

                             height=(request.form.get(
                                     'height_ft', type=int) * 12) +
                             request.form.get('height_inch', type=int),

                             weight=request.form['weight'],

                             is_mythical=is_mythical,
                             is_legendary=is_legendary,

                             evolution_before=request.form['evolution_before'],
                             evolution_after_list=parse_evolution_after_list(
                                 request.form['evolution_after']),

                             type_list=parse_type_list(request.form['type']),
                             weakness_list=parse_type_list(
                                 request.form['weakness']),
                             move_list=parse_move_list(request.form['move']),
                             category_id=check_category(
                                 request.form['category']),

                             user_id=login_session['user_id'])

        # Add the new pokemon entry to the database
        session.add(newPokemon)
        session.commit()

        # Indicate success in a message
        flash('New pokemon added')

        # Show the newly-added pokemon's details
        returnPokemon = session.query(Pokemon).filter_by(
            pokedex_id=newPokemon.pokedex_id).filter_by(
                name=newPokemon.name).filter_by(
                    description=newPokemon.description).filter_by(
                        image=newPokemon.image).first()
        return redirect(url_for('showPokemon', id=returnPokemon.id))

    else:
        # Show the form for adding new pokemon
        return render_template('new.html')
示例#10
0
    session.delete(i)

session.commit()

print ('Previous database deleted')

# Menu for Electric pokemon

category1 = Pokemon_Category(category='Electric')

session.add(category1)

pokemon1 = Pokemon(name='Pikachu',
                   img="http://www.cartoonbucket.com/wp-content/uploads/"
                   "2015/05/Laughing-Pikachu-Image.png",
                   description="Pikachu, the Mouse Pokemon, and the evolved"
                   "form of Pichu. Pikachu's tail is sometimes struck by"
                   "lightning as it raises it to check its surroundings",
                   created_by='*****@*****.**',
                   pokemon_category=category1)
session.add(pokemon1)

pokemon2 = Pokemon(name='Voltorb',
                   img="https://img00.deviantart.net/c453/i/2016/161/3/c/"
                   "voltorb_png_by_unksoldier55-da5sg2c.png",
                   description="Because of its resemblance to Poke Balls,"
                   "it is thought that it was created when one was exposed to"
                   "an energy pulse. It was first seen in the plant where"
                   "modern Poke Balls were invented. Voltorb is generally"
                   "found in power"
                   "plants and other areas with electric fields.",
                   created_by='*****@*****.**',
示例#11
0
             picture="https://cdn.bulbagarden.net/upload/5/54/Ash_SM.png")
User2 = User(username="******",
             useremail="*****@*****.**",
             picture="https://cdn.bulbagarden.net/upload/6/6a/Brock_SM.png")
User3 = User(username="******",
             useremail="*****@*****.**",
             picture="https://cdn.bulbagarden.net/upload/f/fb/Misty_SM.png")
session.add(User1)
session.add(User2)
session.add(User3)
session.commit()

# Create default pokemon
Pokemon1 = Pokemon(pokemonname="Pikachu",
                   user=User1,
                   picture="https://cdn.bulbagarden.net/upload/1/17/"
                   "025Pikachu-Original.png",
                   gender="Male")
Pokemon2 = Pokemon(pokemonname="Onyx",
                   user=User2,
                   picture="https://cdn.bulbagarden.net/upload/9/9a/"
                   "095Onix.png",
                   gender="Female")
Pokemon3 = Pokemon(pokemonname="Staryu",
                   user=User3,
                   picture="https://cdn.bulbagarden.net/upload/4/4f/"
                   "120Staryu.png",
                   gender="Female")
Pokemon4 = Pokemon(pokemonname="Charizard",
                   user=User1,
                   picture="https://cdn.bulbagarden.net/upload/7/7e/"