예제 #1
0
파일: School.py 프로젝트: vmm86/younoshi
def listSchool(cityid):
    # Список городов, название текущего города
    listCity = City.select().order_by(City.cityName)
    try:
        cityname = City.get(city_ID = cityid).cityName
    except DoesNotExist:
        cityname = None

    # Список школ и количества их дочерних команд
    listSchool = School.select(School, fn.Count(Team.school_ID).alias('countTeams')).join(Team, JOIN_LEFT_OUTER).switch(School).join(City).where(City.city_ID == cityid).group_by(School).order_by(School.schoolName)

    # Переменные для автозаполнения модальной формы добавления/обновления данных в JS-скрипте шаблона
    ## Список полей
    modifyFields = ['schoolName', 'cityName']
    ## Заголовки модального окна
    createHeader = ['"Создать новую спортивную школу"']
    updateHeader = ['"Изменить "', 'schoolName', '" ("', 'cityName', '")"']
    ## Действия формы
    createAction = ['"/city/"', cityid, '"/school/create"']
    updateAction = ['"/city/"', cityid, '"/school/"', 'PK_ID', '"/update"']
    deleteAction = ['"/city/"', cityid, '"/school/"', 'PK_ID', '"/delete"']

    # Вывод шаблона
    return render_template(
        'School.jinja.html', 
        listCity   = listCity, 
        cityid     = cityid, 
        cityname   = cityname, 
        listSchool = listSchool,
        modifyFields = modifyFields,
        createHeader = createHeader,
        updateHeader = updateHeader,
        createAction = createAction,
        updateAction = updateAction,
        deleteAction = deleteAction)
예제 #2
0
def getCity(city, province):
    if not city:
        return None
    c = City.nodes.get_or_none(name=city)
    if not c:
        c = City(name=city).save()
        if province:
            c.province.connect(province)
    c.save()
    return c
예제 #3
0
파일: Team.py 프로젝트: vmm86/younoshi
def listTeam(cityid, schoolid):
    # Список городов и их дочерних школ, название текущего города и школы
    listCity   = City.select().order_by(City.cityName)
    listSchool = School.select().join(City).where(City.city_ID == cityid).order_by(School.schoolName)
    try:
        cityname   = City.get(city_ID = cityid).cityName
        schoolname = School.get(school_ID = schoolid).schoolName
    except DoesNotExist:
        cityname   = None
        schoolname = None

    # Список команд в выбранной школе
    listTeam = Team.select().join(School).where(School.school_ID == schoolid).join(City).where(City.city_ID == cityid).switch(Team).join(Age).order_by(Team.teamName)
    for lt in listTeam:
        lt.age_ID.ageName = int(date.today().year) - int(lt.age_ID.ageName)

    # Список возрастов по состоянию на текущий год
    listAge  = Age.select().order_by(Age.ageName)
    for age in listAge:
        age.ageName = int(date.today().year) - int(age.ageName)

    # Переменные для автозаполнения модальной формы добавления/обновления данных в JS-скрипте шаблона
    ## Список полей
    modifyFields = ['teamName', 'filterAge', 'ageName']
    ## Список групп радиокнопок
    modifyRadios = ['filterAge']
    ## Заголовки модального окна
    createHeader = ['"Создать новую юношескую команду"']
    updateHeader = ['"Изменить "', 'teamName', '" (возраст "', 'ageName', '")"']
    ## Действия формы
    createAction = ['"/city/"', cityid, '"/school/"', schoolid, '"/team/create"']
    updateAction = ['"/city/"', cityid, '"/school/"', schoolid, '"/team/"', 'PK_ID', '"/update"']
    deleteAction = ['"/city/"', cityid, '"/school/"', schoolid, '"/team/"', 'PK_ID', '"/delete"']

    # Вывод шаблона
    return render_template(
        'Team.jinja.html', 
        listCity     = listCity, 
        cityid       = cityid, 
        cityname     = cityname, 
        listSchool   = listSchool, 
        schoolid     = schoolid, 
        schoolname   = schoolname,
        listTeam     = listTeam,
        listAge      = listAge, 
        modifyFields = modifyFields,
        modifyRadios = modifyRadios,
        createHeader = createHeader,
        updateHeader = updateHeader,
        createAction = createAction,
        updateAction = updateAction,
        deleteAction = deleteAction)
