Skip to content

Commit

Permalink
now names of system events are string
Browse files Browse the repository at this point in the history
  • Loading branch information
stanfeldman committed Aug 28, 2012
1 parent 5d7b0ae commit ddc9982
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 34 deletions.
11 changes: 0 additions & 11 deletions kiss/controllers/events.py

This file was deleted.

5 changes: 2 additions & 3 deletions kiss/controllers/router.py
Expand Up @@ -6,7 +6,6 @@
from kiss.core.exceptions import *
from kiss.core.events import Eventer
import traceback
import events
import inspect


Expand Down Expand Up @@ -50,14 +49,14 @@ def route(self, request):
if mtch:
request.params = mtch.groupdict()
try:
self.eventer.publish(events.BeforeControllerAction, request)
self.eventer.publish("BeforeControllerAction", request)
#check if controller has method for all requests
if hasattr(controller, "process") and inspect.ismethod(getattr(controller, "process")):
action = getattr(controller, "process")
else:
action = getattr(controller, request.method.lower())
response = action(request)
self.eventer.publish(events.AfterControllerAction, request, response)
self.eventer.publish("AfterControllerAction", request, response)
if not response:
break
return response
Expand Down
22 changes: 11 additions & 11 deletions kiss/core/application.py
Expand Up @@ -9,11 +9,11 @@
from kiss.views.core import Request, Response
from beaker.middleware import SessionMiddleware
from werkzeug.wsgi import SharedDataMiddleware
from kiss.core.events import *
from kiss.views.static import StaticBuilder
from kiss.views.core import Templater
from kiss.models import metadata
import logging
from kiss.core.events import Eventer


class Application(Singleton):
Expand All @@ -26,17 +26,17 @@ def __init__(self, options):
self.init_eventer()
self.init_router()
self.init_templater()
self.eventer.publish(BeforeDatabaseEngineConfiguration, self)
self.eventer.publish("BeforeDatabaseEngineConfiguration", self)
self.init_db()
self.eventer.publish(AfterDatabaseEngineConfiguration, self)
self.eventer.publish("AfterDatabaseEngineConfiguration", self)
self.init_session()
self.eventer.publish(BeforeInitStatic, self)
self.eventer.publish("BeforeInitStatic", self)
self.init_static()
self.eventer.publish(AfterInitStatic, self)
self.eventer.publish(BeforeInitServer, self)
self.eventer.publish("AfterInitStatic", self)
self.eventer.publish("BeforeInitServer", self)
self.init_server()
self.eventer.publish(AfterInitServer, self)
self.eventer.publish(BeforeApplicationStarted, self)
self.eventer.publish("AfterInitServer", self)
self.eventer.publish("BeforeApplicationStarted", self)

def init_options(self, options):
logging.basicConfig(level=logging.CRITICAL)
Expand Down Expand Up @@ -123,15 +123,15 @@ def wsgi_app(self, options, start_response):
def start(self):
gevent.signal(signal.SIGTERM, self.stop)
gevent.signal(signal.SIGINT, self.stop)
self.eventer.publish(ApplicationStarted, self)
self.eventer.publish("ApplicationStarted", self)
self.server.serve_forever()

def start_no_wait(self):
self.eventer.publish(ApplicationStarted, self)
self.eventer.publish("ApplicationStarted", self)
self.server.start()

def stop(self):
self.eventer.publish(ApplicationStopped, self)
self.eventer.publish("ApplicationStopped", self)
self.server.stop()
if self.db_engine:
self.db_engine.close()
Expand Down
16 changes: 11 additions & 5 deletions kiss/core/events.py
@@ -1,14 +1,11 @@
from pev import Eventer

ApplicationStarted = 0
"""
ApplicationStarted = 0
Event when application is started
"""
ApplicationStopped = 1
"""
Event when application is stopped
"""
BeforeDatabaseEngineConfiguration = 2
AfterDatabaseEngineConfiguration = 3
Expand All @@ -17,3 +14,12 @@
BeforeApplicationStarted = 6
BeforeInitServer = 7
AfterInitServer = 8
BeforeControllerAction = 2
Event before controller action will be executed.
You can change Request object before it will pass to controller action.
AfterControllerAction = 3
Event after controller action was executed.
You can change Response object before rendering.
"""
3 changes: 1 addition & 2 deletions project/settings.py
Expand Up @@ -8,7 +8,6 @@
from kiss.core.application import Application
from controllers.controller1 import Controller1
from controllers.controller2 import Controller2
from kiss.core.events import ApplicationStarted
from kiss.controllers.events import BeforeControllerAction
from kiss.core.exceptions import InternalServerError
from kiss.controllers.page import PageController
Expand Down Expand Up @@ -65,7 +64,7 @@
"translations": ["views.locales"]
},
"events": {
ApplicationStarted: Controller2.application_after_load,
"ApplicationStarted": Controller2.application_after_load,
InternalServerError.code: Controller2.internal_server_error
},
"models": {
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion project/views/templates/view.html
Expand Up @@ -6,7 +6,6 @@
</head>
<body>
<div>{{ foo }}</div>
<div>trans:{% trans %}Mary{% endtrans %}, {{_("lamb")}}</div>
<ul>
{% for user in users %}
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -6,7 +6,7 @@

setup(
name = "kiss.py",
version = "0.4.8",
version = "0.4.9",
author = "Stanislav Feldman",
description = ("MVC web framework in Python with Gevent, Jinja2, Werkzeug"),
url = "http://stanislavfeldman.github.com/kiss.py/",
Expand Down

0 comments on commit ddc9982

Please sign in to comment.