-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdatabase.py
96 lines (84 loc) · 3.5 KB
/
database.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from google.appengine.ext import ndb
def getTags(aUser,anArticle):
q1 = ProxyTag.query()
q1 = q1.filter(ProxyTag.user == aUser)
q1 = q1.filter(ProxyTag.article == anArticle.key)
q1 = q1.order(ProxyTag.score)
return q1.get()
class User(ndb.Model):
createDate = ndb.DateTimeProperty(auto_now_add = True);
lastLoggedIn = ndb.DateTimeProperty(auto_now_add = True);
user = ndb.StringProperty(indexed=True);
class Tag(ndb.Model):
createDate = ndb.DateTimeProperty(auto_now_add = True);
scan = ndb.StringProperty(indexed=True);
scanKey = ndb.StringProperty(indexed=True);
user = ndb.StringProperty(indexed=True);
def json(self):
data = {}
data['Scan'] = self.scan
data['ScanKey'] = self.scanKey
data['User'] = self.user
data['Key'] = self.key.urlsafe()
return data;
class Article(ndb.Model):
createDate = ndb.DateTimeProperty(auto_now_add = True);
title = ndb.StringProperty(indexed=False);
article = ndb.TextProperty()
articleCaptured = ndb.BooleanProperty(default=False);
link = ndb.StringProperty(indexed=False);
indexed = ndb.BooleanProperty(indexed=False,default=False);
chosen = ndb.BooleanProperty(default=False);
casename = ndb.StringProperty(indexed=False);
citation = ndb.StringProperty(indexed=False);
officialReference = ndb.StringProperty(indexed=False);
decisionDate = ndb.StringProperty(indexed=False);
pubDate = ndb.StringProperty(indexed=False);
def jsonUser(self,user):
data = {}
data['Title'] = self.title
data['Article'] = self.article
data['Link'] = self.link
data['Key'] = self.key.urlsafe()
data['LoggedIn']=True
theProxy = getTags(user.user,self)
if theProxy:
if theProxy.score==-1:
data['Scan']='No Tag'
else:
data['Scan']=theProxy.tag.get().scan;
else:
data['Scan']='No Tag'
return data
def json(self):
data = {}
data['Title'] = self.title
data['Article'] = self.article
data['Link'] = self.link
data['Key'] = self.key.urlsafe()
return data;
class ProxyTag(ndb.Model):
createDate = ndb.DateTimeProperty(auto_now_add = True);
tag = ndb.KeyProperty(kind=Tag);
article = ndb.KeyProperty(kind=Article);
user = ndb.StringProperty(indexed=True)
score = ndb.FloatProperty(indexed=True)
computerGenerate = ndb.BooleanProperty(default = False)
def json(self):
data = {}
aTag = self.tag.get()
data=aTag.json();
data['Score']=self.score
data['Computer']=self.computerGenerate
return data
class Word(ndb.Model):
stem = ndb.StringProperty(indexed=True)
def grabKind(self, kind, user):
scan = ScanType.get_or_insert(str(self.stem+"--"+kind+"--"+user))
scan.kind = kind
return scan
class ScanType(ndb.Model):
word = ndb.KeyProperty(kind=Word)
kind = ndb.StringProperty(indexed=True)
spam = ndb.IntegerProperty(indexed=True,default=0)
total = ndb.IntegerProperty(indexed=True,default=0)