Beispiel #1
0
    def setUp(self):
        self.config = testing.setUp()
        from sqlalchemy import create_engine

        engine = create_engine("sqlite://")
        DBSession.configure(bind=engine)
        Base.metadata.create_all(engine)
Beispiel #2
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    config = Configurator(settings=settings)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('mobile', 'mobile', cache_max_age=3600)
    config.include('pyramid_jinja2')
    config.include(review)
    config.include(security)
    config.scan()
    return config.make_wsgi_app()
Beispiel #3
0
def show_user(request):
    try:
        user_id = request.matchdict['id']
        user = DBSession.query(User).filter(User.id == user_id).first()
        return user
    except DBAPIError:
        return Response(conn_err_msg, content_type='text/plain', status_int=500)
Beispiel #4
0
def show_review(request):
    try:
        review_id = request.matchdict['id']
        review = DBSession.query(Review).filter(Review.id == review_id).first()
        return review
    except DBAPIError:
        return Response(conn_err_msg, content_type='text/plain', status_int=500)
Beispiel #5
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        user = User('super', '*****@*****.**')
        user.first_name = 'Super'
        user.last_name = 'Medved'
        user.password = '******'
        user.phone = '000-000-00-00'
        user.gender = 'male'
        user.user_name = 'Wader'
        user.created_date = datetime.datetime.now()
        user.last_login_date = datetime.datetime.now()
        DBSession.add(user)
Beispiel #6
0
def save_new_user(request):
    login = request.POST['login']
    email = request.POST['email']

    if len(login) == 0 or len(email) == 0:
        return Response('Bad input', content_type='text/plain', status_int=500)

    try:
        exists = DBSession.query(User).filter(or_(User.login == login,
                                                  User.email == email)).count()
        if exists > 0:
            existing_user = DBSession.query(User).filter(User.login == login).first()
            return HTTPFound(location=route_url('show_user', request, id=existing_user.id))

        user = User(login, email)
        user.first_name = request.POST['first_name']
        user.last_name = request.POST['last_name']
        user.user_name = request.POST['user_name']
        user.password = request.POST['password']
        user.gender = request.POST['gender']
        user.created_date = datetime.datetime.now()
        user.last_login_date = datetime.datetime.now()

        DBSession.add(user)
        DBSession.flush()
        return HTTPFound(location=route_url('show_user', request, id=user.id))
    except DBAPIError:
        return Response(conn_err_msg, content_type='text/plain', status_int=500)
Beispiel #7
0
def add_review(request):
    try:
        review = Review()
        review.title = request.POST['title']
        review.description = request.POST['description']
        review.rating = int(request.POST['rating'])
        review.review_type = request.POST['review_type']
        review.created_date = datetime.datetime.now()

        # filename = request.POST['img'].filename
        input_file = request.POST['img'].file
        dir_path = os.path.join('..', 'images', 'reviews', '%s' % uuid.uuid1())

        if not os.path.exists(dir_path):
            os.makedirs(dir_path)

        file_path = os.path.join(dir_path, '%s.png' % uuid.uuid4())

        temp_file_path = file_path + '~'
        output_file = open(temp_file_path, 'wb')

        input_file.seek(0)

        while True:
            data = input_file.read(2 << 16)
            if not data:
                break
            output_file.write(data)

        output_file.close()

        os.rename(temp_file_path, file_path)

        DBSession.add(review)
        DBSession.flush()
        return HTTPFound(location=route_url('show_review', request, id=review.id))
    except DBAPIError:
        return Response(conn_err_msg, content_type='text/plain', status_int=500)
Beispiel #8
0
 def tearDown(self):
     DBSession.remove()
     testing.tearDown()