예제 #4
0
파일: City.py 프로젝트: vmm86/younoshi
def createCity():
    # Получение полей формы из шаблона
    cityname = request.form['cityName']

    # Сохранение новой записи в БД
    if session['demo']:
        pass
    else:
        City.create(
            cityName = cityname)

    # Редирект на вид list
    return redirect(
        url_for('listCity'))
예제 #5
0
파일: City.py 프로젝트: vmm86/younoshi
def deleteCity(cityid):
    # Удаление текущей записи в БД
    if session['demo']:
        pass
    else:
        # Ограничение по внешнему ключу FK_School_City 
        # не позволяет удалить населённый пункт при наличии связанных с ним спортивных школ.
        try:
            City.get(city_ID = cityid).delete_instance()
        except IntegrityError:
            flash('Вы не можете удалить этот город, пока в него добавлена хотя бы одна спортивная школа', 'danger')

    # Редирект на вид list
    return redirect(
        url_for('listCity'))
예제 #6
0
파일: City.py 프로젝트: vmm86/younoshi
def updateCity(cityid):
    # Получение полей формы из шаблона
    cityname = request.form['cityName']

    # Обновление текущей записи в БД
    if session['demo']:
        pass
    else:
        city          = City()
        city.city_ID  = cityid
        city.cityName = cityname
        city.save()

    # Редирект на вид list
    return redirect(
        url_for('listCity'))
예제 #7
0
def seed_cities():
    """Add all cities in Biz table to Cities table"""
    # should be 95 cities
    # select city, state from biz group by state, city
    # group by state, city
    all_cities = db.session.query(PlatePalBiz.city, PlatePalBiz.state).filter(
        PlatePalBiz.city != u"blacksburg",
        PlatePalBiz.city != u'Carrboro Saxapahaw Chapel Hill Durham',
        PlatePalBiz.city != u'Greenbelt ')
    cities = all_cities.group_by(PlatePalBiz.state).group_by(
        PlatePalBiz.city).all()

    # calculate lat/lng for each city
    geolocator = Nominatim()
    for city in cities:
        location = geolocator.geocode(city[0] + " " + city[1])
        print city
        print "Lat: {}, Lng: {}".format(location.latitude, location.longitude)
        new_city = City(city=city[0],
                        state=city[1],
                        lat=location.latitude,
                        lng=location.longitude)
        db.session.add(new_city)
    db.session.commit()
    return
예제 #8
0
파일: seed.py 프로젝트: chat19/Travel_App
def load_cities():
    """Load users from u.user into database."""

    print "City"

    for row in open("seed_data/u.flight_data"):
        row = row.rstrip()
        print row.split("|")

        city_id, origin_airport, destination_airport, destination, departure_date, return_date, highest_predicted_fares, currency_code, lowest_predicted_fares, recommendation, lowest_fare, destination_info = row.split(
            "|")

        city = City(
            city_id=city_id,
            origin_airport=origin_airport,
            destination_airport=destination_airport,
            destination=destination,
            departure_date=departure_date,
            return_date=return_date,
            lowest_predicted_fares=lowest_predicted_fares,
            lowest_fare=lowest_fare,
            recommendation=recommendation,
            destination_info=destination_info,
        )

        # We need to add to the session or it won't ever be stored
        db.session.add(city)

        # provide some sense of progress

    # Once we're done, we should commit our work
    db.session.commit()
