Exemplo n.º 1
0
def major():
    if request.method == 'POST':
        # print(request.form)
        new_major = Major(request.form['full_name'])
        db.session.add(new_major)
        db.session.commit()
    majors = Major.query.all()
    return render_template('major.jinja2', major=majors)
Exemplo n.º 2
0
def setup_general():
    """Runs the set-up needed for both local development and production.
       Also sets up first admin, counselor, and student users.."""
    College.insert_colleges()
    Scholarship.insert_scholarships()
    Major.insert_majors()
    Role.insert_roles()
    TestName.insert_tests()
    admin_query = Role.query.filter_by(name='Administrator')
    if admin_query.first() is not None:
        if User.query.filter_by(email=Config.ADMIN_EMAIL).first() is None:
            user = User(first_name='Admin',
                        last_name='Account',
                        password=Config.ADMIN_PASSWORD,
                        confirmed=True,
                        email=Config.ADMIN_EMAIL)
            db.session.add(user)
            db.session.commit()
            print('Added administrator {}'.format(user.full_name()))
    counselor_query = Role.query.filter_by(name='Counselor')
    if counselor_query.first() is not None:
        if User.query.filter_by(email=Config.COUNSELOR_EMAIL).first() is None:
            user = User(first_name='Counselor',
                        last_name='Account',
                        password=Config.COUNSELOR_PASSWORD,
                        confirmed=True,
                        email=Config.COUNSELOR_EMAIL)
            db.session.add(user)
            db.session.commit()
            print('Added counselor {}'.format(user.full_name()))
    user_query = Role.query.filter_by(name='User')
    if user_query.first() is not None:
        if User.query.filter_by(email=Config.USER_EMAIL).first() is None:
            user = User(first_name='Student',
                        last_name='Account',
                        password=Config.USER_PASSWORD,
                        confirmed=True,
                        email=Config.USER_EMAIL,
                        student_profile=StudentProfile.generate_fake())
            db.session.add(user)
            db.session.commit()
            print('Added user {}'.format(user.full_name()))
Exemplo n.º 3
0
class EditUserForm(Form):
    major = SelectField(u'major',
                        choices=[(m['name'], m['name'])
                                 for m in Major.get_all(include_none=True)],
                        coerce=_coerce_unicode)
    year = SelectField(u'year',
                       choices=[(y['year'], y['name'])
                                for y in Year.get_all(include_none=True)],
                       coerce=lambda x: int(x) if x else None)

    def validate(self):
        # validating with SelectField is hard?
        # if not super(EditUserForm, self).validate():
        #     return False
        return True
Exemplo n.º 4
0
def edit_user():
    form = EditUserForm()
    if form.validate_on_submit():
        current_user.year = form.year.data
        current_user.major = form.major.data
        current_user.save()
        flash('Successfully updated user details', 'success')
    elif request.method == 'GET':
        form.year.default = current_user.year
        form.major.default = current_user.major
        form.process()
    dept_by_major = Major.get_department_mapping()
    dept_by_major['None'] = 'None'
    return render_template('edit_user.html',
                           form=form,
                           dept_by_major=dept_by_major)
Exemplo n.º 5
0
def setModular():
    name = request.values.get('name', type=str)
    identity = request.values.get('id', type=int)
    registered_time = getCurrentDateTime()
    founder = current_user.get_id()
    introduction = request.values.get('introduction', type=str)
    majorType = request.values.get('type', type=int)
    father_id = request.values.get('father_id', type=int)
    file_url = savePhotoRequestFile(value='picture')

    if majorType is 0:
        column = Major(name=name,
                       identity=identity,
                       time=registered_time,
                       founder=founder,
                       introduction=introduction,
                       picture=file_url,
                       url='')
    elif majorType is 1:
        column = Subject(name=name,
                         identity=identity,
                         time=registered_time,
                         founder=founder,
                         introduction=introduction,
                         picture=file_url,
                         father_id=father_id,
                         url='')
    elif majorType is 3:
        column = Description(name=name,
                             identity=identity,
                             time=registered_time,
                             founder=founder,
                             introduction=introduction,
                             picture=file_url,
                             father_id=father_id,
                             url='')
    elif majorType is 2:
        column = Orientation(name=name,
                             identity=identity,
                             time=registered_time,
                             founder=founder,
                             introduction=introduction,
                             picture=file_url,
                             url='')
    db.session.add(column)
    db.session.commit()
    return json.dumps(sendData(True, "提交成功", "OK"))
