Esempio n. 1
0
def newCountry():
    country = Country(name=request.form.get('name'),
                      add_owner=login_session['gplus_id'])

    if 'gplus_id' in login_session:
        session.add(country)
        session.commit()

    return redirect('/')
Esempio n. 2
0
def newCountry():
    if request.method == 'POST':
        newCountry = Country(
            name=request.form['name'], user_id=login_session['user_id'])
        session.add(newCountry)
        flash('New Country %s Successfully Created' % newCountry.name)
        session.commit()
        return redirect(url_for('showCountries'))
    else:
        return render_template('newcountry.html')
Esempio n. 3
0
def newCountry():
    '''Method to add a new country'''
    if request.method == 'POST':
        newCountry = Country(name=request.form['name'],
                             user_id=session_object['user_id'])
        session.add(newCountry)
        flash('Succesfully added new country: %s' % newCountry.name)
        session.commit()
        return redirect(url_for('showCountries'))
    else:
        return render_template('new-country.html')
Esempio n. 4
0
def NewCountry():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newCountry = Country(name=request.form['name'],
                             user_id=login_session['user_id'])
        session.add(newCountry)
        session.commit()
        flash('new country created!')
        return redirect(url_for('CountryList'))
    else:
        return render_template('new-country.html')
Esempio n. 5
0
def addNewCountry():
    if request.method == 'POST':
        newName = request.form['name']
        message = countryConditions(newName, '', False)
        if (message == ''):
            user_var = session.query(User).filter_by(
                id=login_session['id']).first()
            country = Country(name=newName, user=user_var)
            session.add(country)
            session.commit()
            return redirect(
                url_for('countryHighlights', country_name=country.name))
        else:
            return error(message)
    else:
        countries = session.query(Country).order_by(Country.name).all()
        return render_template('addNewCountry.html', countries=countries)
Esempio n. 6
0
from database_setup import Country, Club, base, User

engine = create_engine('sqlite:///clubs.db')
base.metadata.bind = engine
DBsession = sessionmaker(bind=engine)
session = DBsession()

user1 = User(
    name='Hazem Ahmed',
    email='*****@*****.**',
)
session.add(user1)
session.commit()

'#England'
country1 = Country(name='England',
                   img_url='https://images3.alphacoders.com/743/74305.jpg')
session.add(country1)
session.commit()

club1 = Club(
    name='Liverpool',
    description="Liverpool Football Club is a\
 professional football club in Liverpool, England, that competes in the\
 Premier League, the top tier of English football. The club has won six\
 European Cups, more than any other English club, three UEFA Cups and four\
 UEFA Super Cups, also English records, eighteen League titles, seven FA Cups\
 a record eight League Cups and fifteen FA Community Shields.",
    img_url=
    'https://pluspng.com/img-png/logo-liverpool-fc-png-liverpool-fc-logo-500.png',
    country=country1,
    user_id=1)
Esempio n. 7
0
             picture='http://lorempixel.com/200/200/people/1')
session.add(user1)
session.commit()

user2 = User(name="Sharath Kumar", email="*****@*****.**",
             picture='http://lorempixel.com/200/200/people/2')
session.add(user2)
session.commit()

user3 = User(name="Mithun Airani", email="*****@*****.**",
             picture='http://lorempixel.com/200/200/people/3')
session.add(user3)
session.commit()

# Creating country and its missiles
firstCountry = Country(name="India", user_id=1)

session.add(firstCountry)
session.commit()

missile1 = Missile(name="Akash",
                   description="Surface to air missile.",
                   country=firstCountry,
                   link="https://en.wikipedia.org/wiki/Akash_(missile)",
                   user_id=1)
session.add(missile1)
session.commit()

