Example #1
0
def profile():
    user_id = session['username']
    user = get_db_session().query(User).filter_by(id=user_id).one()
    user_form = ProfileForm(csrf_enabled=False, obj=user)
    if request.method == 'POST':
        user.first_name = user_form.first_name.data
        user.last_name = user_form.last_name.data
        if user_form.password.data != '':
            user.password = user_form.password.data
        user.contact_no = user_form.contact_no.data
        profile_pic = request.files['profile_pic']
        file_op.save_profile_pic(profile_pic, user_id)
        get_db_session().commit()
    return render_template('forms/profile.html', user=user, form=user_form, randint=random.randint(1000, 9999))
Example #2
0
def practice():
    user_id = session['username']
    db_session = get_db_session()
    user = db_session.query(User).filter_by(id=user_id).one()
    problems = db_session.query(Problem).all()
    db_session.close()
    return render_template('student/practice.html', user=user, problems=problems, randint=random.randint(1000, 9999))
Example #3
0
def add_problem():
    problem_form = ProblemForm(csrf_enabled=False)
    if request.method == 'POST':
        problem = Problem(
            title=problem_form.problem_title.data,
            statement=problem_form.problem_statement.data,
            constraints=problem_form.constraints.data,
            time_limit=problem_form.time_limit.data,
            sample_input=problem_form.sample_input.data,
            sample_output=problem_form.sample_output.data,
            difficulty_level=problem_form.difficulty_level.data,
            category=problem_form.category.data,
            successful_submission=0,
            attempts=0,
            input_format=problem_form.input_format.data,
            output_format=problem_form.output_format.data,
            explanation=problem_form.explanation.data
        )

        db_session = get_db_session()
        db_session.add(problem)
        db_session.commit()
        problem_id = problem.id
        db_session.close()

        file_op.save_test_cases(problem_form.input_test_case_file.data, problem_id,
                                TestCaseFileType.INPUT)
        file_op.save_test_cases(problem_form.output_test_case_file.data, problem_id,
                                TestCaseFileType.OUTPUT)
    return render_template('forms/add_problem.html', form=problem_form)
Example #4
0
def register():
    form = RegistrationForm(csrf_enabled=False)
    if request.method == 'POST' and form.validate():
        user = User()
        user.id = form.id.data
        user.first_name = form.first_name.data
        user.last_name = form.last_name.data
        user.password = form.password.data
        user.email = form.email.data
        user.contact_no = form.contact_no.data
        user.branch = form.branch.data
        user.profile_type = request.form['profile_type']
        profile_pic = request.files['profile_pic']

        if profile_pic:
            profile_pic_extension = ctrl.get_extension_of_file(profile_pic.filename)
            user.profile_pic_extension = profile_pic_extension
            file_op.save_profile_pic(profile_pic, user.id)

        if user.profile_type != 'P':
            ctrl.mkdir_p(os.path.join(app.config['SOLUTION_FILES_DEST'], user.id))
        user.is_active = 'Y'

        db_session = get_db_session()
        insert_to_db(db_session, user)
        return render_template('forms/registration_success.html')
    return render_template('forms/register.html', form=form)
Example #5
0
def problem_solving(problem_id):
    # TODO secure location for saving source code files
    user_id = session['username']
    db_session = get_db_session()
    user = db_session.query(User).filter_by(id=user_id).one()
    problem = db_session.query(Problem).filter_by(id=problem_id).one()
    db_session.close()
    return render_template('student/problem.html', user=user, problem=problem, randint=random.randint(1000, 9999))
Example #6
0
def dashboard():
    user_id = session['username']
    user = get_db_session().query(User).filter_by(id=user_id).one()

    problem_solved_ids = \
        get_db_session().query(Solution) \
            .filter_by(user_id=user_id, result_code=ResultCodes.CORRECT_ANSWER) \
            .distinct(Solution.problem_id) \
            .with_entities(Solution.problem_id).all()

    problem_attempted = get_db_session().query(Solution).filter_by(user_id=user_id) \
        .distinct(Solution.problem_id).with_entities(Solution.problem_id).count()

    problem_wrong_ans = get_db_session().query(Solution) \
        .filter_by(user_id=user_id, result_code=ResultCodes.WRONG_ANSWER).count()

    problem_correct_ans = get_db_session().query(Solution) \
        .filter_by(user_id=user_id, result_code=ResultCodes.CORRECT_ANSWER).count()

    problem_tle = get_db_session().query(Solution) \
        .filter_by(user_id=user_id, result_code=ResultCodes.TIME_LIMIT_EXCEED).count()

    problem_compile_err = get_db_session().query(Solution) \
        .filter_by(user_id=user_id, result_code=ResultCodes.COMPILE_ERROR).count()

    return render_template('student/dashboard.html',
                           user=user,
                           problem_solved_ids=problem_solved_ids,
                           problem_attempted=problem_attempted,
                           problem_correct_ans=problem_correct_ans,
                           problem_wrong_ans=problem_wrong_ans,
                           problem_tle=problem_tle,
                           problem_compile_err=problem_compile_err,
                           randint=random.randint(1000, 9999))
Example #7
0
def validate_email(form, field):
    """
        Perform necessary lookup for EMAIL to avoid multiple user registering
        with same email.

        Args:
            form (Optional) : form currently being used
            field (Optional) : field which requires check

        Raises:
            ValidationError: if email already registered
    """
    db_session = get_db_session()
    email_query = db_session.query(User).filter_by(email=field.data).all()
    db_session.close()
    if email_query:
        raise ValidationError('Email id already registered')
Example #8
0
def validate_user_id(form, field):
    """
        Perform necessary lookup for user ID to avoid multiple user registering
        with same id.

        Args:
            form (Optional) : form currently being used
            field (Optional) : field which requires check

        Raises:
            ValidationError: if user already registered
    """
    db_session = get_db_session()
    id_query = db_session.query(User).filter_by(id=field.data).all()
    db_session.close()
    if id_query:
        raise ValidationError('User already exists')
Example #9
0
def index():
    if 'username' in session:
        return redirect(url_for('dashboard'))
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        try:
            db_session = get_db_session()
            user = db_session.query(User).filter_by(id=username).one()
            db_session.close()
            if user.password == password:
                session['username'] = username
                return redirect(url_for('dashboard'))
            else:
                raise
        except Exception as e:
            flash('Invalid Credentials')
    return render_template('index.html')
Example #10
0
def help():
    user_id = session['username']
    user = get_db_session().query(User).filter_by(id=user_id).one()
    return render_template('help.html', user=user, randint=random.randint(1000,9999))