-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClubAPI.py
176 lines (121 loc) · 5.38 KB
/
ClubAPI.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
__author__ = 'Siddharth'
import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote
from google.appengine.api import memcache
from google.appengine.api import taskqueue
from google.appengine.ext import ndb
from Models import Club_Creation,CollegeDb,Profile,Club,ClubMiniForm
def createClub(request=None):
#When createClubRequest is called
print("Request Entity for Create Club ", request)
clubRequest = Club_Creation()
collegeId = ndb.Key('CollegeDb',int(request.college_id))
college = CollegeDb.query(CollegeDb.key == collegeId).fetch(1)
college_key = college[0].key
if request and college :
for field in ('abbreviation','club_name','from_pid','to_pid','isAlumni','collegeId','description'):
if field == "abbreviation":
clubRequest.abbreviation = request.abbreviation
elif field == "club_name":
clubRequest.club_name = request.club_name
elif field == "description":
clubRequest.description = request.description
elif field == "from_pid":
print("Entered from_pid")
profile = Profile(
name = 'SiddharthSend',
email = 'sid.tiger184@gmail.com',
phone = '7760531993',
isAlumni='N',
collegeId=college_key
)
profile_key = profile.put()
print("Finished frompid")
setattr(clubRequest, field, profile_key)
elif field == "to_pid":
print("Entered To PID")
profile = Profile(
name = 'SiddharthRec',
email = 'sid.tiger183@gmail.com',
phone = '7760531994',
isAlumni='N',
collegeId=college_key
)
profile_key = profile.put()
setattr(clubRequest, field, profile_key)
elif field == "isAlumni":
setattr(clubRequest, field, "N")
elif field == "collegeId":
setattr(clubRequest, field, college_key)
clubRequest.put()
return clubRequest
def createClubAfterApproval(requestentity=None):
if requestentity:
newClub = Club()
newClub.abbreviation = requestentity.abbreviation
newClub.admin = requestentity.from_pid
newClub.collegeId = requestentity.collegeId
newClub.name = requestentity.club_name
newClub.isAlumni = requestentity.isAlumni
newClub.description = requestentity.description
newClub.members.append(requestentity.from_pid)
newClub.follows.append(requestentity.from_pid)
clubkey = newClub.put()
profile = requestentity.from_pid.get()
print("To check if profile retrieval is correct ", profile)
profile.clubsJoined.append(clubkey)
print("Checking if the guy has joined the club",profile.clubsJoined)
profile.follows.append(clubkey)
print("Check if the profile has folowed the club",profile.follows)
profile.put()
college = newClub.collegeId.get()
if(college):
college.group_list.append(newClub.key)
college.put()
print("finished appending college list")
return newClub
def getClub(request=None):
retClub = ClubMiniForm()
clubKey = ndb.Key('Club',int(request.club_id))
club = clubKey.get()
print("The retrieved club is",club)
collegeidret = club.collegeId
adminret = club.admin
print("Admin ret",adminret)
if club:
college = CollegeDb.query(CollegeDb.collegeId == collegeidret.get().collegeId).fetch(1)
print("Club id is",club.key.id())
retClub.club_id = str(club.key.id())
retClub.admin = adminret.get().name
retClub.abbreviation = club.abbreviation
retClub.name = club.name
retClub.collegeName = college[0].name
retClub.description = club.description
return retClub
def unfollowClub(request):
''' steps that need to be done
Get the profile and the club
If the profile matches that of the club admin then disallow
Check if the profile is a follower of a club. If true remove from each other's lists
'''
print("Request for unfollow is ",request)
from_pid = ndb.Key('Profile',int(request.from_pid))
club_id = ndb.Key('Club',int(request.club_id))
profile = from_pid.get()
club = club_id.get()
print("Profile",profile)
print("Club",profile)
if(club.admin == from_pid):
return False
if(from_pid in club.follows):
#remove club id from profile followers list
#remove profile id from clubs followers list
club.follows.remove(from_pid)
profile.follows.remove(club_id)
club.put()
profile.put()
return True
else:
return False