Ejemplo n.º 1
0
def get_dummy_student(version, shard_gen=None):
    inst = None
    fname = None
    lname = None
    school_num = None
    grade = None
    sid = None

    if version == 1:
        fname = "Janet"
        lname = "Bishop"
        school_num = "11"
        grade = "12"
        sid = "1"
    elif version == 2:
        fname = "Norma"
        lname = "Watkins"
        school_num = "1"
        grade = "12"
        sid = "2"
    elif version == 3:
        fname = "Angela"
        lname = "Hart"
        school_num = "5"
        grade = "6"
        sid = "3"
    elif version == 4:
        fname = "Nicholas"
        lname = "Dixon"
        school_num = "2"
        grade = "4"
        sid = "4"
    else:
        raise ValueError("Unsupported version: {}".format(version))

    if shard_gen:
        shard = next(shard_gen)
        inst = Student(id=sid, parent=shard.key)
    else:
        inst = Student(id=sid)
    inst.fname = fname
    inst.lname = lname
    inst.school_num = school_num
    inst.grade = grade
    inst.sid = sid
    return inst
Ejemplo n.º 2
0
 def convert_row(self, row, shard=None):
     if not row or len(row) < 2:
         raise NotAStudentError("Not a student record, possibly a title or summary line?\n{}".format(row))
     sid = row[1].strip()
     if not sid:
         raise StudentIdError("SID is missing or blank for row: {}".format(row))
     instance = None
     if shard:
         instance = Student(id=sid, parent=shard.key)
     else:
         instance = Student(id=sid)
     try:
         instance.fname = row[12].strip()
         instance.lname = row[13].strip()
         instance.school_num = row[0].strip()
         instance.grade = row[2].strip()
         instance.sid = sid
         return instance
     except IndexError:
         raise NotAStudentError("Not a student record, possibly a title or summary line?\n{}".format(row))