Example #1
0
def _getProfileFromEmail(email):
    user_id = Profile.query(Profile.email == email).fetch(1)
    if len(user_id) > 0:
        print "User Existed"
        return user_id[0]

    else:
        print "New User"
        return Profile(
            name='',
            email='',
            phone='',
            isAlumni='N',
        )
Example #2
0
def messageProp(batch,collegeId,data):
       postList = []
       print ("collegeId",collegeId)
       if collegeId == None or collegeId =="":
          college = None
       else:   
          collegeId = ndb.Key('CollegeDb',int(collegeId))
          college = collegeId.get()
       if batch == None or batch == "":
          batch = None

       
       if(college !=None and batch!=None): 
         print "CASE 1"
         print data
         print batch
         print college
         profileList = Profile.query(ndb.AND(Profile.batch == batch,Profile.collegeId == collegeId))  
       elif (college == None and batch == None):
         print "Case 2"
         print data
         print batch
         print college
         print "Entered normal"
         profileList = Profile.query() 
       elif (college != None and batch == None):
         print data
         print batch
         print college
         print "Case 3"
         profileList = Profile.query(Profile.collegeId == collegeId)
       else: 
         print data
         print batch
         print college
         print "Case 4"
         profileList = Profile.query(Profile.batch == batch)
       

       print "Reached"
       print profileList
       for profile in profileList :
           if(profile.gcmId):
              postList.append(profile.gcmId)

       print postList
       gcm_message = GCMMessage(postList, data)
       gcm_conn = GCMConnection()
       gcm_conn.notify_device(gcm_message)
Example #3
0
def messageProp(batch, collegeId, data):
    postList = []
    print("collegeId", collegeId)
    if collegeId == None or collegeId == "":
        college = None
    else:
        collegeId = ndb.Key('CollegeDb', int(collegeId))
        college = collegeId.get()
    if batch == None or batch == "":
        batch = None

    if (college != None and batch != None):
        print "CASE 1"
        print data
        print batch
        print college
        profileList = Profile.query(
            ndb.AND(Profile.batch == batch, Profile.collegeId == collegeId))
    elif (college == None and batch == None):
        print "Case 2"
        print data
        print batch
        print college
        print "Entered normal"
        profileList = Profile.query()
    elif (college != None and batch == None):
        print data
        print batch
        print college
        print "Case 3"
        profileList = Profile.query(Profile.collegeId == collegeId)
    else:
        print data
        print batch
        print college
        print "Case 4"
        profileList = Profile.query(Profile.batch == batch)

    print "Reached"
    print profileList
    for profile in profileList:
        if (profile.gcmId):
            postList.append(profile.gcmId)

    print postList
    gcm_message = GCMMessage(postList, data)
    gcm_conn = GCMConnection()
    gcm_conn.notify_device(gcm_message)
Example #4
0
def changeGcm(request):
    email = request.email

    profile = Profile.query(Profile.email == email)
    print type(profile)

    for y in profile:
        print y.gcmId

        y.gcmId = request.gcmId
        y.put()

    return
Example #5
0
def _getProfileFromEmail(email):
        user_id=Profile.query(Profile.email==email).fetch(1)
        if len(user_id)>0:
            print "User Existed"            
            return user_id[0]
            
        else:
            print "New User"
            return Profile(name = '',
                           email = '',
                           phone = '',
                           isAlumni='N',
                           )
Example #6
0
def changeGcm(request):
    email = request.email

    profile = Profile.query(Profile.email==email)
    print  type(profile)

    for y in profile:
        print y.gcmId

        y.gcmId = request.gcmId
        y.put()

    return