예제 #9
0
    def setUp(self):
        """Stuff to do before every test."""

        # Get the Flask test client
        self.client = app.test_client()
        app.config['TESTING'] = True
        app.config['SECRET_KEY'] = os.environ['SECRET_KEY']

        # Logs in test user
        with self.client as c:
            with c.session_transaction() as sess:
                sess['user_id'] = 1

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()

        user = User(username='******', password='******')
        city = City(name='San Francisco')
        destination = Destination(
            city=city,
            name='Mission Dolores Park',
            address='Dolores St &, 19th St, San Francisco, CA 94114')

        db.session.add_all([user, city])
        db.session.commit()
예제 #10
0
파일: city.py 프로젝트: wasimakh2/automato
def add_city():
    if request.method == 'POST':
        payload = request.json
        print(payload)
        if len(payload['name']) != 0:

            check_data = City.query.filter_by(name=payload['name'].lower().strip())
            if check_data.first():
                return jsonify({'message': 'Data - '+check_data.first().name+' already exists.'})
            else:
                try:
                    if 'state' not in payload.keys():
                        payload['state'] = ""
                    if 'country' not in payload.keys():
                        payload['country'] = ""

                    new_data = City(
                        payload['name'].lower().strip() , payload['state'].lower().strip() , payload['country'].lower().strip())

                    db.session.add(new_data)
                    db.session.commit()
                    json_data = { 'id' : new_data.id , 'name' : new_data.name}
                    return jsonify({'success': 'Data Added', 'data' : json_data})

                except Exception as e:
                    print(str(e))
                    db.session.rollback()
                    db.session.close()
                    return jsonify({'message': 'Something unexpected happened. Check logs', 'log': str(e)})
        else:
            return jsonify({'message': 'Empty Data.'})

    else:
        return jsonify({'message': 'Invalid HTTP method . Use POST instead.'})
예제 #11
0
파일: City.py 프로젝트: vmm86/younoshi
def listCity():
    # Вывод списка городов и количества их дочерних школ
    listCity = City.select(City, fn.Count(School.city_ID).alias('countSchools')).join(School, JOIN_LEFT_OUTER).group_by(City).order_by(City.cityName)

    # Переменные для автозаполнения формы добавления/обновления данных в JS-скрипте шаблона
    ## Список полей
    modifyFields = ['cityName']
    ## Заголовки модального окна
    createHeader = ['"Создать новый населённый пункт"']
    updateHeader = ['"Изменить "', 'cityName']
    ## Действия формы
    createAction = ['"/city/create"']
    updateAction = ['"/city/"', 'PK_ID', '"/update"']
    deleteAction = ['"/city/"', 'PK_ID', '"/delete"']

    # Вывод шаблона
    return render_template(
        'City.jinja.html', 
        listCity     = listCity,
        modifyFields = modifyFields,
        createHeader = createHeader,
        updateHeader = updateHeader,
        createAction = createAction,
        updateAction = updateAction,
        deleteAction = deleteAction)
예제 #12
0
def create_city(city, state, forecast_office_id):
    """ Create and return a new city"""

    city = City(city=city, state=state, forecast_office_id=forecast_office_id)

    db.session.add(city)
    db.session.commit()

    return city
예제 #13
0
def add_city():
    name = request.form.get('name')
    try:
        cty = City(name=name)
        db.session.add(cty)
        db.session.commit()
    except Exception:
        flash('')
        return redirect(url_for('city'))
    return redirect(url_for('city'))
예제 #14
0
def display():
    print("List of countries:")
    [print(
        "    -",
        country,
    ) for country in Country.get_names()]
    print("List of cities:")
    [print(
        "    -",
        city,
    ) for city in City.get_names()]
예제 #15
0
def add_city(city_name, country_code, teleport_id, urban_area=None, latlon=None):
    """Basic function to add a city to db."""

    city = City(city_name=city_name, country_code=country_code, 
                teleport_id=teleport_id, urban_area=urban_area, latlon=latlon)

    print(f">> before trying to init this city: {city}")
    db.session.add(city)
    db.session.commit()
    print(f">> after db commit: {city}")

    return city
