def createPost(self, request): print("Entered Post Entry Portion") flag=0 clubRequest = postEntry(request,flag) print("Inserted into the posts table") return message_types.VoidMessage()
def createPost(self, request): response = MessageResponse() print("Entered Post Entry Portion") flag=0 try: person_key = ndb.Key('Profile',int(request.from_pid)) profile = person_key.get() print(profile) club_key = ndb.Key('Club',int(request.club_id)) if club_key in profile.follows: print "Present" newPost = postEntry(request,flag) print("NEW POST",newPost) response.status = "1" response.text = "Inserted into Posts Table" #Create Notification Feed group = newPost.club_id.get() groupName = group.name data = {'message': groupName,"title": newPost.title} postlist = [] if (group.follows): for pid in group.follows: person = pid.get() print ("PID is",person) gcmId = person.gcmId if (gcmId): print ("GCM ID is",gcmId) postlist.append(gcmId) newNotif = Notifications( clubName = groupName, clubId = newPost.club_id, clubphotoUrl = group.photoUrl, postName = newPost.title, postId = newPost.key, timestamp = newPost.timestamp, type = "Post", to_pid = pid ) print("Notification to be inserted",newNotif) newNotifKey = newNotif.put() print ("post list is",postlist) gcm_message = GCMMessage(postlist, data) gcm_conn = GCMConnection() gcm_conn.notify_device(gcm_message) else: print "Not present" clubRequest = postRequest(request) response.status = "2" response.text = "Inserted into Posts Requests Table" except: print "Error" response.status = "3" response.text = "Couldn't insert into Posts Table" print("Inserted into the posts table") return response