missile2 = Missile(name="Nag",
                   description="Anti tank missile.",
                   country=firstCountry,
Esempio n. 8
0
from sqlalchemy.orm import sessionmaker
from database_setup import Base, Country, TouristPlaces, Users

# Create database and create a shortcut for easier to update database
engine = create_engine('sqlite:///country_catalog.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

# Creating an user
user_1 = Users(name="admin", email="*****@*****.**")
session.add(user_1)
session.commit()

# India
country_1 = Country(user_id=1, name="India")
session.add(country_1)
session.commit()

# Australia
country_2 = Country(user_id=1, name="Australia")
session.add(country_2)
session.commit()

# England
country_3 = Country(user_id=1, name="England")
session.add(country_3)
session.commit()

# Paris
country_4 = Country(user_id=1, name="Paris")
Esempio n. 9
0
engine = create_engine('sqlite:///handmade.db')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

country1 = Country(countryName="Afghanistan")
session.add(country1)
session.commit()
country2 = Country(countryName="Albania")
session.add(country2)
session.commit()
country3 = Country(countryName="Algeria")
session.add(country3)
session.commit()
country4 = Country(countryName="Algeria")
session.add(country4)
session.commit()
country5 = Country(countryName="Algeria")
session.add(country5)
session.commit()
country6 = Country(countryName="Algeria")
Esempio n. 10
0
session = DBSession()

# Create dummy user

User1 = User(
    name='Chandraveer Singh',
    email='*****@*****.**',
    picture=
    'https://png.pngtree.com/element_pic/17/07/23/3e1a80864fe450b9312f5cb7cf486dcf.jpg'
)
session.add(User1)
session.commit()

# Projects in India

country1 = Country(user_id=1, name='India')

session.add(country1)
session.commit()

project1 = Project(
    user_id=1,
    name='Project1',
    description='this is a hrm project',
    number_of_members='60',
    category='HRMProject',
    country=country1,
)

session.add(project1)
session.commit()
Esempio n. 11
0
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create dummy user
User1 = User(name="Jerry Woods",
             email="*****@*****.**",
             picture="/static/img/user_1.jpg")
session.add(User1)
session.commit()

# Create Countries
countries = [{"id": "1", "name": "United States Of America"}]

for country in countries:
    newCountry = Country(id=country["id"], name=country["name"])
    session.add(newCountry)
    session.commit()

# Create states/regions
regions = [{
    "country_id": "1",
    "id": "1",
    "name": "Alabama"
}, {
    "country_id": "1",
    "id": "2",
    "name": "Alaska"
}, {
    "country_id": "1",
    "id": "3",
Esempio n. 12
0
from sqlalchemy.orm import sessionmaker
from database_setup import Base, User, Country, Highlight

engine = create_engine('sqlite:///countries.db')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()

# Add user
user_var = User(username="******", email="*****@*****.**")
session.add(user_var)
session.commit()

# New Zealand
country_var = Country(name="New Zealand", user=user_var)

session.add(country_var)
session.commit()

highlight_var = Highlight(
    name="Taupo",
    prologue="Home to a giant lake.",
    description=
    ("Lake Taupo is the largest freshwater lake in Australasia and is roughly the size of Singapore. The lake is the crater of one of the largest volcanic eruptions of the last 5000 years. Lake Taupo is a staggering 159 metres deep. Skydiving is a popular activity in the Taupo area since Taupo has New Zealand's largest commercial skydive drop zone. Taupo is the skydiving capital of the world with more than 30,000 jumps a year."
     ),
    img_url="/static/medium/taupo-460.jpg",
    country=country_var,
    user=user_var)

session.add(highlight_var)
Esempio n. 13
0
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()

session.query(Country).delete()
session.query(Team).delete()

sample_countries = [
    'Belarus', 'Croatia', 'Spain', 'Germany', 'Hungary', 'France', 'Poland', 
    'Sweden', 'Denmark', 'Turkey', 'Portugal', 'Macedonia', 'Norway', 'Romania', 
    'Austria', 'Iceland', 'Switzerland', 'Slovenia', 'Russia', 'Ukraine'
]

for country_name in sample_countries:
    country = Country(country_name)
    session.add(country)
session.commit()

sample_teams = {
    'HC Meshkov Brest': 1, 'RK Zagreb': 2, 'Aalborg Handbold': 9,
    'HBC Nantes': 6, 'Paris Saint-Germain': 6, 'SG Flensburg-Handewitt': 4,
    'THW Kiel': 4, 'Rhein-Neckar Lowen': 4, 'Pick Szeged': 5,
    'Veszprem KSE ': 5, 'RK Vardar': 12, 'Vive Kielce': 7,
    'Wisla Plock': 7, 'RK Celje': 18, 'Barcelona': 3, 'IFK Kristianstad': 8,
    'Skjern Handbold': 9, 'Montpellier Handball': 6,
    'RK Metalutg Skopje': 12, 'Elverum Handball': 13,
    'Dinamo Bucarest': 14, 'Chekhovskiye Medvedi': 19,
    'RK Gorenje Velenje': 18, 'CB Ademar Leon': 3,
    'Kadetten Schaffhausen': 17, 'Besiktas': 10,
    'HC Motor Zaporozhye': 20, 'Alpla Hard': 15, 'Riihimaki Cocks': 16,
Esempio n. 14
0
session = DBSession()

# Create dummy user

User2 = User(name="yasser", email="*****@*****.**", picture='#')
session.add(User2)
session.commit()

User3 = User(name="yasser2", email="*****@*****.**", picture='#')
session.add(User3)
session.commit()

with open('sample_data/country.csv', 'rb') as csvfile:
    reader = csv.reader(csvfile, delimiter=',', quotechar='"')
    for row in reader:
        country = Country(name=row[0])
        session.add(country)
        session.commit()

with open('sample_data/university.csv', 'rb') as csvfile:
    reader = csv.reader(csvfile, delimiter=',', quotechar='"')
    for row in reader:
        country = session.query(Country).filter_by(name=row[0]).one()
        year_established = datetime.datetime.strptime(row[3],
                                                      "%d/%m/%Y").date()
        university = University(university_name=row[1],
                                common_abbreviation=row[2],
                                year_established=year_established,
                                description=row[4],
                                country_id=country.id,
                                user_id=User2.id)