Example #7
0
def postEntry(requestentity=None,check=0):

        newPost = Post()
        #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123')
        #college_key = college.put()
        query = CollegeDb.query()
        club_name = Club.query()
        if check==0:
            print "The request entity key is " + requestentity.clubId
            key1 = ndb.Key('Club',int(requestentity.clubId))
            key2 = ndb.Key('Profile',int(requestentity.fromPid))
        else:
            key1 = requestentity.clubId
            key2 = requestentity.fromPid

        persons = Profile.query()
        #print club_name[0]
        #print "The key is " + club_name[0].key
        club_key = key1
        profile_key = key2
        flag = 0
        flag1 = 0
        clubs = Club.query()

        print "Profile Key " + str(profile_key)
        for x in persons:
            print x.key
            if(x.key == profile_key):
                print "Same"
                flag=1
            else:
                print "NOPE"

        for x in clubs:
            print x.key
            if(x.key == club_key):
                print "Same"
                flag1=1
            else:
                print "NOPE"

                    #setattr(clubRequest, field, profile_key)

        if(flag==1 and flag1==1):
            if requestentity:
                for field in ('title','description','clubId','fromPid','likes','views','timestamp','photo','photoUrl','tags'):

                    if hasattr(requestentity, field):
                        print(field,"is there")
                        val = getattr(requestentity, field)
                        if(field=="clubId"):
                            print "Club_Id stage"
                            setattr(newPost, 'club_id', club_key)

                        elif field == "fromPid":
                            print "Entered here"
                            person = profile_key.get()
                            print "Person's email-id ", person.email
                            person_collegeId = person.collegeId
                            print "His college Id ", person.collegeId
                            college_details = person_collegeId.get()
                            print "The sup is ", college_details.student_sup
                            setattr(newPost, 'from_pid', profile_key)
                            print "Put PID"
                            setattr(newPost,'collegeId',person_collegeId)
                            print "Put college id"

                        elif field=="timestamp":
                            setattr(newPost, field, val)

                        elif field=="photoUrl" and val == None:
                            setattr(newPost, field, "https://lh3.googleusercontent.com/VLbWVdaJaq2HoYnu6J3T5aKC9DP_ku0KC3eelxawe6sqsPdNTarc5Vc0sx6VGqZ1Y-MlguZNd0plkDEZKYM9OnDbvR2tomX-Kg")

                        elif field=="tags":
                            print("Value is",val)
                            setattr(newPost, field, (val))

                        elif val:
                            print("Value is",val)
                            setattr(newPost, field, str(val))



                    else:
                        if field == "timestamp":
                            temp = datetime.strptime(getattr(requestentity,"date"),"%Y-%m-%d").date()
                            temp1 = datetime.strptime(getattr(requestentity,"time"),"%H:%M:%S").time()
                            setattr(newPost,field,datetime.combine(temp,temp1))

                        setattr(newPost, "likes", 0)
                        setattr(newPost, "views", 0)

            print("About to create Post")
            print(newPost)
            newPost.put()


        else:
             print "Invalid Entry"



        return newPost