예제 #16
0
def load_cities(file_user):

    # City.query.delete()

    for row in (open(file_user)):
        row = row.strip()

        city, county = row.split(",")

        new_city = City(city=city, county=county)

        db.session.add(new_city)
        db.session.commit()
예제 #17
0
def create_city(city_name, country, iso2, lat, lon, pop):
    """Create and return a city with their lat & lon"""
    city = City(city_name=city_name,
                country=country,
                iso2=iso2,
                lat=lat,
                lon=lon,
                pop=pop)

    db.session.add(city)
    db.session.commit()

    return city
예제 #18
0
def create_city(city_name, country_name, geo_lat, geo_lng):

    city = City(city_name=city_name,
                country_name=country_name,
                geo_lat=geo_lat,
                geo_lng=geo_lng)

    print(city)

    db.session.add(city)
    db.session.commit()

    return city
예제 #19
0
def get_city_id(city):
    """Get the city id from database. Otherwise, add city to database and get the city id."""

    try:
        existing_city = db.session.query(City).filter(City.name == city).one()

    except NoResultFound:
        new_city = City(name=city)
        db.session.add(new_city)
        db.session.commit()
        return new_city.city_id

    return existing_city.city_id
예제 #20
0
파일: server.py 프로젝트: wliu16/HikeSF
def load_cities():
    """
    load cities available
    """
    for row in open("data/cities.csv"):
        row = row.rstrip()
        name = row.split(",")[1]
        city = City(name=name)
        try:
            tmp_res = db.session.query(City).filter(City.name == name).one()
        except NoResultFound:
            db.session.add(city)
            db.session.commit()
예제 #21
0
def load_cities():
    """Load all the available cities users can choose from."""

    for row in open('seed_data/u.cities'):

        row = row.rstrip()
        city_id, name = row.split('|')

        city = City(city_id=city_id, name=name)

        db.session.add(city)

    db.session.commit()
예제 #22
0
파일: app.py 프로젝트: wildanshq/DVD_rental
def add_city():
    body = request.json
    city = body.get('city')
    country_id = body.get('country_id')

    try:
        city = City(city, country_id)
        city_schema = CitySchema()
        db.session.add(city)
        db.session.commit()
        return jsonify(city_schema.dump(city))
    except Exception as e:
        return jsonify(eror=str(e))
예제 #23
0
 def add_city(self):
     from model import City
     city = City()
     city.id = 2
     city.cityname = "杭州"
     city.cityid = "2"
     city.provinceid = "1"
     self.session.add(city)
     self.session.commit()
예제 #24
0
def load_cities():

    print "Cities"

    url = "http://api.travelpayouts.com/data/cities.json?token={}".format(
        travel_payouts_api)

    r = requests.get(url)
    data = r.text
    results = json.loads(data)

    for key in results:
        city_name = key['name'].encode('utf-8')
        city_code = key['code'].encode('utf-8')
        country_code = key['country_code'].encode('utf-8')
        country = Country.query.filter(Country.code == country_code).first()
        if country:
            country_id = country.id
            city = City(name=city_name, code=city_code, country_id=country_id)
        else:
            city = City(name=city_name, code=city_code)
        db.session.add(city)

    db.session.commit()
예제 #25
0
파일: crud.py 프로젝트: yuchida522/onTrack
def create_city(city_name, zipcode):
    """function that saves city information of the race from API call to db"""

    exists = City.query.filter_by(city_name=city_name).first()
    city = City(city_name=city_name, zipcode=zipcode)

    if not exists:

        #add city to db
        db.session.add(city)
        db.session.commit()

        return city
    else:
        return exists
예제 #26
0
def write_citiesdb(city_dict, countries):
    """ Write the cities from dictionary in read_city_file to database

    write_citiesdb({'Sao Paolo': [Brazil', '-23.56288', '-46.654659']})
    'Sao Paolo': [Brazil', '-23.56288', '-46.654659']

    """
    # instantiate objects of each city with values from dictionary
    for city in city_dict:
        city_table = City(city_name=city,
                          country_code=countries[city_dict[city][0]],
                          city_lat=city_dict[city][1],
                          city_long=city_dict[city][2])
        db.session.add(city_table)

    db.session.commit()
