update to reflect API changes
[gae-samples.git] / geochat / settings.py
blob870ab189ef4a06dd2b5f9cef032f74c2c3a3dc3a
2 import datamodel
3 from google.appengine.ext import db
5 """Helper functions for managing user settings.
7 get(): Returns the settings for a specified user.
8 new(): Initializes and inserts a new user.
9 """
12 def get(user):
13 """Returns the settings for a specified user.
15 Args:
16 user: The user object to look up.
18 Returns:
19 Either a datamodel.Settings instance, if found. Returns None otherwise.
20 """
21 query = db.Query(datamodel.Settings)
22 query.filter('user =', user)
23 results = query.fetch(1)
24 if len(results) == 0:
25 return None
26 else:
27 return results[0]
29 def new(user, default_location = ''):
30 """Initializes and inserts a new user.
32 Args:
33 user: The user object to create settings for.
34 default_location: Optionally specifies the user's starting location as a
35 string.
36 """
37 user_settings = datamodel.Settings()
38 user_settings.user = user
39 if default_location:
40 user_settings.default_location = str(default_location)
41 user_settings.put()
42 return user_settings