Example #8
0
def deleteProfile(request):
    #Steps to be incorporated for deletion of a profile
    #1) Check if fromKey == pidKey
    from_key = ndb.Key('Profile', int(request.fromPid))
    pid_key = ndb.Key('Profile', int(request.pid))
    if (from_key == pid_key and pid_key != None):
        profile = pid_key.get()
        print profile.name

    #2) Remove the profile key from followers and members of every club
    #3) If the profile is in club.admin then remove it from club.admin and make Superadmin the admin of the club
    clubList = Club.query()

    for club in clubList:

        if (len(club.members) != 0):
            if pid_key in club.members:
                print("club key is", club.key)
                club.members.remove(pid_key)

        if (len(club.follows) != 0):

            if pid_key in club.follows:
                club.follows.remove(pid_key)

        if pid_key == club.admin:
            #obtain super admin profile of college
            college = club.collegeId.get()
            emailId = college.sup_emailId
            profileret = Profile.query(Profile.email == emailId)
            for superadmin in profileret:
                print("Superadmin", superadmin.name)
                superadmin.admin.append(club.key)
                club.admin = superadmin.key
                superadmin.clubsJoined.append(club.key)
                superadmin.follows.append(club.key)
                club.members.admin(superadmin.key)
                club.follows.admin(superadmin.key)
                superadmin.put()
        club.put()

    #4 Delete Posts which are created by the profile
    postRet = Post.query(Post.from_pid == pid_key)

    for posts in postRet:
        likePostmini = LikePost()
        likePostmini.from_pid = str(pid_key.id())
        likePostmini.postId = str(posts.key.id())
        deletePost(likePostmini)

    # Remove pid_key from event_attendees list
    eventlist = Event.query()
    for event in eventlist:
        if (len(event.attendees) != 0):
            if (pid_key in event.attendees):

                event.attendees.remove(pid_key)
                event.put()

    #Remove Events created by that profile
    eventRet = Event.query(Event.event_creator == pid_key)
    for events in eventRet:
        modifyeventmini = ModifyEvent()
        modifyeventmini.from_pid = str(pid_key.id())
        modifyeventmini.eventId = str(events.key.id())
        deleteEvent(modifyeventmini)

    #Remove Club_Creation requests by that profile or to that profile
    clubcreationlist = Club_Creation.query(
        ndb.OR(Club_Creation.from_pid == pid_key,
               Club_Creation.to_pid == pid_key))

    for clubcreation in clubcreationlist:
        print clubcreation
        clubcreation.key.delete()

    #Remove Join Creation, Join Requests, Post_Requests
    joinCreationRet = Join_Creation.query(
        ndb.OR(Join_Creation.from_pid == pid_key,
               Join_Creation.to_pid == pid_key))
    for jc in joinCreationRet:
        print jc
        jc.key.delete()

    joinReqRet = Join_Request.query(
        ndb.OR(Join_Request.from_pid == pid_key,
               Join_Request.to_pid == pid_key))
    for jr in joinReqRet:
        print jr
        jr.key.delete()
    postReqRet = Post_Request.query(
        ndb.OR(Post_Request.from_pid == pid_key
               or Post_Request.to_pid == pid_key))

    for pr in postReqRet:
        print pr
        pr.key.delete()

    commentlist = Comments.query(Comments.pid == pid_key)
    for comments in commentlist:
        print comments
        comments.key.delete()

    #notificationsRet =  Notifications.query(Notifications.to_pid == pid_key)
    notificationsRet = Notifications.query(
        Notifications.to_pid_list.IN([pid_key]))
    for notif in notificationsRet:
        notif.key.delete()

    notificationsRet2 = Notifications.query(Notifications.to_pid == pid)
    for notif in notificationsRet2:
        notif.key.delete()

    #Delete the profile entity
    pid_key.delete()
