-
Notifications
You must be signed in to change notification settings - Fork 1
/
group_controller.py
109 lines (75 loc) · 2.05 KB
/
group_controller.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
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
from google.appengine.ext import ndb
from google.appengine.api import app_identity
class FatherGroup(ndb.Model):
email = ndb.StringProperty(required=True)
added_at = ndb.DateTimeProperty(auto_now_add=True)
class ChildGroup(ndb.Model):
email = ndb.StringProperty(required=True)
added_at = ndb.DateTimeProperty(auto_now_add=True)
class Group(ndb.Model):
name = ndb.StringProperty()
def getGroupName():
q = Group.query()
if q.count() > 0:
return q.get().name
else:
return False
def setGroupName(content):
q = Group.query()
if q.count() > 0:
g = q.get()
else:
g = Group(name=content)
g.name = content
g.put()
def findChildGroup(email):
q = ChildGroup.query(ChildGroup.email == email)
return q.get()
def findFatherGroup(email):
q = FatherGroup.query(FatherGroup.email == email)
return q.get()
def haveSameChildGroup(email):
q = ChildGroup.query(ChildGroup.email == email)
if q.count() > 0:
return True
else:
return False
def haveFatherGroup(email):
if email.split('@')[0] == app_identity.get_application_id():
return True
q = FatherGroup.query(FatherGroup.email == email)
if q.count() > 0:
return True
else:
return False
def getAllChildGroups():
return ChildGroup.query().fetch()
def getFatherGroup():
return FatherGroup.query().fetch()
def addFatherGroup(email):
if haveFatherGroup(email):
return False
father = FatherGroup(email=email)
father.put()
return True
def delFatherGroup():
q = FatherGroup.query()
if q.count() > 0:
ret = q.get().email
q.get().key.delete()
return ret
else:
return False
def addChildGroup(email):
if haveSameChildGroup(email):
return False
group = ChildGroup(email=email)
group.put()
return True
def delChildGroup(email):
if not haveSameChildGroup(email):
return False
group = findChildGroup(email)
group.key.delete()
return True