-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
33 lines (29 loc) · 920 Bytes
/
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
# -*- coding:utf-8 -*-
from google.appengine.ext import db
from random import random
# Globals.
EMPTY_LIST = 'x\x9c\x8b\x8e\x05\x00\x01\x15\x00\xb9' # compression of '[]'
EMPTY_DICT = 'x\x9c\xab\xae\x05\x00\x01u\x00\xf9' # compression of '{}'
class UserData(db.Model):
"""Store user term query and date lat run."""
user = db.UserProperty()
salt = db.StringProperty()
term = db.StringProperty()
term_valid = db.BooleanProperty()
mu_corpus = db.BlobProperty()
relevant_docs = db.BlobProperty()
irrelevant_docs = db.BlobProperty()
def init_data(user):
"""Initialize UserData for a new user."""
# Instantiate.
data = UserData(
key_name = user.user_id(),
user = user,
salt = unicode(random()),
mu_corpus = EMPTY_DICT,
relevant_docs = EMPTY_LIST,
irrelevant_docs = EMPTY_LIST,
)
# Save to the datastore and return.
data.put()
return data