Ejemplo n.º 1
0
def new_submission(challenge_id=None):
    if not ModuleAPI.can_read('challenge') or current_user.is_anonymous:
        abort(403)

    if request.args.get('challenge_id'):
        challenge_id = request.args.get('challenge_id')
    else:
        return "Error, no 'challenge_id' given"

    if request.args.get('submission'):
        submission = request.args.get('submission')
    else:
        return "Error, no 'submission' given"

    new_submission = ChallengeAPI.create_submission(challenge_id=challenge_id,
                                                    user_id=current_user.id,
                                                    submission=submission,
                                                    image_path=None)

    if new_submission is False:
        return "Question is already submitted"

    challenge = ChallengeAPI.fetch_challenge(challenge_id)

    return ChallengeAPI.validate_question(new_submission, challenge)
Ejemplo n.º 2
0
def add_manual_submission(challenge_id):
    challenge = ChallengeAPI.fetch_challenge(challenge_id)
    if challenge is None:
        return abort(404)

    form = init_form(ManualSubmissionForm)

    if form.validate_on_submit():
        new_submission = ChallengeAPI.create_submission(
            challenge_id=challenge.id,
            user_id=form.user.data.id,
            submission=None,
            image_path=None)

        if new_submission is False:
            flash(_("Already added a submission for this user, "
                    "or the challenge is not open."), 'danger')
            return render_template('challenge/add_manual_submission.htm',
                                   form=form, challenge=challenge)

        new_submission.approved = True
        ChallengeAPI.assign_points_to_user(challenge.weight,
                                           new_submission.user_id)

        db.session.add(new_submission)
        db.session.commit()

        flash(_('Submission saved successfully.'), 'success')

        return redirect(url_for('.view_list'))

    return render_template('challenge/add_manual_submission.htm',
                           form=form, challenge=challenge)