-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
47 lines (39 loc) · 1.22 KB
/
models.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import logging
from google.appengine.ext import db
class Greeting(db.Model):
uid = db.StringProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
_facebook = None
_author = None
def fbinit(self, facebook):
self._facebook = facebook
self._author = None
logging.debug("Greeting: Facebook initialized")
def author(self):
if self._author:
logging.debug("Greeting: Author returned")
return self._author
elif self._facebook:
logging.debug("Greeting: Author will be loaded")
self._author = Author(self.uid, self._facebook)
return self._author
else:
logging.debug("Greeting: Neither facebook nor author were init'd")
return None
class Author(object):
def __init__(self, uid="", facebook=None):
self.uid = uid
if facebook:
self.load(facebook)
elif uid == "":
self.name = "Test User"
self.pic_small = ''
self.pic_square = ''
def load(self, facebook):
data = facebook.users.getInfo(
[self.uid],
['uid', 'name', 'pic_small', 'pic_square'])[0]
self.name = data['name']
self.pic_small = data['pic_small']
self.pic_square = data['pic_square']