-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
33 lines (26 loc) · 1005 Bytes
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Recipe(db.Model):
text = db.TextProperty()
owner = db.UserProperty()
def put(self):
if not self.owner:
self.owner = users.get_current_user()
return db.Model.put(self)
def get_by_key_name(cls, key_name, parent=None):
entity = super(Recipe, cls).get_by_key_name(key_name, parent)
if entity.owner != users.get_current_user():
raise Exception("Access denied")
return entity
# Set the owner automatically
r = Recipe(key_name="secret sauce")
r.text = "ketchup and mayonnaise"
r.put()
# Only allow the owner to get the record
r = Recipe.get_by_key_name("secret sauce")
====================================================================
See http://fi.am/entry/urlsafe-base64-encodingdecoding-in-two-lines/
You can do this using Python's built-in base64 library in just two lines of code:
import base64
def uri_b64encode(s):
return base64.urlsafe_b64encode(s).strip('=')
def uri_b64decode(s):
return base64.urlsafe_b64decode(s + '=' * (len(s) % 4))