-
Notifications
You must be signed in to change notification settings - Fork 79
/
model.py
44 lines (35 loc) · 1.42 KB
/
model.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
import logging
from google.appengine.api import users
from google.appengine.ext import db
class User(db.Model):
# Just store email address, because GAFYD seems to be buggy (omits domain in stored email or something...)
email = db.StringProperty()
following = db.StringListProperty()
enabled = db.BooleanProperty(default=True)
tags = db.StringListProperty()
tags_following = db.StringListProperty()
def pretty_name(self):
return self.email.split('@')[0]
class Snippet(db.Model):
user = db.ReferenceProperty(User)
text = db.TextProperty()
date = db.DateProperty()
def compute_following(current_user, users):
"""Return set of email addresses being followed by this user."""
email_set = set(current_user.following)
tag_set = set(current_user.tags_following)
following = set()
for u in users:
if ((u.email in email_set) or
(len(tag_set.intersection(u.tags)) > 0)):
following.add(u.email)
return following
def user_from_email(email):
return User.all().filter("email =", email).fetch(1)[0]
def create_or_replace_snippet(user, text, date):
# Delete existing (yeah, yeah, should be a transaction)
for existing in Snippet.all().filter("date =", date).filter("user =", user).fetch(10):
existing.delete()
# Write new
snippet = Snippet(text=text, user=user, date=date)
snippet.put()