Exemplo n.º 6
0
def add_users():
    names = [
        'andrew', 'brian', 'connor', 'david', 'elise', 'francis', 'gerald',
        'hillary', 'isabela', 'jennifer', 'kelly', 'lisa', 'mona', 'natalie',
        'oswald', 'peter', 'quincy', 'richard', 'sarah', 'timothy', 'uma',
        'valerie', 'wally', 'xavier', 'yamini', 'zachary'
    ]
    years = [year['year'] for year in Year.get_all()]
    majors = [major['name'] for major in Major.get_all()]
    remaining_with_majors = 20
    for name in names:
        email = '{}@gatech.edu'.format(name)
        year = years[randint(0, len(years) - 1)]
        major = None if remaining_with_majors <= 0 else majors[randint(
            0,
            len(majors) - 1)]
        remaining_with_majors -= 1
        new_user = User(username=name,
                        password=name,
                        email=email,
                        year=year,
                        major=major)
        new_user.save()
Exemplo n.º 7
0
def parse(response, year):
    soup = BeautifulSoup(response.text, "html5lib")
    td = soup.find_all("td", {"scope": "col", "valign": "middle"})
    td_length = len(td)
    n, i = 0, 1
    while n < td_length:
        stu_number = td[n + 1].get_text().strip()
        stu = Student.query.filter_by(number=stu_number).first()
        if stu is not None or stu_number[0:4] != year:
            print('continue')
            n += 14
            continue
        # print(stu_number, '---  ', stu)
        stu_name = td[n + 2].get_text().strip()
        stu_sex = td[n + 3].get_text().strip()
        stu_grade = td[n + 4].get_text().strip()
        stu_major = td[n + 6].get_text().strip()
        stu_class = td[n + 7].get_text().strip()
        # stu_class变量中含有中英文两种符号,现在将其全部转换为英文()
        stu_class = stu_class.replace("(", "(")
        stu_class = stu_class.replace(")", ")")
        stu_level = td[n + 9].get_text().strip()
        stu_length_of_schooling = td[n + 10].get_text().strip()
        print("第%d次循环" % i)
        print(stu_number, stu_name, stu_sex, stu_grade, stu_major, stu_class,
              stu_level, stu_length_of_schooling)
        marjor = Major.query.filter_by(name=stu_major).first()
        class_ = Class.query.filter_by(name=stu_class).first()
        # 判断marjor和class之前存在与否
        if marjor is None:
            try:
                marjor = Major(name=stu_major)
                db.session.add(marjor)
                db.session.commit()
            except Exception as e:
                db.session.rollback()
                print("There is an error %r" % e)
                break
        if class_ is None:
            try:
                class_ = Class(name=stu_class)
                db.session.add(class_)
                db.session.commit()
            except Exception as e:
                db.session.rollback()
                print("There is an error %r" % e)
                break
        # print('测试 ##--> marjor', marjor.id)
        # print('测试 ##--> class_', class_.id)
        student = Student(number=stu_number,
                          name=stu_name,
                          sex=stu_sex,
                          grade=stu_grade,
                          marjor_id=marjor.id,
                          class_id=class_.id,
                          level=stu_level,
                          length_of_schooling=stu_length_of_schooling)
        try:
            db.session.add(student)
            db.session.commit()
        except Exception as e:
            db.session.rollback()
            print("There is an error %r" % e)
            break
        i, n = i + 1, n + 14