How to use the ramp-frontend.ramp_frontend.views.redirect.redirect_to_credit function in ramp-frontend

To help you get started, we’ve selected a few ramp-frontend examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
# if not new:
    #    credit_form.self_credit.data = str(100 - sum_credit)
    if credit_form.validate_on_submit():
        try:
            sum_credit = int(credit_form.self_credit.data)
            logger.info(sum_credit)
            for source_submission in source_submissions:
                s_field = get_s_field(source_submission)
                sum_credit += int(getattr(credit_form, s_field).data)
            if sum_credit != 100:
                return redirect_to_credit(
                    submission_hash,
                    'Error: The total credit should add up to 100'
                )
        except Exception as e:
            return redirect_to_credit(submission_hash, 'Error: {}'.format(e))
        for source_submission in source_submissions:
            s_field = get_s_field(source_submission)
            similarity = int(getattr(credit_form, s_field).data) / 100.
            submission_similarity = \
                (SubmissionSimilarity.query
                                     .filter_by(
                                         type='target_credit',
                                         user=flask_login.current_user,
                                         source_submission=source_submission,
                                         target_submission=submission)
                                     .all())
            # if submission_similarity is not empty, we need to
            # add zero to cancel previous credits explicitly
            if similarity > 0 or submission_similarity:
                add_submission_similarity(
                    db.session,
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
sum_credit += submission_credit
        credit_form.name_credits.append(
            (s_field, str(submission_credit), source_submission.link)
        )
    # This doesnt work, not sure why
    # if not new:
    #    credit_form.self_credit.data = str(100 - sum_credit)
    if credit_form.validate_on_submit():
        try:
            sum_credit = int(credit_form.self_credit.data)
            logger.info(sum_credit)
            for source_submission in source_submissions:
                s_field = get_s_field(source_submission)
                sum_credit += int(getattr(credit_form, s_field).data)
            if sum_credit != 100:
                return redirect_to_credit(
                    submission_hash,
                    'Error: The total credit should add up to 100'
                )
        except Exception as e:
            return redirect_to_credit(submission_hash, 'Error: {}'.format(e))
        for source_submission in source_submissions:
            s_field = get_s_field(source_submission)
            similarity = int(getattr(credit_form, s_field).data) / 100.
            submission_similarity = \
                (SubmissionSimilarity.query
                                     .filter_by(
                                         type='target_credit',
                                         user=flask_login.current_user,
                                         source_submission=source_submission,
                                         target_submission=submission)
                                     .all())