예제 #27
0
def load_cities():
    """Load cities into database."""

    cities = []

    for row in (open('cities.txt')):
        city = row.rstrip()
        cities.append(city)

    ordered_cities = sorted(cities)

    for city in ordered_cities:
        find_city = City.query.filter_by(name=city).first()
        if not find_city:
            city = City(name=city)
            db.session.add(city)

    db.session.commit()
    print "Cities loaded."
예제 #28
0
def make_test_cities():
    """Create some cities for testing."""
    cities = {
        'San Francisco': {'ccode': 'USA', 'tid': 5391959, 'urban_area': 'Bay Area', 
                          'latlon': (37.77493, -122.41942)},
        'London': {'ccode':'GBR', 'tid': 2643743, 'latlon': (51.50853, -0.12574)}, 
        'Paris': {'ccode': 'FRA', 'tid': 2988507, 'latlon': (48.85341, 2.3488)},
        'Taipei': {'ccode': 'TWN', 'tid': 1668341, 'latlon': (25.04776, 121.53185)}
    }

    for c, cinfo in cities.items():
        city = City(city_name=c, urban_area=cinfo.get('urban_area'), 
                    teleport_id=cinfo.get('tid'), country_code=cinfo['ccode'], 
                    latlon=cinfo.get('latlon'))
        db.session.add(city)

    db.session.commit()

    print("*** Success: Added some cities ***")
def create_missing_country_city():

    to_save = []
    cnt_added = 0
    city_add = 0
    with open('../../data/json/finale.json') as ffop:
        data = json.load(ffop)
        for line in data:
            if 'continent_code' in line.keys():
                if not sess.query(Country).filter_by(
                        country_code=line['country_code']).all():
                    continent = sess.query(Continent).filter_by(
                        continent_code=line['continent_code']).all()[0]
                    continent_id = continent.id
                    country = Country(name=line['country_full'],
                                      country_code=line['country_code'],
                                      continent_id=continent_id)
                    sess.add(country)
                    sess.commit()
                    print('Added a country:', line['country_full'])
                    cnt_added += 1
                    print(cnt_added)

                else:
                    country = sess.query(Country).filter_by(
                        country_code=line['country_code']).all()[0]
                    city = City(name=line['city_name'],
                                city_id=line['city_id'],
                                country_id=country.id,
                                lat=line['lat'],
                                lon=line['lon'])
                    city_add += 1
                    to_save.append(city)
                    print('Added a city:', line['city_name'])
                    print(city_add)

    sess.bulk_save_objects(to_save)
    sess.commit()
예제 #30
0
def load_cities(cities_filename):
    """Load cities from file into database."""

    print("Cities")

    for i, row in enumerate(open(cities_filename)):
        row = row.rstrip()
        name, lat, lon, country_code, population, timezone = row.split("|")

        lat = float(lat)
        lon = float(lon)

        city = City(name=name,
                    lat=lat,
                    lon=lon,
                    country_code=country_code,
                    timezone=timezone)

        # add user to the session
        db.session.add(city)

    # commit session
    db.session.commit()
예제 #31
0
def install():
    Base.metadata.create_all(Session().bind)

    data = [('Chicago', 'United States', ('60601', '60602', '60603', '60604')),
            ('Montreal', 'Canada', ('H2S 3K9', 'H2B 1V4', 'H7G 2T8')),
            ('Edmonton', 'Canada', ('T5J 1R9', 'T5J 1Z4', 'T5H 1P6')),
            ('New York', 'United States', ('10001', '10002', '10003', '10004',
                                           '10005', '10006')),
            ('San Francisco', 'United States', ('94102', '94103', '94104',
                                                '94105', '94107', '94108'))]

    countries = {}
    all_post_codes = []
    for city, country, postcodes in data:
        try:
            country = countries[country]
        except KeyError:
            countries[country] = country = Country(country)

        city = City(city, country)
        pc = [PostalCode(code, city) for code in postcodes]
        Session.add_all(pc)
        all_post_codes.extend(pc)

    for i in xrange(1, 51):
        person = Person(
            "person %.2d" % i,
            Address(street="street %.2d" % i,
                    postal_code=all_post_codes[random.randint(
                        0,
                        len(all_post_codes) - 1)]))
        Session.add(person)

    Session.commit()

    # start the demo fresh
    Session.remove()
