How to use ramp-frontend - 10 common examples

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
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,
        is_public=event.is_public,
        is_controled_signup=event.is_controled_signup,
        is_competitive=event.is_competitive,
        min_duration_between_submissions_hour=h,
        min_duration_between_submissions_minute=m,
        min_duration_between_submissions_second=s,
        opening_timestamp=event.opening_timestamp,
        closing_timestamp=event.closing_timestamp,
        public_opening_timestamp=event.public_opening_timestamp,
    )
    if form.validate_on_submit():
        try:
            if form.suffix.data == '':
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 / auth.py View on Github external
"for an approval from a RAMP administrator", category='error'
        )
        return redirect(url_for('general.index'))
    User.query.filter_by(email=email).update({'access_level': 'asked'})
    db.session.commit()
    admin_users = User.query.filter_by(access_level='admin')
    for admin in admin_users:
        subject = 'Approve registration of {}'.format(
            user.name
        )
        body = body_formatter_user(user)
        url_approve = ('http://{}/sign_up/{}'
                       .format(app.config['DOMAIN_NAME'], user.name))
        body += 'Click on the link to approve the registration '
        body += 'of this user: {}'.format(url_approve)
        send_mail(admin.email, subject, body)
    flash(
        "An email has been sent to the RAMP administrator(s) who will "
        "approve your account"
    )
    return redirect(url_for('auth.login'))
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / auth.py View on Github external
form = EmailForm()
    error = ''
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).one_or_none()
        if user and user.access_level != 'asked':
            token = ts.dumps(user.email)
            recover_url = url_for(
                'auth.reset_with_token', token=token, _external=True
            )

            subject = "Password reset requested - RAMP website"
            body = ('Hi {}, \n\nclick on the link to reset your password:\n'
                    .format(user.firstname))
            body += recover_url
            body += '\n\nSee you on the RAMP website!'
            send_mail(user.email, subject, body)
            logger.info(
                'Password reset requested for user {}'.format(user.name)
            )
            logger.info(recover_url)
            flash('An email to reset your password has been sent')
            return redirect(url_for('auth.login'))
        elif user is None:
            error = ('The email address is not linked to any user. You can '
                     'sign-up instead.')
        else:
            error = ('Your account has not been yet approved. You cannot '
                     'change the password already.')
    return render_template('reset_password.html', form=form, error=error)
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
interaction='upload',
                        user=flask_login.current_user,
                        event=event,
                        submission_file=submission_file
                    )

            return redirect(request.referrer)
            # TODO: handle different extensions for the same workflow element
            # ie: now we let upload eg external_data.bla, and only fail at
            # submission, without giving a message

        elif ('submit-csrf_token' in request.form and
              submit_form.validate_on_submit()):
            new_submission_name = request.form['submit-submission_name']
            if not 4 < len(new_submission_name) < 20:
                return redirect_to_sandbox(
                    event,
                    'Submission name should have length between 4 and '
                    '20 characters.'
                )
            try:
                new_submission_name.encode('ascii')
            except Exception as e:
                return redirect_to_sandbox(event, 'Error: {}'.format(e))
            try:
                new_submission = add_submission(db.session, event_name,
                                                event_team.team.name,
                                                new_submission_name,
                                                sandbox_submission.path)
            except DuplicateSubmissionError:
                return redirect_to_sandbox(
                    event,
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
diff = '\n'.join(difflib.unified_diff(
                            old_code.splitlines(), new_code.splitlines()))
                        similarity = difflib.SequenceMatcher(
                            a=old_code, b=new_code).ratio()
                        if app.config['TRACK_USER_INTERACTION']:
                            add_user_interaction(
                                db.session,
                                interaction='save',
                                user=flask_login.current_user,
                                event=event,
                                submission_file=submission_file,
                                diff=diff, similarity=similarity
                            )
            except Exception as e:
                return redirect_to_sandbox(event, 'Error: {}'.format(e))
            return redirect_to_sandbox(
                event,
                'You submission has been saved. You can safely comeback to '
                'your sandbox later.',
                is_error=False, category='File saved'
            )

        elif request.files:
            upload_f_name = secure_filename(
                request.files['file'].filename)
            upload_name = upload_f_name.split('.')[0]
            # TODO: create a get_function
            upload_workflow_element = WorkflowElement.query.filter_by(
                name=upload_name, workflow=event.workflow).one_or_none()
            if upload_workflow_element is None:
                return redirect_to_sandbox(event,
                                           '{} is not in the file list.'
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
return redirect_to_sandbox(
                event,
                'You submission has been saved. You can safely comeback to '
                'your sandbox later.',
                is_error=False, category='File saved'
            )

        elif request.files:
            upload_f_name = secure_filename(
                request.files['file'].filename)
            upload_name = upload_f_name.split('.')[0]
            # TODO: create a get_function
            upload_workflow_element = WorkflowElement.query.filter_by(
                name=upload_name, workflow=event.workflow).one_or_none()
            if upload_workflow_element is None:
                return redirect_to_sandbox(event,
                                           '{} is not in the file list.'
                                           .format(upload_f_name))

            # TODO: create a get_function
            submission_file = SubmissionFile.query.filter_by(
                submission=sandbox_submission,
                workflow_element=upload_workflow_element).one()
            if submission_file.is_editable:
                old_code = submission_file.get_code()

            tmp_f_name = os.path.join(tempfile.gettempdir(), upload_f_name)
            request.files['file'].save(tmp_f_name)
            file_length = os.stat(tmp_f_name).st_size
            if (upload_workflow_element.max_size is not None and
                    file_length > upload_workflow_element.max_size):
                return redirect_to_sandbox(
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / auth.py View on Github external
def update_profile():
    """User profile update."""
    form = UserUpdateProfileForm()
    form.user_name.data = flask_login.current_user.name
    if form.validate_on_submit():
        set_user_by_instance(
            db.session,
            user=flask_login.current_user,
            lastname=form.lastname.data,
            firstname=form.firstname.data,
            email=form.email.data,
            linkedin_url=form.linkedin_url.data,
            twitter_url=form.twitter_url.data,
            facebook_url=form.facebook_url.data,
            google_url=form.google_url.data,
            github_url=form.github_url.data,
            website_url=form.website_url.data,
            is_want_news=form.is_want_news.data
        )
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / auth.py View on Github external
)
        return redirect(url_for('auth.login'))
    elif user.access_level == 'asked':
        flash(
            "Your email address already has been confirmed. You need to wait "
            "for an approval from a RAMP administrator", category='error'
        )
        return redirect(url_for('general.index'))
    User.query.filter_by(email=email).update({'access_level': 'asked'})
    db.session.commit()
    admin_users = User.query.filter_by(access_level='admin')
    for admin in admin_users:
        subject = 'Approve registration of {}'.format(
            user.name
        )
        body = body_formatter_user(user)
        url_approve = ('http://{}/sign_up/{}'
                       .format(app.config['DOMAIN_NAME'], user.name))
        body += 'Click on the link to approve the registration '
        body += 'of this user: {}'.format(url_approve)
        send_mail(admin.email, subject, body)
    flash(
        "An email has been sent to the RAMP administrator(s) who will "
        "approve your account"
    )
    return redirect(url_for('auth.login'))
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,