Example #9
0
def postEntry(requestentity=None, check=0):

    newPost = Post()
    #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123')
    #college_key = college.put()
    query = CollegeDb.query()
    club_name = Club.query()
    if check == 0:
        print "The request entity key is " + requestentity.clubId
        key1 = ndb.Key('Club', int(requestentity.clubId))
        key2 = ndb.Key('Profile', int(requestentity.fromPid))
    else:
        key1 = requestentity.clubId
        key2 = requestentity.fromPid

    persons = Profile.query()
    #print club_name[0]
    #print "The key is " + club_name[0].key
    club_key = key1
    profile_key = key2
    flag = 0
    flag1 = 0
    clubs = Club.query()

    print "Profile Key " + str(profile_key)
    for x in persons:
        print x.key
        if (x.key == profile_key):
            print "Same"
            flag = 1
        else:
            print "NOPE"

    for x in clubs:
        print x.key
        if (x.key == club_key):
            print "Same"
            flag1 = 1
        else:
            print "NOPE"

            #setattr(clubRequest, field, profile_key)

    if (flag == 1 and flag1 == 1):
        if requestentity:
            for field in ('title', 'description', 'clubId', 'fromPid', 'likes',
                          'views', 'timestamp', 'photo', 'photoUrl', 'tags'):

                if hasattr(requestentity, field):
                    print(field, "is there")
                    val = getattr(requestentity, field)
                    if (field == "clubId"):
                        print "Club_Id stage"
                        setattr(newPost, 'club_id', club_key)

                    elif field == "fromPid":
                        print "Entered here"
                        person = profile_key.get()
                        print "Person's email-id ", person.email
                        person_collegeId = person.collegeId
                        print "His college Id ", person.collegeId
                        college_details = person_collegeId.get()
                        print "The sup is ", college_details.student_sup
                        setattr(newPost, 'from_pid', profile_key)
                        print "Put PID"
                        setattr(newPost, 'collegeId', person_collegeId)
                        print "Put college id"

                    elif field == "timestamp":
                        setattr(newPost, field, val)

                    elif field == "photoUrl" and val == None:
                        setattr(
                            newPost, field,
                            "https://lh3.googleusercontent.com/VLbWVdaJaq2HoYnu6J3T5aKC9DP_ku0KC3eelxawe6sqsPdNTarc5Vc0sx6VGqZ1Y-MlguZNd0plkDEZKYM9OnDbvR2tomX-Kg"
                        )

                    elif field == "tags":
                        print("Value is", val)
                        setattr(newPost, field, (val))

                    elif val:
                        print("Value is", val)
                        setattr(newPost, field, str(val))

                else:
                    if field == "timestamp":
                        temp = datetime.strptime(
                            getattr(requestentity, "date"), "%Y-%m-%d").date()
                        temp1 = datetime.strptime(
                            getattr(requestentity, "time"), "%H:%M:%S").time()
                        setattr(newPost, field, datetime.combine(temp, temp1))

                    setattr(newPost, "likes", 0)
                    setattr(newPost, "views", 0)

        print("About to create Post")
        print(newPost)
        newPost.put()

    else:
        print "Invalid Entry"

    return newPost
Example #10
0
def unJoinClub(request):
        ''' steps that need to be done
        get the profile from pid and the fromProfile from the from pid.

        if fromProfile == Profile (Same person ) or if from profile is from the club admin then allow the unjoining of Profile       
        else
        dont allow 
        '''
        print("Request for unJoin is ",request)

        from_pid = ndb.Key('Profile',int(request.fromPid))
        fromProfile = from_pid.get() #received from Profile
 
        pid = ndb.Key('Profile',int(request.pid))
        profile = pid.get()
        
        clubId = ndb.Key('Club',int(request.clubId))
        club = clubId.get()


        if club and len(club.members)!=0:     
           if pid in club.members:
                if (club.admin == from_pid or from_pid == pid) :
                    print ("Entered part1")
                    if(club.admin == from_pid and from_pid == pid): #Case when club admin doesnt want to be a member anymore. In this case make SUP the admin of the club
                            print ("Entered part2")
                            collegeId = club.collegeId
                            college = collegeId.get()
                            print ("College",college)
                            profileofSup = Profile.query(Profile.email == college.sup_emailId).fetch()
                            for x in profileofSup:
                                if clubId not in x.admin:
                                   x.admin.append(clubId)
                                if clubId not in x.clubsJoined:
                                   x.clubsJoined.append(clubId)
                                if clubId not in x.follows:
                                   x.follows.append(clubId)

                                if x.key not in club.follows:
                                   club.follows.append(x.key)
                                if x.key not in club.members:
                                   club.members.append(x.key)
                                
                                club.admin = x.key


                                club.members.remove(pid)
                                profile.clubsJoined.remove(clubId)

                                print ("Club",club)
                                club.put()
                                profile.put()
                                x.put()
                            return True
                   
                    else: #General case when a member wants to leave the club. Change the details of the club.members, profile.members 
                      print ("Entered part3")
                      club.members.remove(pid)
                      profile.clubsJoined.remove(clubId)
                      club.put()
                      profile.put()
                      return True
                else :
                    print ("Entered part4")
                    return False

           else:
             print ("Entered part5")
             return False         

        else:
            print ("No members in this club")
            return False