예제 #32
0
    if city == "":
        if state == "":
            city = country
        else:
            city = state

    # Checks for empty values

    try:
        city_obj = City.query.filter_by(name=str(city)).first()

        if city_obj:
            pass
        else:
            city_obj = City(str(city), str(state), str(country))
            db.session.add(city_obj)

        con_obj = Contact(name, contact, "", "", "", city_obj)
        db.session.add(con_obj)

        for item in tag:
            tag_obj = Tag.query.filter_by(name=item).first()
            if tag_obj:
                pass
            else:
                tag_obj = Tag(str(item))
                db.session.add(tag_obj)

            con_obj.tag_contact.append(tag_obj)
예제 #33
0
def add_rec_to_db():
    """recordes info submitted by user, creates the objects for the db, and adds to the db"""

    #Update session on login - get the username in the session
    username = session['username']

    #then get that user's user object,
    user_obj = User.query.filter_by(username=username).first()

    #then get the user id to pass into the rec table
    user_id = user_obj.user_id


    #get the city_name & info separately since we need city_name for a query
    city_name = request.form.get('city_name')
    city_name = city_name.lower()
    city_info = request.form.get('city_info')


    #create the city obj if it doesn't exist other wise get the city_id for recs instantiation.
    city_obj = City.query.filter_by(city_name=city_name).first()
        
    if city_obj == None:
        city = City(city_name=city_name, city_info=city_info)
        db.session.add(city)
        db.session.commit()
        city_id = city.city_id
    else:    
        city_id = city_obj.city_id

    #get the path for four images, save it in the directory and then save the path before adding to the db in url variable
    file = request.files['file']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        app.logger.info(os.path.join(app.config['UPLOAD_FOLDER']))
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        img_url = f'static/images/{filename}'

    file = request.files['file2']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        app.logger.info(os.path.join(app.config['UPLOAD_FOLDER']))
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        img_url2 = f'static/images/{filename}'

    file = request.files['file3']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        app.logger.info(os.path.join(app.config['UPLOAD_FOLDER']))
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        img_url3 = f'static/images/{filename}'

    file = request.files['file4']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        app.logger.info(os.path.join(app.config['UPLOAD_FOLDER']))
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        img_url4 = f'static/images/{filename}'



    #add to the database
    recommendation = Recommendation(rec_name = request.form.get('rec_name'), stay_name= request.form.get('stay_name'), 
                stay_info = request.form.get('stay_info'), eat_name= request.form.get('eat_name'), 
                eat_info = request.form.get('eat_info'), do_name= request.form.get('do_name'), 
                do_info = request.form.get('do_info'), user_id=user_id, city_id=city_id, img_url=img_url, img_url2=img_url2, img_url3=img_url3, img_url4=img_url4)

    #call the save function to add to the database
    db.session.add(recommendation)
    db.session.commit()

    flash("Awesome! You've created a recommendation")
    return redirect(f'/view_recommendation/{recommendation.rec_id}')
예제 #34
0
 def test_calculate_tiles(self):
     c1 = City("London", x=5, y=1, x2=5, y2=1, city_type="normal")
     c2 = City("Berlin", 3, 9, 4, 10, "mammoth market")
     self.assertListEqual(c1.tiles, [(5, 1)])
     self.assertListEqual(c2.tiles, [(3, 9), (3, 10), (4, 9), (4, 10)])
