About
How to not build trains when putting google app engine on rails.
Accounts
Friends
Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.
Click here to check if anything new just came in.
November 18 2008
HTTPDecoratorsPlugin and AuthDecoratorsPlugin
I wrote and commited two decorator plugins, have a look at the source. They help to restrict actions to logged in users only (AuthDecoratorsPlugin) or rescrict the HTTP method of a request (HTTPDecoratorsPlugin).
November 16 2008
Decorator example: Get method only
def get_method_only(fn):
def wrapper(self, *args, **kwargs):
if self._request_method.upper() == "GET":
return fn(self, *args, **kwargs)
else:
self.hnd.error(405)
self.render(text="405 Not Allowed")
return wrapper
@get_method_only
def show(self):
self.render(text="Thank you for your GET request!")
def wrapper(self, *args, **kwargs):
if self._request_method.upper() == "GET":
return fn(self, *args, **kwargs)
else:
self.hnd.error(405)
self.render(text="405 Not Allowed")
return wrapper
@get_method_only
def show(self):
self.render(text="Thank you for your GET request!")
Method decorators
How do I protect my top secret controller-action from being requested anonymously? I use a decorator! Although the syntax is more complex to understand than common code in Python, the result is very handy. Now I have to simply decorate my secret actions by adding "@login_required". If anonymous users request /secrets/confidential now, they get redirected to the login page and back after login.
from gaeo.controller import BaseController
from google.appengine.api import users
class SecretsController(BaseController):
def login_required(fn):
def wrapper(self, *args, **kwargs):
if users.get_current_user():
return fn(self, *args, **kwargs)
elif self and issubclass(self.__class__, BaseController):
self.redirect(users.create_login_url(self.request.path))
return wrapper
@login_required
def confidential(self):
self.render("Thank god you're a user!")
from gaeo.controller import BaseController
from google.appengine.api import users
class SecretsController(BaseController):
def login_required(fn):
def wrapper(self, *args, **kwargs):
if users.get_current_user():
return fn(self, *args, **kwargs)
elif self and issubclass(self.__class__, BaseController):
self.redirect(users.create_login_url(self.request.path))
return wrapper
@login_required
def confidential(self):
self.render("Thank god you're a user!")
November 15 2008
Environment: Dev or prod?
UsingĀ os.getenv('SERVER_SOFTWARE'), you are able to see if you're running on your development machine ("Development/1.0") or the google cloud ("Google Apphosting/1.0").
Controller's before_action interceptor
In your controllers, that are instances of BaseController, you can override the "before_action" and "after_action" methods that get called right before/after the requested action. A common use case is checking some preconditions within the before_action preventing the action from being called if it fails. At the time of writing (release 0.2 beta) you can't do that. But I commited some some today that enables it: In case your before_action returns False, both the action and after_action will not get called.
About
Dear sphere,
I decided to let you follow my progress of diving into web development with Google App Engine Oil. Coming from Groovy and Grails (and still enjoying it), I got excited about the Google App Engine and stumbled upon GAEO, a framework that enables rapid web development following the patterns I got used to. I'll post random notes about what I consider "useful information token" here, have fun!
Cheers,
Fabian
Older posts are this way
If this message doesn't go away, click anywhere on the page to continue loading posts.
Could not load more posts
Maybe Soup is currently being updated? I'll try again automatically in a few seconds...
Maybe Soup is currently being updated? I'll try again automatically in a few seconds...
Just a second, loading more posts...
You've reached the end.
