How to use the ramp-frontend.ramp_frontend.views.redirect.redirect_to_user 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 / admin.py View on Github external
Parameters
    ----------
    event_name : str
        The name of the event.
    """
    if not is_admin(db.session, event_name, flask_login.current_user.name):
        return redirect_to_user(
            'Sorry {}, you do not have admin rights'
            .format(flask_login.current_user.firstname),
            is_error=True
        )
    event = get_event(db.session, event_name)
    if not is_accessible_event(db.session, event_name,
                               flask_login.current_user.name):
        return redirect_to_user(
            '{}: no event named "{}"'
            .format(flask_login.current_user.firstname, event_name)
        )
    logger.info('{} is updating event {}'
                .format(flask_login.current_user.name, event.name))
    admin = is_admin(db.session, event_name, flask_login.current_user.name)
    # We assume here that event name has the syntax _
    suffix = event.name[len(event.problem.name) + 1:]

    h = event.min_duration_between_submissions // 3600
    m = event.min_duration_between_submissions // 60 % 60
    s = event.min_duration_between_submissions % 60
    form = EventUpdateProfileForm(
        suffix=suffix, title=event.title,
        is_send_trained_mails=event.is_send_trained_mails,
        is_send_submitted_mails=event.is_send_submitted_mails,
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / general.py View on Github external
def keywords(keyword_name):
    """Page which give details about a keyword."""
    keyword = Keyword.query.filter_by(name=keyword_name).one_or_none()
    if keyword:
        return render_template('keyword.html', keyword=keyword)
    return redirect_to_user('Keyword {} does not exist.'
                            .format(keyword_name), is_error=True)
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
.one_or_none())
    if workflow_element is None:
        error_str = ('{} is not a valid workflow element by {} '
                     .format(workflow_element_name,
                             flask_login.current_user.name))
        error_str += 'in {}/{}/{}/{}'.format(event, team, submission, f_name)
        return redirect_to_user(error_str)
    submission_file = \
        (SubmissionFile.query.filter_by(submission=submission,
                                        workflow_element=workflow_element)
                             .one_or_none())
    if submission_file is None:
        error_str = ('No submission file by {} in {}/{}/{}/{}'
                     .format(flask_login.current_user.name,
                             event, team, submission, f_name))
        return redirect_to_user(error_str)

    # superfluous, perhaps when we'll have different extensions?
    f_name = submission_file.f_name

    submission_abspath = os.path.abspath(submission.path)
    if not os.path.exists(submission_abspath):
        error_str = ('{} does not exist by {} in {}/{}/{}/{}'
                     .format(submission_abspath, flask_login.current_user.name,
                             event, team, submission, f_name))
        return redirect_to_user(error_str)

    if app.config['TRACK_USER_INTERACTION']:
        add_user_interaction(
            db.session,
            interaction='looking at submission',
            user=flask_login.current_user,
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
def user_event(event_name):
    """Landing page for a given event.

    Parameters
    ----------
    event_name : str
        The event name.
    """
    if flask_login.current_user.access_level == 'asked':
        msg = 'Your account has not been approved yet by the administrator'
        logger.error(msg)
        return redirect_to_user(msg)
    if not is_accessible_event(db.session, event_name,
                               flask_login.current_user.name):
        return redirect_to_user('{}: no event named "{}"'
                                .format(flask_login.current_user.firstname,
                                        event_name))
    event = get_event(db.session, event_name)
    if event:
        if app.config['TRACK_USER_INTERACTION']:
            add_user_interaction(db.session, interaction='looking at event',
                                 event=event, user=flask_login.current_user)
        description_f_name = os.path.join(
            event.problem.path_ramp_kit,
            '{}_starting_kit.html'.format(event.problem.name)
        )
        with codecs.open(description_f_name, 'r', 'utf-8') as description_file:
            description = description_file.read()
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
def event_plots(event_name):
    """Landing page of the plot illustrating the score evolution over time for
    a specific RAMP event.

    Parameters
    ----------
    event_name : str
        The name of the event.
    """
    event = get_event(db.session, event_name)
    if not is_accessible_event(db.session, event_name,
                               flask_login.current_user.name):
        return redirect_to_user('{}: no event named "{}"'
                                .format(flask_login.current_user.firstname,
                                        event_name))
    if event:
        p = score_plot(db.session, event)
        script, div = components(p)
        return render_template('event_plots.html',
                               script=script,
                               div=div,
                               event=event)
    return redirect_to_user('Event {} does not exist.'
                            .format(event_name),
                            is_error=True)
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
def sign_up_for_event(event_name):
    """Landing page to sign-up to a specific RAMP event.

    Parameters
    ----------
    event_name : str
        The name of the event.
    """
    event = get_event(db.session, event_name)
    if not is_accessible_event(db.session, event_name,
                               flask_login.current_user.name):
        return redirect_to_user('{}: no event named "{}"'
                                .format(flask_login.current_user.firstname,
                                        event_name))
    if app.config['TRACK_USER_INTERACTION']:
        add_user_interaction(db.session, interaction='signing up at event',
                             user=flask_login.current_user, event=event)

    ask_sign_up_team(db.session, event.name, flask_login.current_user.name)
    if event.is_controled_signup:
        admin_users = User.query.filter_by(access_level='admin')
        for admin in admin_users:
            subject = ('Request to sign-up {} to RAMP event {}'
                       .format(event.name, flask_login.current_user.name))
            body = body_formatter_user(flask_login.current_user)
            url_approve = ('http://{}/events/{}/sign_up/{}'
                           .format(
                               app.config['DOMAIN_NAME'], event.name,
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
"""The landing page to credit other submission when a user submit is own.

    Parameters
    ----------
    submission_hash : str
        The submission hash of the current submission.
    """
    submission = (Submission.query.filter_by(hash_=submission_hash)
                                  .one_or_none())
    access_code = is_accessible_code(
        db.session, submission.event_team.event.name,
        flask_login.current_user.name, submission.name
    )
    if submission is None or not access_code:
        error_str = 'Missing submission: {}'.format(submission_hash)
        return redirect_to_user(error_str)
    event_team = submission.event_team
    event = event_team.event
    source_submissions = get_source_submissions(db.session, submission.id)

    def get_s_field(source_submission):
        return '{}/{}/{}'.format(
            source_submission.event_team.event.name,
            source_submission.event_team.team.name,
            source_submission.name)

    # Make sure that CreditForm is empty
    CreditForm.name_credits = []
    credit_form_kwargs = {}
    for source_submission in source_submissions:
        s_field = get_s_field(source_submission)
        setattr(CreditForm, s_field, StringField('Text'))
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
)
            else:
                add_user_interaction(
                    db.session, interaction='looking at problem',
                    problem=current_problem
                )
        description_f_name = os.path.join(
            current_problem.path_ramp_kit,
            '{}_starting_kit.html'.format(current_problem.name)
        )
        with codecs.open(description_f_name, 'r', 'utf-8') as description_file:
            description = description_file.read()
        return render_template('problem.html', problem=current_problem,
                               description=description, admin=admin)
    else:
        return redirect_to_user('Problem {} does not exist'
                                .format(problem_name), is_error=True)
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / admin.py View on Github external
subject = ('Signed up for the RAMP event {}'
                           .format(asked_event_team.event.name))
                body = ('{}, you have been registered to the RAMP event {}. '
                        'You can now proceed to your sandbox and make '
                        'submissions.\nHave fun!!!'
                        .format(user.name, asked_event_team.event.name))
                send_mail(
                    to=user.email, subject=subject, body=body
                )
            elif request.form["submit_button"] == "Remove!":
                delete_event_team(
                    db.session, asked_event_team.event.name,
                    asked_event_team.team.name
                )
            message += "{}\n".format(asked_event_team)
        return redirect_to_user(
            message, is_error=False,
            category="{}d users".format(request.form["submit_button"][:-1])
        )
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
with codecs.open(description_f_name, 'r', 'utf-8') as description_file:
            description = description_file.read()
        admin = is_admin(db.session, event_name, flask_login.current_user.name)
        approved = is_user_signed_up(
            db.session, event_name, flask_login.current_user.name
        )
        asked = is_user_sign_up_requested(
            db.session, event_name, flask_login.current_user.name
        )
        return render_template('event.html',
                               description=description,
                               event=event,
                               admin=admin,
                               approved=approved,
                               asked=asked)
    return redirect_to_user('Event {} does not exist.'
                            .format(event_name), is_error=True)