Example #11
0
def createClub(request=None):

        #When createClubRequest is called

        print("Request Entity for Create Club ", request)
        clubRequest = Club_Creation()


        collegeId = ndb.Key('CollegeDb',int(request.collegeId))
        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','approval_status','photoUrl','timestamp'):


                if field == "abbreviation":
                    clubRequest.abbreviation = request.abbreviation
                elif field == "club_name":
                    clubRequest.club_name = request.clubName
                elif field == "description":
                    clubRequest.description = request.description

                elif field == "from_pid":
                     profile_key = ndb.Key('Profile',int(request.fromPid))
                     print("Finished frompid")
                     setattr(clubRequest, field, profile_key)
                elif field == "to_pid":
                     '''print("Entered To PID")
                     profile =  Profile(
                               name = 'SiddharthRec',
                               email = '*****@*****.**',
                               phone = '7760531994',
                               isAlumni='N',
                               collegeId=college_key
                               )'''
                     #get the college of the from_pid guy
                     #Get the email of the college
                     #correspond it to the SUP profile
                     #get his key and save it

                     from_pid_key = ndb.Key('Profile',int(request.fromPid))
                     from_profile = from_pid_key.get()

                     print("From Profile is",from_profile)
                     college_key = from_profile.collegeId
                     college = college_key.get()

                     email = college.sup_emailId

                     print("Email is",email)

                     query = Profile.query(Profile.email == email).fetch(1)

                     if(query[0]):
                         to_pid_key = query[0].key
                         print("to_pid_key",to_pid_key)
                         setattr(clubRequest, field, to_pid_key)
                elif field == "isAlumni":
                     setattr(clubRequest, field, "N")
                elif field == "collegeId":
                     setattr(clubRequest, field, college_key)
                elif field == "approval_status":
                     setattr(clubRequest, field, "N")
                elif field == "photoUrl":
                     if(request.photoUrl):
                         setattr(clubRequest, field, str(request.photoUrl))

                elif field == "timestamp":
                     print ("Going to enter timestamp")
                     setattr(clubRequest, field, dt.datetime.now().replace(microsecond = 0))
                

            clubRequest.put()

        return clubRequest
Example #12
0
def unJoinClub(request):
    ''' steps that need to be done
        get the profile from pid and the fromProfile from the from pid.

        if fromProfile == Profile (Same person ) or if from profile is from the club admin then allow the unjoining of Profile       
        else
        dont allow 
        '''
    print("Request for unJoin is ", request)

    from_pid = ndb.Key('Profile', int(request.fromPid))
    fromProfile = from_pid.get()  #received from Profile

    pid = ndb.Key('Profile', int(request.pid))
    profile = pid.get()

    clubId = ndb.Key('Club', int(request.clubId))
    club = clubId.get()

    if club and len(club.members) != 0:
        if pid in club.members:
            if (club.admin == from_pid or from_pid == pid):
                print("Entered part1")
                if (
                        club.admin == from_pid and from_pid == pid
                ):  #Case when club admin doesnt want to be a member anymore. In this case make SUP the admin of the club
                    print("Entered part2")
                    collegeId = club.collegeId
                    college = collegeId.get()
                    print("College", college)
                    profileofSup = Profile.query(
                        Profile.email == college.sup_emailId).fetch()
                    for x in profileofSup:
                        if clubId not in x.admin:
                            x.admin.append(clubId)
                        if clubId not in x.clubsJoined:
                            x.clubsJoined.append(clubId)
                        if clubId not in x.follows:
                            x.follows.append(clubId)

                        if x.key not in club.follows:
                            club.follows.append(x.key)
                        if x.key not in club.members:
                            club.members.append(x.key)

                        club.admin = x.key

                        club.members.remove(pid)
                        profile.clubsJoined.remove(clubId)

                        print("Club", club)
                        club.put()
                        profile.put()
                        x.put()
                    return True

                else:  #General case when a member wants to leave the club. Change the details of the club.members, profile.members
                    print("Entered part3")
                    club.members.remove(pid)
                    profile.clubsJoined.remove(clubId)
                    club.put()
                    profile.put()
                    return True
            else:
                print("Entered part4")
                return False

        else:
            print("Entered part5")
            return False

    else:
        print("No members in this club")
        return False
