Beispiel #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',
        )
Beispiel #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', '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