Ejemplo n.º 1
0
def import_via_schoolsoft_view_via_post(request):
    import shutil, os
    from tempfile import NamedTemporaryFile
    import xlrd
    import sqlalchemy
    from pkg_resources import resource_filename
    from pyramid.httpexceptions import HTTPFound
    from pyramid_sqlalchemy import Session
    from ..models import NewStudentModel
    from ..forms import UploadForm

    form = UploadForm(request.POST)

    if form.validate():
        with NamedTemporaryFile(delete=True) as f:
            shutil.copyfileobj(form.file.data.file, f)
            f.flush()
            f.seek(0)
            workbook = xlrd.open_workbook(f.name)
            table = workbook.sheet_by_index(0)
            start_row = 3
            end_column = 38
            changed_list = []
            for i in range(3, table.nrows):
                try:
                    new_student = Session.query(NewStudentModel).filter_by(id_number=table.cell(i, 3).value).one()
                    new_student.school_number = table.cell(i, 33).value
                    new_student.klass         = table.cell(i, 34).value
                    new_student.class_number  = table.cell(i, 35).value

                    # 改大頭照檔名
                    if new_student.picture_name:
                        basename, extname = new_student.picture_name.split('.')
                        newname = '.'.join([new_student.school_number, extname])
                        pictures_dir_root = resource_filename('tp_enroll', 'static/pictures')
                        src_file = os.path.join(pictures_dir_root, new_student.picture_name)
                        dst_file = os.path.join(pictures_dir_root, newname)
                        shutil.move(src_file, dst_file)
                        new_student.picture_name = newname

                    changed_list.append(new_student)
                except (sqlalchemy.orm.exc.NoResultFound, FileNotFoundError):
                    pass
            if changed_list:
                Session.add_all(changed_list)
            return HTTPFound(location=request.route_path('home'))
    else:
        return {'form': form}
Ejemplo n.º 2
0
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    Session.configure(bind=engine)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    with transaction.manager:

        products = [Product(id=1, name='Capsule House'), Product(id=2, name='Electric Rice Cooker'),
                    Product(id=3, name='Electric Rice Cooker'), Product(id=4, name='Silverstar 4'),
                    Product(id=5, name='Hydrojet'), Product(id=6, name='Archeological Evacuation Robot'),
                    Product(id=7, name='Time machine'), Product(id=8, name='Boat'),
                    Product(id=14, name='Motorcycle'), Product(id=19, name='Small Pirate Submarine'),
                    Product(id=21, name='Mines'), Product(id=22, name='Battle Information Building'),
                    Product(id=23, name='Team Reception Building'), Product(id=29, name='Clothing Shop Building'),
                    Product(id=30, name='Accessory Shop Building'), Product(id=36, name='Powersuit'),
                    Product(id=39, name='Mix Shop Building'), Product(id=43, name='Messerschmitt KR'),
                    Product(id=61, name='Airplane'), Product(id=67, name='Hoverbike'),
                    Product(id=69, name='Powersuit'), Product(id=80, name='Submarine'),
                    Product(id=82, name='Flying Vehicle'), Product(id=85, name='West City Police scooter'),
                    Product(id=87, name='Jet-copter'), Product(id=88, name='Skill Shop Building'),
                    Product(id=96, name='Spatiotemporal Delivery Service Building'), Product(id=103, name='Airplane'),
                    Product(id=115, name='Airplane (4 passengers)'), Product(id=116, name='Hot Air Balloon'),
                    Product(id=192, name='Airship'), Product(id=239, name='Large plane (King Castle)'),
                    Product(id=240, name='Large plane'), Product(id=333, name='Penguin 333 fridge'),
                    Product(id=339, name='Airplane'), Product(id=341, name='Flying Vehicle'),
                    Product(id=462, name='Item Shop Building'), Product(id=576, name='VTOL Plane'),
                    Product(id=673, name='Yellow Van'), Product(id=991, name='Airplane'),
                    Product(id=1138, name='Spaceship'), Product(id=2031, name='Caps Fridge'),
                    Product(id=2150, name='West City Taxi'), Product(id=2402, name='Great Saiyaman Watch'),
                    ]
        cities = [City(name='Central City'), City(name='North City'),
                  City(name='East City'), City(name='West City'),
                  City(name='Orange Star City'), City(name='South City')]
        users = []
        prices = []
        for counter, city in enumerate(cities, start=1):
            users.append(User(id='{}[email protected]'.format(city.name.lower().split()[0]),
                              city=city))
            prices.append(Price(city=city, product=products[0], value=counter*10))
        Session.add_all(products + cities + users + prices)
Ejemplo n.º 3
0
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        DBSession.add_all([
            User(UserName='******', UserPass='******'),
            User(UserName='******', UserPass='******'),
            Group(GroupName='123', VospName='123'),
        ])