예제 #35
0
파일: contacts.py 프로젝트: ural23/automato
def upload_contact():
    file = request.files['file']
    tags = json.loads(request.form['data'])
    try:
        if file:
            filename = file.filename
            foldertemp = os.path.join(UPLOAD_FOLDER, 'contacts')

            if os.path.exists(foldertemp):
                filetemp = os.path.join(foldertemp, filename)
                file.save(filetemp)
            else:

                os.makedirs(foldertemp)

                filetemp = os.path.join(foldertemp, filename)
                file.save(filetemp)

            with open(filetemp, mode="r") as csv_file:

                csv_data = list(csv.reader(csv_file, delimiter=","))

                for item in csv_data:
                    name = item[0] + '-' + item[1]
                    contact_one = str(item[6])
                    contact_two = str(item[7])
                    address = str(item[2])
                    city = item[3].lower()
                    state = item[4]
                    country = item[5]
                    email = item[8]
                    tag = tags
                    city = city.split('-')[0].split('(')[0]

                    if len(contact_one) == 10:
                        contact_one = '91' + contact_one

                    if city == "":
                        if state == "":
                            city = country
                        else:
                            city = state

                    # Checks for empty values
                    if item[0] is not "":

                        try:
                            city_obj = City.query.filter_by(
                                name=str(city)).first()

                            if city_obj:
                                pass
                            else:

                                city_obj = City(str(city), str(state),
                                                str(country))
                                db.session.add(city_obj)

                            con_obj = Contact(name, contact_one, contact_two,
                                              address, email, city_obj)
                            db.session.add(con_obj)

                            for item in tag:
                                tag_obj = Tag.query.filter_by(
                                    name=item['name']).first()
                                if tag_obj:
                                    pass
                                else:
                                    pass
                                    tag_obj = Tag(str(item['name']))
                                    db.session.add(tag_obj)

                                con_obj.tag_contact.append(tag_obj)
                            db.session.commit()
                        except IntegrityError as e:
                            db.session.rollback()
                            print('Duplicate ----- ' + name, city)
                            pass
                        except Exception as e:
                            db.session.rollback()
                            print('Oh No ---------', name, city)
                            pass
                    else:
                        pass

        return jsonify({'success': 'Data Added'})

    except Exception as e:
        # return Exception for duplicate data
        print(str(e))
        return jsonify({'message': 'Returns error'})
예제 #36
0
def seed_city():
    """Seed  cities table."""
    # This function will demonstrate how to seed city table.

    paris = City(city_name="Paris, France")
    london = City(city_name="London, United Kingdom")
    barcelona = City(city_name="Barcelona, Spain")
    istanbul = City(city_name="Istanbul, Turkey")
    madrid = City(city_name="Madrid, Spain")
    nice = City(city_name="Nice, France")
    berlin = City(city_name="Berlin, Germany")
    hongkong = City(city_name="Hong Kong, Hong Kong")
    singapore = City(city_name="Singapore, Singapore")
    sanfrancisco = City(city_name="San Francisco, United States")
    newyork = City(city_name="New York, United States")
    losangeles = City(city_name="Los Angeles, United States")
    chicago = City(city_name="Chicago, United States")

    db.session.add_all([
        paris, london, barcelona, istanbul, madrid, nice, berlin, hongkong,
        singapore, sanfrancisco, newyork, losangeles, chicago
    ])

    db.session.commit()