Example #13
0
def createClub(request=None):

    #When createClubRequest is called

    print("Request Entity for Create Club ", request)
    clubRequest = Club_Creation()

    collegeId = ndb.Key('CollegeDb', int(request.collegeId))
    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',
                      'approval_status', 'photoUrl', 'timestamp'):

            if field == "abbreviation":
                clubRequest.abbreviation = request.abbreviation
            elif field == "club_name":
                clubRequest.club_name = request.clubName
            elif field == "description":
                clubRequest.description = request.description

            elif field == "from_pid":
                profile_key = ndb.Key('Profile', int(request.fromPid))
                print("Finished frompid")
                setattr(clubRequest, field, profile_key)
            elif field == "to_pid":
                '''print("Entered To PID")
                     profile =  Profile(
                               name = 'SiddharthRec',
                               email = '*****@*****.**',
                               phone = '7760531994',
                               isAlumni='N',
                               collegeId=college_key
                               )'''
                #get the college of the from_pid guy
                #Get the email of the college
                #correspond it to the SUP profile
                #get his key and save it

                from_pid_key = ndb.Key('Profile', int(request.fromPid))
                from_profile = from_pid_key.get()

                print("From Profile is", from_profile)
                college_key = from_profile.collegeId
                college = college_key.get()

                email = college.sup_emailId

                print("Email is", email)

                query = Profile.query(Profile.email == email).fetch(1)

                if (query[0]):
                    to_pid_key = query[0].key
                    print("to_pid_key", to_pid_key)
                    setattr(clubRequest, field, to_pid_key)
            elif field == "isAlumni":
                setattr(clubRequest, field, "N")
            elif field == "collegeId":
                setattr(clubRequest, field, college_key)
            elif field == "approval_status":
                setattr(clubRequest, field, "N")
            elif field == "photoUrl":
                if (request.photoUrl):
                    setattr(clubRequest, field, str(request.photoUrl))

            elif field == "timestamp":
                print("Going to enter timestamp")
                setattr(clubRequest, field,
                        dt.datetime.now().replace(microsecond=0))

        clubRequest.put()

    return clubRequest
