예제 #1
0
파일: Helpers.py 프로젝트: RJJ11/SAMPLE
def createPostHelper(request):
        response = MessageResponse()
        print("Entered Post Entry Portion")
        flag=0
        try:
            person_key = ndb.Key('Profile',int(request.fromPid))

            profile = person_key.get()
            print(profile)
            club_key = ndb.Key('Club',int(request.clubId))
            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,
                            'id':str(newPost.key.id()),'type':"Post"}
                    
                    
                    postlist = []
                    if (group.follows):
                      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
                                      )
                      for pid in group.follows:
                           person = pid.get()
                           newNotif.to_pid_list.append(pid)
                           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 Exception,e:
                print "Error"
                print str(e)
                response.status = "3"
                response.text = "Couldn't insert into Posts Table"
예제 #2
0
파일: Helpers.py 프로젝트: RJJ11/SAMPLE
def createPostHelper(request):
    response = MessageResponse()
    print("Entered Post Entry Portion")
    flag = 0
    try:
        person_key = ndb.Key('Profile', int(request.fromPid))

        profile = person_key.get()
        print(profile)
        club_key = ndb.Key('Club', int(request.clubId))
        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,
                'id': str(newPost.key.id()),
                'type': "Post"
            }

            postlist = []
            if (group.follows):
                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
                )
                for pid in group.follows:
                    person = pid.get()
                    newNotif.to_pid_list.append(pid)
                    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 Exception, e:
        print "Error"
        print str(e)
        response.status = "3"
        response.text = "Couldn't insert into Posts Table"
예제 #3
0
파일: Helpers.py 프로젝트: RJJ11/SAMPLE
def createEventHelper(request):
        response = MessageResponse()
        print("Entered Event Entry Portion")
        
        try:
            person_key = ndb.Key('Profile',int(request.eventCreator))
            print(person_key)
            profile = person_key.get()
            
            club_key = ndb.Key('Club',int(request.clubId))
            if club_key in profile.clubsJoined:
                    print "GOING INTO EVENTS ENTRY"
                    newEvent = eventEntry(request)
                    response.status = "1"
                    response.text = "Inserted into Posts Table"
                    group = newEvent.club_id.get()
                    groupName = group.name

                    

                    data = {'message': groupName,"title": newEvent.title,
                           'id':str(newEvent.key.id()),'type':"newEvent"}
                    #get the followers of the club pids. Get GCM Id's from those and send
                    print ("GROUP FOLLOWS LIST ", group.follows)

                    eventlist = []
                    if (group.follows):
                        newNotif = Notifications(
                                        clubName = groupName,
                                        clubId = newEvent.club_id,
                                        clubphotoUrl = group.photoUrl,
                                        eventName = newEvent.title,
                                        eventId = newEvent.key,
                                        timestamp = newEvent.timestamp,
                                        type = "Event",
                                        #to_pid = pid
                                        )
                       


                        for pid in group.follows:
                           person = pid.get()
                           newNotif.to_pid_list.append(pid)
                           gcmId = person.gcmId
                           if (gcmId):
                             print ("GCM ID is",gcmId)
                             eventlist.append(gcmId)
                             
                           #newNotif = Notifications(
                           #             clubName = groupName,
                           #             clubId = newEvent.club_id,
                           #             clubphotoUrl = group.photoUrl,
                           #             eventName = newEvent.title,
                           #             eventId = newEvent.key,
                           #             timestamp = newEvent.timestamp,
                           #             type = "Event",
                           #             to_pid = pid
                           #             )
                        print("Notification to be inserted",newNotif)
                        newNotifKey = newNotif.put()

                            
                      
                             
                    
                    print ("Event list is",eventlist)
                    gcm_message = GCMMessage(eventlist, data)
                    gcm_conn = GCMConnection()
                    #gcm_conn.notify_device(gcm_message)
                   
                    print("Should have worked")

            else:
                print "Not Present"
                response.status = "2"
                response.text = "Could not insert"

        except Exception,e:
                print "Error"
                print str(e)
                response.status = "3"
                response.text = "Error"
예제 #4
0
파일: Helpers.py 프로젝트: RJJ11/SAMPLE
def createEventHelper(request):
    response = MessageResponse()
    print("Entered Event Entry Portion")

    try:
        person_key = ndb.Key('Profile', int(request.eventCreator))
        print(person_key)
        profile = person_key.get()

        club_key = ndb.Key('Club', int(request.clubId))
        if club_key in profile.clubsJoined:
            print "GOING INTO EVENTS ENTRY"
            newEvent = eventEntry(request)
            response.status = "1"
            response.text = "Inserted into Posts Table"
            group = newEvent.club_id.get()
            groupName = group.name

            data = {
                'message': groupName,
                "title": newEvent.title,
                'id': str(newEvent.key.id()),
                'type': "newEvent"
            }
            #get the followers of the club pids. Get GCM Id's from those and send
            print("GROUP FOLLOWS LIST ", group.follows)

            eventlist = []
            if (group.follows):
                newNotif = Notifications(
                    clubName=groupName,
                    clubId=newEvent.club_id,
                    clubphotoUrl=group.photoUrl,
                    eventName=newEvent.title,
                    eventId=newEvent.key,
                    timestamp=newEvent.timestamp,
                    type="Event",
                    #to_pid = pid
                )

                for pid in group.follows:
                    person = pid.get()
                    newNotif.to_pid_list.append(pid)
                    gcmId = person.gcmId
                    if (gcmId):
                        print("GCM ID is", gcmId)
                        eventlist.append(gcmId)

                    #newNotif = Notifications(
                    #             clubName = groupName,
                    #             clubId = newEvent.club_id,
                    #             clubphotoUrl = group.photoUrl,
                    #             eventName = newEvent.title,
                    #             eventId = newEvent.key,
                    #             timestamp = newEvent.timestamp,
                    #             type = "Event",
                    #             to_pid = pid
                    #             )
                print("Notification to be inserted", newNotif)
                newNotifKey = newNotif.put()

            print("Event list is", eventlist)
            gcm_message = GCMMessage(eventlist, data)
            gcm_conn = GCMConnection()
            #gcm_conn.notify_device(gcm_message)

            print("Should have worked")

        else:
            print "Not Present"
            response.status = "2"
            response.text = "Could not insert"

    except Exception, e:
        print "Error"
        print str(e)
        response.status = "3"
        response.text = "Error"