def getProfile(self, request): """Return user profile.""" email=getattr(request,"email") result = Profile.query(Profile.email==email) present =0 isAdmin="N" isSuperAdmin="N" for y in result: if y.email == email: present = 1 if y.admin is not None: if len(y.admin)>0: isAdmin="Y" if y.superadmin is not None: if len(y.superadmin)>0: isSuperAdmin="Y" if present ==1: success="True" a = _doProfile(email) return ProfileResponse(success=success,result=a,isAdmin=isAdmin,isSuperAdmin=isSuperAdmin) else: success="False" a = ProfileMiniForm(name = '', email = '', phone = '', isAlumni='', collegeId ='' ) return ProfileResponse(success=success,result=a,isAdmin=isAdmin,isSuperAdmin=isSuperAdmin)
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
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', )
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
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', )
def setSuperAdmin(self,request): collegeKey = ndb.Key('CollegeDb',int(request.collegeId)) college = collegeKey.get() emailId = college.sup_emailId retrievedProfile = Profile.query(Profile.email==emailId).fetch(1) print ("retrievedProfile is",retrievedProfile[0]) if not retrievedProfile[0].superadmin: retrievedProfile[0].superadmin.append(collegeKey) retrievedProfile[0].put() print("inserted into profile table") return message_types.VoidMessage()
def _getProfileFromUser(): """Return user Profile from datastore""" user = endpoints.get_current_user() if not user: raise endpoints.UnauthorizedException('Authorization required f**k you') user_id=Profile.query(Profile.email==user.email()).fetch(1) if len(user_id)>0: return user_id[0] #p_key = ndb.Key(Profile, user_id[0]) #profile = p_key.get() else: return Profile(name = '', email = '', phone = '', isAlumni='N', )
def insertUnique(self,request): #This method is just a reference in order for you to reuse this code in order to insert unique entries in the DB college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123') college_key = college.put() query = CollegeDb.query() profile = Profile(name = 'RJJ', email = '*****@*****.**', phone = '7760532293', password = '******', pid = '1234', isAlumni='N', collegeId= college_key) profileret = Profile.query(Profile.pid == profile.pid).fetch(1) print("A is ", profileret) if profileret: print("Not inserting") else : print("Inserting") profile_key = profile.put()
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.club_id key1 = ndb.Key('Club',int(requestentity.club_id)) key2 = ndb.Key('Profile',int(requestentity.from_pid)) else: key1 = requestentity.club_id key2 = requestentity.from_pid persons = Profile.query() #print club_name[0] #print "The key is " + club_name[0].key club_key = key1 profile_key = key2 flag = 0 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" #setattr(clubRequest, field, profile_key) if(flag==1): if requestentity: for field in ('title','description','club_id','from_pid','likes','views'): if hasattr(requestentity, field): print(field,"is there") val = getattr(requestentity, field) if(field=="club_id"): print "Club_Id stage" setattr(newPost, field, club_key) elif field == "from_pid": 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, field, profile_key) print "Put PID" setattr(newPost,'collegeId',person_collegeId) print "Put college id" elif val: print("Value is",val) setattr(newPost, field, str(val)) else: setattr(newPost, "likes", 0) setattr(newPost, "views", 0) print("About to create Post") print(newPost) newPost.put() else: print "Invalid Person" return
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', 'approval_status', 'photoUrl', 'timestamp'): 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": profile_key = ndb.Key('Profile', int(request.from_pid)) 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.from_pid)) 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
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.club_id key1 = ndb.Key('Club',int(requestentity.club_id)) key2 = ndb.Key('Profile',int(requestentity.from_pid)) else: key1 = requestentity.club_id key2 = requestentity.from_pid 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','club_id','from_pid','likes','views','timestamp','photo','photoUrl'): if hasattr(requestentity, field): print(field,"is there") val = getattr(requestentity, field) if(field=="club_id"): print "Club_Id stage" setattr(newPost, field, club_key) elif field == "from_pid": 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, field, profile_key) print "Put PID" setattr(newPost,'collegeId',person_collegeId) print "Put college id" elif field=="timestamp": 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
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", "approval_status", "photoUrl", "timestamp", ): 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": profile_key = ndb.Key("Profile", int(request.from_pid)) 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.from_pid)) 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