Skip to content

Instantly share code, notes, and snippets.

@kixxauth
Created October 24, 2010 22:49
Show Gist options
  • Save kixxauth/644101 to your computer and use it in GitHub Desktop.
Save kixxauth/644101 to your computer and use it in GitHub Desktop.
A wrapper for App Engine models that incorporates user permissions.
# 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