Example #14
0
def deleteProfile(request):
   #Steps to be incorporated for deletion of a profile
   #1) Check if fromKey == pidKey 
   from_key = ndb.Key('Profile',int(request.fromPid)) 
   pid_key = ndb.Key('Profile',int(request.pid))
   if(from_key == pid_key and pid_key!=None):
      profile = pid_key.get()
      print profile.name
   
   #2) Remove the profile key from followers and members of every club
   #3) If the profile is in club.admin then remove it from club.admin and make Superadmin the admin of the club   
   clubList = Club.query()
   
   for club in clubList:
       
       
       if(len(club.members)!=0):
          if pid_key in club.members:
             print ("club key is",club.key)
             club.members.remove(pid_key)
             
       
       if(len(club.follows)!=0):
      
          if pid_key in club.follows:
             club.follows.remove(pid_key)
             
       if pid_key == club.admin:
          #obtain super admin profile of college
          college = club.collegeId.get()
          emailId = college.sup_emailId
          profileret = Profile.query(Profile.email == emailId)
          for superadmin in profileret:
            print ("Superadmin",superadmin.name)
            superadmin.admin.append(club.key)
            club.admin = superadmin.key
            superadmin.clubsJoined.append(club.key)
            superadmin.follows.append(club.key)
            club.members.admin(superadmin.key)
            club.follows.admin(superadmin.key)
            superadmin.put()
       club.put()
          


   #4 Delete Posts which are created by the profile
   postRet =  Post.query(Post.from_pid == pid_key)
   
   for posts in postRet:
         likePostmini = LikePost()
         likePostmini.from_pid = str(pid_key.id())
         likePostmini.postId = str(posts.key.id())   
         deletePost(likePostmini)
     
   # Remove pid_key from event_attendees list
   eventlist = Event.query()
   for event in eventlist:
      if(len(event.attendees)!=0):
          if(pid_key in event.attendees):

             event.attendees.remove(pid_key)
             event.put()
             
    #Remove Events created by that profile
   eventRet =  Event.query(Event.event_creator == pid_key)
   for events in eventRet:
         modifyeventmini = ModifyEvent()
         modifyeventmini.from_pid = str(pid_key.id())
         modifyeventmini.eventId = str(events.key.id())   
         deleteEvent(modifyeventmini)

    #Remove Club_Creation requests by that profile or to that profile 
   clubcreationlist = Club_Creation.query(ndb.OR(Club_Creation.from_pid == pid_key,Club_Creation.to_pid == pid_key))
   
   for clubcreation in clubcreationlist:
             print clubcreation
             clubcreation.key.delete()

    #Remove Join Creation, Join Requests, Post_Requests
   joinCreationRet =  Join_Creation.query(ndb.OR(Join_Creation.from_pid == pid_key,Join_Creation.to_pid == pid_key)) 
   for jc in joinCreationRet:
             print jc
             jc.key.delete()
   
   joinReqRet =  Join_Request.query(ndb.OR(Join_Request.from_pid == pid_key,Join_Request.to_pid == pid_key))
   for jr in joinReqRet:
             print jr
             jr.key.delete()
   postReqRet =  Post_Request.query(ndb.OR(Post_Request.from_pid == pid_key or Post_Request.to_pid == pid_key ))
   
   for pr in postReqRet:
         print pr
         pr.key.delete()

   commentlist = Comments.query(Comments.pid == pid_key)
   for comments in commentlist:
         print comments
         comments.key.delete()         

   #notificationsRet =  Notifications.query(Notifications.to_pid == pid_key)
   notificationsRet = Notifications.query(Notifications.to_pid_list.IN([pid_key]))
   for notif in notificationsRet:
        notif.key.delete()

   notificationsRet2 = Notifications.query(Notifications.to_pid == pid)
   for notif in notificationsRet2:
        notif.key.delete()


   #Delete the profile entity
   pid_key.delete()   
Example #15
0
def createCollege(requestentity=None):

        newCollege = CollegeDb()
        query = CollegeDb.query()
        print "The data got on querying is " , query , " type is ", type(query), "\n"
        count = 0
        names = []
        location = []

        """profile =  Profile(name = 'RJJ',
                            email = '*****@*****.**',
                            phone = '7760532293',
                            password = '******',
                            pid = '1234',
                            isAlumni='N',
                            collegeId= 'NIoTK')
        profile_key = profile.put()
        """

        for records in query:
           print"The name of the college is ", records.name , " and location is " , records.location
           names.append(records.name)
           location.append(records.location)
           count += 1
           #print "\n"

        print "count is, " , count

        collegeName = ""
        if requestentity:
            for field in ('name','abbreviation','location','studentSup','alumniSup','email'):
                val = getattr(requestentity, field)
                if field == "name":
                    collegeName = getattr(requestentity, field).strip()
                if val:
                    val = val.strip()
                    print("Value is",val)
                    if field == 'studentSup':
                        setattr(newCollege, 'student_sup', str(val))
                    elif field == 'alumniSup':
                        setattr(newCollege, 'alumni_sup', str(val))
                    else:
                        setattr(newCollege, field, str(val))
            #Now setting the attributes not recieved from the front-end.
            setattr(newCollege, 'student_count', 0)
            setattr(newCollege, 'group_count', 0)
            newlist = []
            setattr(newCollege, 'group_list', newlist)
            setattr(newCollege,'sup_emailId',requestentity.email)
            # Making CollegeId
            newString = ""
            newString = collegeName[0]
            for x in xrange(len(collegeName)):
                if(collegeName[x]==' '):
                    newString+=collegeName[x+1]

            setattr(newCollege, 'collegeId', newString)

        print(newCollege)
        flag = 0
        for var in xrange(count):
            if(newCollege.name==names[var] and newCollege.location==location[var]):
                flag=1

        if(flag):
            print "Sorry already existing record"

        else:
            print "Unique"
            email = getattr(requestentity, "email")
            phone = getattr(requestentity, "phone")
            if(getattr(requestentity, "studentSup")==None):
                isAlumni = "Yes"
                person_name = getattr(requestentity, "alumniSup")
            else:
                isAlumni = "No"
                person_name = getattr(requestentity, "studentSup")

            collegeId = newCollege.put()
            profile =  Profile(name = person_name ,
                            email = email,
                            phone = phone,
                            isAlumni=isAlumni,
                            collegeId= collegeId)
            profile.superadmin.append(collegeId)
            key1 = profile.put()
            newCollege.student_count = 1
            newCollege.put()
            return newCollege
