Commits

Ronny Pfannschmidt committed 5362358

kill most of the old app object code, add 404 handler

Comments (0)

Files changed (2)

lodgeit/application.py

     """The WSGI Application"""
 
     def __init__(self, dburi, secret_key):
-        self.secret_key = secret_key
-
-        #: bind metadata, create engine and create all tables
-        self.engine = engine = create_engine(dburi, convert_unicode=True)
-        db.metadata.bind = engine
-        db.metadata.create_all(engine, [Paste.__table__])
-
         #: jinja_environment update
         jinja_environment.globals.update({
             'i18n_languages': i18n.list_languages()})
-        jinja_environment.filters.update({
-            'datetimeformat': i18n.format_datetime})
-        jinja_environment.install_null_translations()
 
-        #: bind the application to the current context local
-        self.bind_to_context()
-
-        self.cleanup_callbacks = (db.session.close, _local_manager.cleanup,
-                                  self.bind_to_context)
-
-    def bind_to_context(self):
-        ctx.application = self
-
-    def __call__(self, environ, start_response):
-        """Minimal WSGI application for request dispatching."""
-        #: bind the application to the new context local
-        self.bind_to_context()
-
-        urls = urlmap.bind_to_environ(environ)
-
-        request = Request(environ, urls)
-        request.bind_to_context()
-
-        try:
-            endpoint, args = urls.match(request.path)
-            handler = get_controller(endpoint)
-            resp = handler(**args)
-        except NotFound:
-            handler = get_controller('static/not_found')
-            resp = handler()
-        except HTTPException, e:
-            resp = e.get_response(environ)
-        else:
-            expires = datetime.utcnow() + timedelta(days=31)
-            if request.first_visit or request.session.should_save:
-                request.session.save_cookie(resp, COOKIE_NAME,
-                                            expires=expires)
-
-        return ClosingIterator(resp(environ, start_response),
-                               self.cleanup_callbacks)
 
 
 def make_app(dburi, secret_key, debug=False):
     app.config['SQLALCHEMY_DATABASE_URI'] = dburi
     app.babel = Babel(app)
     app.debug = debug
+
+    @app.errorhandler(404)
+    def not_found(e):
+        return flask.render_template('not_found.html')
+
     from lodgeit import controllers
     for blueprint in controllers.all:
         app.register_blueprint(blueprint)

lodgeit/templates/not_found.html

   <p>
     {% trans %}Sorry, but the page you requested was not found on this server.{% endtrans %}
   </p>
-  <p>{% trans url=url('static/about') %}
+  <p>{% trans url=url_for('static.about') %}
     We've recently updated this pastebin. While it is out goal for nothing to get
     lost, you may have found a page that was mis-placed. Check your URL to ensure
     you have gone where you intended. If everything looks OK and you still see
     this error page, please consider <a href="{{ url }}">contacting us</a>.{% endtrans %}
   </p>
   <p>
-    {% trans url=url('pastes/new_paste') %}Click <a href="{{ url }}">here</a> to add a new paste.{% endtrans %}
+    {% trans url=url_for('pastes.new_paste') %}Click <a href="{{ url }}">here</a> to add a new paste.{% endtrans %}
   </p>
 {% endblock %}