예제 #37
0
파일: SAST.py 프로젝트: vmm86/younoshi
def listSAST(seasonid, ageid, sasid):
    # Список сезонов и возрастов по состоянию на текущий год, название текущего сезона и возраста, название и тип игровой стадии текущего игрового этапа
    listSeason = Season.select().order_by(Season.season_ID.asc())
    listAge = Age.select().order_by(Age.ageName)
    for age in listAge:
        age.ageName = int(date.today().year) - int(age.ageName)
    try:
        seasonname = Season.get(season_ID = seasonid).seasonName
        agename    = Age.get(age_ID = ageid).ageName
        sasname    = SAS.get(SAS_ID = sasid).stage_ID.stageName
        sastype    = SAS.get(SAS_ID = sasid).stage_ID.stageType
    except DoesNotExist:
        seasonname = None
        agename    = None
        sasname    = None
        sastype    = None

    # Список игровых этапов по типам
    listSAS_Z = SAS.select().where(SAS.season_ID == seasonid, SAS.age_ID == ageid).join(Stage).where(Stage.stageType == "Z").order_by(Stage.stageName)
    listSAS_G = SAS.select().where(SAS.season_ID == seasonid, SAS.age_ID == ageid).join(Stage).where(Stage.stageType == "G").order_by(Stage.stageName)
    listSAS_P = SAS.select().where(SAS.season_ID == seasonid, SAS.age_ID == ageid).join(Stage).where(Stage.stageType == "P").order_by(Stage.stageName)

    # Список городов, спортивных школ и команд для фильтрации по связанным выпадающим спискам
    filterCity   =   City.select().order_by(City.cityName)
    filterSchool = School.select().order_by(School.schoolName)
    filterTeam   =   Team.select().order_by(Team.teamName)

    # Список команд в текущем игровом этапе
    listSAST  = SAST.select().where(SAST.SAS_ID == sasid).join(Stage, JOIN_LEFT_OUTER).order_by(SAST.SAST_ID)
    # Список игровых стадий
    listStage = Stage.select().order_by(Stage.stageType, Stage.stageName).order_by(Stage.stage_ID)

    # Есть ли в текущем игровом этапе подгруппы
    is_SASTsubstage  = SAST.select().where(SAST.SAS_ID == sasid).join(Stage).exists()
    # Список подгрупп текущего игрового этапа (если они есть)
    listSASTsubstage = SAST.select(SAST.substage_ID).distinct().where(SAST.SAS_ID == sasid).join(Stage, JOIN_LEFT_OUTER)

    # Переменные для автозаполнения формы добавления/обновления данных в JS-скрипте шаблона
    ## Список полей
    modifyFields = ['filterCity', 'filterSchool', 'filterTeam', 'substage_ID', 'stageType', 'stageName']
    ## Список групп радиокнопок
    modifyRadios = ['substage_ID']
    ## Список выпадающих списков
    modifySelect = ['filterCity', 'filterSchool', 'filterTeam']   
    ## Заголовки модального окна
    createHeader = ['"Добавить команду в "', 'stageType', '" "', 'stageName']
    updateHeader = ['"Изменить команду, участвующую в "', 'stageType', '" "', 'stageName']
    ## Действия формы
    createAction = ['"/season/"', seasonid, '"/age/"', ageid, '"/stage/"', sasid, '"/team/create"']
    updateAction = ['"/season/"', seasonid, '"/age/"', ageid, '"/stage/"', sasid, '"/team/"', 'PK_ID', '"/update"']
    deleteAction = ['"/season/"', seasonid, '"/age/"', ageid, '"/stage/"', sasid, '"/team/"', 'PK_ID', '"/delete"']

    # Вывод шаблона
    return render_template(
        'SAST.jinja.html', 
        listSeason       = listSeason,
        seasonid         = seasonid,
        seasonname       = seasonname,
        listAge          = listAge,
        ageid            = ageid,
        agename          = agename,
        listSAS_Z        = listSAS_Z,
        listSAS_G        = listSAS_G,
        listSAS_P        = listSAS_P,
        sasid            = sasid,
        sasname          = sasname,
        sastype          = sastype,
        filterCity       = filterCity,
        filterSchool     = filterSchool,
        filterTeam       = filterTeam,
        listSAST         = listSAST,
        listStage        = listStage,
        is_SASTsubstage  = is_SASTsubstage,
        listSASTsubstage = listSASTsubstage,
        modifyFields     = modifyFields,
        modifyRadios     = modifyRadios,
        modifySelect     = modifySelect,
        createHeader     = createHeader,
        updateHeader     = updateHeader,
        createAction     = createAction,
        updateAction     = updateAction,
        deleteAction     = deleteAction)