Created
October 24, 2010 22:49
-
-
Save kixxauth/644101 to your computer and use it in GitHub Desktop.
A wrapper for App Engine models that incorporates user permissions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In a handler module. | |
class SomeHandler(BaseHandler): | |
def get(self): | |
if not self.user: | |
logging.warn('There is no user logged in. How aweful!') | |
return AuthenticationError | |
user_store = self.user.db | |
try: | |
iter = user_store.SecretModel.all() | |
except UserUnauthorized: | |
return Response('You are not authorized to see instances of SecretModel!') | |
except Exception, e: | |
logging.exception(e) | |
return InternalServerError | |
return Response('/n'.join(map(lambda secret: 'secret: %s'% secret.stuff, iter))) | |
# In another module in a far away land... | |
import fwerks | |
class SecretModel(fwerks.Model): | |
"""A class for building a ORM object. | |
By defining SecretModel as a subclass of fwerks.Model it will be availble | |
to the user.db object with the proper user permissions attached. | |
""" | |
stuff = fwerks.TextProperty() | |
short_stuff = fwerks.StringProperty() | |
secret_int = fwerks.IntegerProperty() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment