Esempio n. 1
0
   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()
Esempio n. 2
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", "student_sup", "alumni_sup"):
            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)
        # 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"
        newCollege.put()

    return newCollege
Esempio n. 3
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','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