Example #1
0
def main():
    f = codecs.open(result_filename,encoding='utf8')
    lines = f.readlines()
    c = 0
    c1 = 0
    for l in lines:
        items = l.strip().split(',')
        if len(items)==7:
            nat_id, title, first_name, last_name, email, password, major = items
            try:
                a = Applicant.objects.get(national_id=nat_id)
            except:
                a = Applicant(national_id=nat_id,
                              title=title,
                              first_name=first_name,
                              last_name=last_name,
                              email=email)
                a.random_password()
                print 'created applicant for', nat_id
                c1 += 1


            a.has_additional_result = True
            if len(password)>10:
                a.additional_hashed_password = password
            else:
                a.set_password(password)
            a.save()

            old_results = AdditionalResult.objects.filter(applicant=a,
                                                          round_number=round_number).all()
            if len(old_results)==0:
                additional_result = AdditionalResult(applicant=a)
            else:
                additional_result = old_results[0]

            additional_result.name = major
            additional_result.round_number = round_number
            additional_result.save()
            c += 1

    print "Imported %d applicants (%d created)" % (c,c1)
Example #2
0
def main():
    f = codecs.open(result_filename, encoding='utf8')
    lines = f.readlines()
    c = 0
    c1 = 0
    for l in lines:
        items = l.strip().split(',')
        if len(items) == 7:
            nat_id, title, first_name, last_name, email, password, major = items
            try:
                a = Applicant.objects.get(national_id=nat_id)
            except:
                a = Applicant(national_id=nat_id,
                              title=title,
                              first_name=first_name,
                              last_name=last_name,
                              email=email)
                a.random_password()
                print 'created applicant for', nat_id
                c1 += 1

            a.has_additional_result = True
            if len(password) > 10:
                a.additional_hashed_password = password
            else:
                a.set_password(password)
            a.save()

            old_results = AdditionalResult.objects.filter(
                applicant=a, round_number=round_number).all()
            if len(old_results) == 0:
                additional_result = AdditionalResult(applicant=a)
            else:
                additional_result = old_results[0]

            additional_result.name = major
            additional_result.round_number = round_number
            additional_result.save()
            c += 1

    print "Imported %d applicants (%d created)" % (c, c1)