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 = '*****@*****.**', 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 = '*****@*****.**', 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 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 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','student_sup','alumni_sup','email'): val = getattr(requestentity, field) if field == "name": collegeName = getattr(requestentity, field).strip() if val: val = val.strip() print("Value is",val) 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, "student_sup")==None): isAlumni = "Yes" person_name = getattr(requestentity, "alumni_sup") else: isAlumni = "No" person_name = getattr(requestentity, "student_sup") collegeId = newCollege.put() profile = Profile(name = person_name , email = email, phone = phone, isAlumni=isAlumni, collegeId= collegeId) profile.superadmin.append(collegeId) key1 = profile.put() return newCollege