Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Integrated new person class to code

  • Loading branch information...
commit 2398b0e4fb4974dd3aa2d2e2c0d601d5d8718379 1 parent 805b992
Edmund von der Burg authored
13 app_engine/handlers/site.py
View
@@ -6,7 +6,7 @@
from google.appengine.ext.webapp import template
from google.appengine.api import users
-from models import Site
+from models import Person, Site
class SiteHandler(webapp.RequestHandler):
def __init__(self):
@@ -16,8 +16,8 @@ def __init__(self):
user = users.get_current_user()
if user:
- self.user = user
- self.vars["user"] = self.user
+ self.person = Person.from_user(user)
+ self.vars["person"] = self.person
self.vars["logout_url"] = users.create_logout_url('/')
def post(self, site_key):
@@ -46,7 +46,7 @@ def list_sites(self):
self.template_path = 'templates/site_list.html'
# find all matching sites
- sites = Site.all().filter('owner =', self.user).fetch(100)
+ sites = self.person.site_set.fetch(100)
self.vars["sites"] = sites
def add_site(self):
@@ -54,7 +54,6 @@ def add_site(self):
# get the site key
site_key = self.request.get('site_key').strip()
- # site_key = re.sub('\s+', '', site_key)
self.vars['site_key'] = site_key
# return if there is no site_key, or we are not a post
@@ -72,14 +71,14 @@ def add_site(self):
return
# ok to create
- site = Site( site_key=site_key )
+ site = Site( site_key=site_key, owner=self.person )
site.put()
self.redirect('/site/' + site_key )
def show_site(self, site_key):
self.template_path = 'templates/site_show.html'
- site = Site.all().filter( 'site_key =', site_key).get()
+ site = self.person.site_set.filter( 'site_key =', site_key).get()
if not site:
return self.error(404)
20 app_engine/models/person.py
View
@@ -7,3 +7,23 @@ class Person(db.Model):
email = db.StringProperty(required=True)
user_id = db.StringProperty(required=True)
created = db.DateTimeProperty(auto_now_add=True)
+
+ @classmethod
+ def from_user( cls, user ):
+ """Find or create a person object for the user, and check email is correct"""
+
+ user_id = user.user_id()
+ email = user.email()
+
+ person = cls.all().filter( 'user_id =', user_id ).get()
+
+ if person is None:
+ person = cls( email=email, user_id=user_id )
+ person.put()
+
+ if person.email != email:
+ person.email = email
+ person.put()
+
+ return person
+
6 app_engine/templates/base.html
View
@@ -11,10 +11,10 @@
<li><a href="/about">About</a></li>
<li><a href="/site/">Create Privatar urls</a></li>
- {% if user %}
+ {% if person %}
<li>
- <img src="{{ user.email|privatar_url_from_email }}?s=16" height="16" width="16">
- {{ user.nickname }}
+ <img src="{{ person.email|privatar_url_from_email }}?s=16" height="16" width="16">
+ {{ person.email }}
(<a href="{{ logout_url }}">log out</a>)
</li>
{% endif %}
Please sign in to comment.
Something went wrong with that request. Please try again.