Ejemplo n.º 4
0
def preload_countries():
    """
    Read the country list contained in GeoLite2.zip and populate the Continent and Country classes
    """
    countries = []
    cnt = 0
    with zipfile.ZipFile('test_cliquet/scripts/GeoLite2.zip') as zf:
        with TextIOWrapper(zf.open(FILENAMES.countries.value)) as data:
            reader = csv.reader(data)
            _ = next(reader)  # skip header
            for cnt, row in enumerate(reader):
                accumulate_continents(row)
                if row[5] != '':
                    countries.append(Country(**map_country_class(row)))
        logger.info('Loaded {} countries'.format(cnt))
        Session.add_all(continents)
        Session.flush()
        continent_conversion(continents)
        replace_continent_id(countries)
        Session.add_all(countries)
Ejemplo n.º 5
0
def delete_items(clazz, items):
    to_delete = db.query(clazz).filter(clazz.id.in_(items)).all()
    map(lambda x: setattr(x, 'logical_del', 1), to_delete)

    with transaction.manager:
        db.add_all(to_delete)
Ejemplo n.º 6
0
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)
    with transaction.manager:

        model = User(
            login = u'admin',
            password = u'1234qwer4321',
            date_of_registration = datetime.now()
        )
        DBSession.add(model)


        model = Journal(
            name = u'AIP Conference Proceedings',
            publishing_country = u'USA'
        )
        DBSession.add(model)


        model = University(
            name = u'Ural Federal University named after the first President of Russia B. N. Yeltsin',
            country = u'Russia',
            city = u'Yekaterinburg'
        )
        DBSession.add(model)


        university = DBSession.query(University.id).\
            filter(University.name == u'Ural Federal University named after the first President of Russia B. N. Yeltsin').all()
        model1 = Author(
            full_name = u'Шибаев Вячеслав Алексеевич',
            university_id = university[0][0]
        )
        model2 = Author(
            full_name = u'Берестова Светлана Александрована',
            university_id = university[0][0]
        )
        model3 = Author(
            full_name = u'Митюшов Евгений Александрович',
            university_id = university[0][0]
        )
        model4 = Author(
            full_name = u'Хлебников Николай Александрович',
            university_id = university[0][0]
        )
        DBSession.add_all([model1, model2, model3, model4])



        journal = DBSession.query(Journal.id).\
            filter(Journal.name == u'AIP Conference Proceedings').all()
        user = DBSession.query(User.id).\
            filter(User.login == u'admin').all()
        model = Article(
            name = u'Mathematical modelling of the spatial network of bone implants obtained by 3D-prototyping',
            keywords = u'biomaterials, implants, 3D-printing',
            abstract = u'''
             In this paper, the mathematical model suitable for bone implants 3D-prototyping is proposed. The composite
             material with the spatial configuration of reinforcement with matrix of hydroxyapatite and titanium alloys
             fibers is considered. An octahedral cell is chosen as an elementary volume. The distribution of reinforcing
             fibers is described by textural parameters. Textural parameters are integrated characteristics that
             summarize information on the direction of reinforcing fibers and their volume fractions. Textural
             parameters, properties of matrix and reinforcing fibers allow calculating effective physical and mechanical
             properties of the composite material. The impact of height and width of the octahedral reinforcement cells
             on textural parameters of the composite material is investigated in this work. The impact of radius of
             fibers is also analyzed. It is shown that the composite becomes quasi-isotropic under certain geometrical
             parameters of cell.
            ''',
            file = 'VAShibaev.pdf',
            journal_id = journal[0][0],
            year_of_publishing = 2017,
            number_of_journal = 1,
            start_page = 92,
            end_page = 96,
            user_id = user[0][0]
        )
        DBSession.add(model)



        article = DBSession.query(Article.id).\
            filter(Article.name == u'Mathematical modelling of the spatial network of bone ' +
                                   u'implants obtained by 3D-prototyping').all()
        author1 = DBSession.query(Author.id).\
            filter(Author.full_name == u'Шибаев Вячеслав Алексеевич').all()
        author2 = DBSession.query(Author.id).\
            filter(Author.full_name == u'Берестова Светлана Александрована').all()
        author3 = DBSession.query(Author.id).\
            filter(Author.full_name == u'Митюшов Евгений Александрович').all()
        author4 = DBSession.query(Author.id).\
            filter(Author.full_name == u'Хлебников Николай Александрович').all()
        model1 = Article_Author(
            article_id = article[0][0],
            author_id = author1[0][0]
        )
        model2 = Article_Author(
            article_id = article[0][0],
            author_id = author2[0][0]
        )
        model3 = Article_Author(
            article_id = article[0][0],
            author_id = author3[0][0]
        )
        model4 = Article_Author(
            article_id = article[0][0],
            author_id = author4[0][0]
        )
        DBSession.add_all([model1, model2, model3, model4])