Example #16
0
def createCollege(requestentity=None):

    newCollege = CollegeDb()
    query = CollegeDb.query()
    print "The data got on querying is ", query, " type is ", type(query), "\n"
    count = 0
    names = []
    location = []
    """profile =  Profile(name = 'RJJ',
                            email = '*****@*****.**',
                            phone = '7760532293',
                            password = '******',
                            pid = '1234',
                            isAlumni='N',
                            collegeId= 'NIoTK')
        profile_key = profile.put()
        """

    for records in query:
        print "The name of the college is ", records.name, " and location is ", records.location
        names.append(records.name)
        location.append(records.location)
        count += 1
        #print "\n"

    print "count is, ", count

    collegeName = ""
    if requestentity:
        for field in ('name', 'abbreviation', 'location', 'studentSup',
                      'alumniSup', 'email'):
            val = getattr(requestentity, field)
            if field == "name":
                collegeName = getattr(requestentity, field).strip()
            if val:
                val = val.strip()
                print("Value is", val)
                if field == 'studentSup':
                    setattr(newCollege, 'student_sup', str(val))
                elif field == 'alumniSup':
                    setattr(newCollege, 'alumni_sup', str(val))
                else:
                    setattr(newCollege, field, str(val))
        #Now setting the attributes not recieved from the front-end.
        setattr(newCollege, 'student_count', 0)
        setattr(newCollege, 'group_count', 0)
        newlist = []
        setattr(newCollege, 'group_list', newlist)
        setattr(newCollege, 'sup_emailId', requestentity.email)
        # Making CollegeId
        newString = ""
        newString = collegeName[0]
        for x in xrange(len(collegeName)):
            if (collegeName[x] == ' '):
                newString += collegeName[x + 1]

        setattr(newCollege, 'collegeId', newString)

    print(newCollege)
    flag = 0
    for var in xrange(count):
        if (newCollege.name == names[var]
                and newCollege.location == location[var]):
            flag = 1

    if (flag):
        print "Sorry already existing record"

    else:
        print "Unique"
        email = getattr(requestentity, "email")
        phone = getattr(requestentity, "phone")
        if (getattr(requestentity, "studentSup") == None):
            isAlumni = "Yes"
            person_name = getattr(requestentity, "alumniSup")
        else:
            isAlumni = "No"
            person_name = getattr(requestentity, "studentSup")

        collegeId = newCollege.put()
        profile = Profile(name=person_name,
                          email=email,
                          phone=phone,
                          isAlumni=isAlumni,
                          collegeId=collegeId)
        profile.superadmin.append(collegeId)
        key1 = profile.put()
        newCollege.student_count = 1
        newCollege.put()
        return newCollege