예제 #1
0
 def __init__(self, dbname):
     if sys.version < '3':
         from psycopg2.extensions import register_type, UNICODE
         register_type(UNICODE)
     self.dbconn = DbConnection(dbname)
     self.film = FilmHandler(self.dbconn)
     self.url_map = Map([
         Rule('/', endpoint='index'),
         Rule('/films', endpoint='film'),
         Rule('/film/<path:parts>', endpoint='film')
     ])
예제 #2
0
 def __init__(self, dbname):
     if sys.version < '3':
         print("Please run under Python 3.x")
         sys.exit(1)
     self.dbconn = DbConnection(dbname)
     self.film = FilmHandler(self.dbconn)
     self.url_map = Map([
             Rule('/', endpoint='index'),
             Rule('/films', endpoint='film'),
             Rule('/film/<path:parts>', endpoint='film')
             ])
예제 #3
0
 def __init__(self, dbname):
     if sys.version < '3':
         from psycopg2.extensions import register_type, UNICODE
         register_type(UNICODE)
     self.dbconn = DbConnection(dbname)
     self.film = FilmHandler(self.dbconn)
     self.url_map = Map([
             Rule('/', endpoint='index'),
             Rule('/films', endpoint='film'),
             Rule('/film/<path:parts>', endpoint='film')
             ])
예제 #4
0
class DatabaseApp(object):
    def __init__(self, dbname):
        if sys.version < '3':
            print("Please run under Python 3.x")
            sys.exit(1)
        self.dbconn = DbConnection(dbname)
        self.film = FilmHandler(self.dbconn)
        self.url_map = Map([
                Rule('/', endpoint='index'),
                Rule('/films', endpoint='film'),
                Rule('/film/<path:parts>', endpoint='film')
                ])

    def index(self, request):
        return render('home.html')

    def error404(self, msg=''):
        return render('error/404.html', msg=str(msg))

    def dispatch(self, request):
        adapter = self.url_map.bind_to_environ(request.environ)
        try:
            endpoint, values = adapter.match()
            if endpoint == 'index':
                return getattr(self, endpoint)(request, **values)
            else:
                return self.film.dispatch(request)
        except NotFound as exc:
            response = self.error404(exc.description)
            response.status_code = 404
            return response
        except HTTPException as exc:
            return exc

    def wsgi_app(self, environ, start_response):
        req = Request(environ)
        response = self.dispatch(req)
        return response(environ, start_response)

    def __call__(self, environ, start_response):
        return self.wsgi_app(environ, start_response)
예제 #5
0
class DatabaseApp(object):
    def __init__(self, dbname):
        if sys.version < '3':
            from psycopg2.extensions import register_type, UNICODE
            register_type(UNICODE)
        self.dbconn = DbConnection(dbname)
        self.film = FilmHandler(self.dbconn)
        self.url_map = Map([
            Rule('/', endpoint='index'),
            Rule('/films', endpoint='film'),
            Rule('/film/<path:parts>', endpoint='film')
        ])

    def index(self, request):
        return render('home.html')

    def error404(self, msg=''):
        return render('error/404.html', msg=str(msg))

    def dispatch(self, request):
        adapter = self.url_map.bind_to_environ(request.environ)
        try:
            endpoint, values = adapter.match()
            if endpoint == 'index':
                return getattr(self, endpoint)(request, **values)
            else:
                return self.film.dispatch(request)
        except NotFound as exc:
            response = self.error404(exc.description)
            response.status_code = 404
            return response
        except HTTPException as exc:
            return exc

    def wsgi_app(self, environ, start_response):
        req = Request(environ)
        response = self.dispatch(req)
        return response(environ, start_response)

    def __call__(self, environ, start_response):
        return self.wsgi_app(environ, start_response)
예제 #6
0
class DatabaseApp(object):
    def __init__(self, dbname):
        if sys.version < '3':
            from psycopg2.extensions import register_type, UNICODE
            register_type(UNICODE)
        self.dbconn = DbConnection(dbname)
        self.film = FilmHandler(self.dbconn)

    def menu(self):
        while True:
            for cmd in ['Films', 'Quit']:
                print('  %s - %s' % (cmd[:1], cmd))
            cmd = raw_input("Command? ").upper()[:1]
            if cmd == 'Q':
                break
            elif cmd == 'F':
                if self.film.menu() == 'Q':
                    break
            else:
                print("Invalid choice")
        self.dbconn.close()
        print "Done"
예제 #7
0
class DatabaseApp(object):
    def __init__(self, dbname):
        if sys.version < '3':
            print("Please run under Python 3.x")
            sys.exit(1)
        self.dbconn = DbConnection(dbname)
        self.film = FilmHandler(self.dbconn)

    def menu(self):
        while True:
            for cmd in ['Films', 'Quit']:
                print('  %s - %s' % (cmd[:1], cmd))
            cmd = input("Command? ").upper()[:1]
            if cmd == 'Q':
                break
            elif cmd == 'F':
                if self.film.menu() == 'Q':
                    break
            else:
                print("Invalid choice")
        self.dbconn.close()
        print("Done")
예제 #8
0
 def __init__(self, dbname):
     if sys.version < '3':
         from psycopg2.extensions import register_type, UNICODE
         register_type(UNICODE)
     self.dbconn = DbConnection(dbname)
     self.film = FilmHandler(self.dbconn)
예제 #9
0
 def __init__(self, dbname):
     if sys.version < '3':
         print("Please run under Python 3.x")
         sys.exit(1)
     self.dbconn = DbConnection(dbname)
     self.film = FilmHandler(self.dbconn)