How to use the ramp-frontend.ramp_frontend.views.redirect.redirect_to_sandbox 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
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 / ramp.py View on Github external
submission: {}
                    submission path: {}
                    """.format(event_team.event.name,
                               flask_login.current_user.name,
                               new_submission.name, new_submission.path)
                    send_mail(admin.email, subject, body)
            if app.config['TRACK_USER_INTERACTION']:
                add_user_interaction(
                    db.session,
                    interaction='submit',
                    user=flask_login.current_user,
                    event=event,
                    submission=new_submission
                )

            return redirect_to_sandbox(
                event,
                '{} submitted {} for {}'
                .format(flask_login.current_user.firstname,
                        new_submission.name, event_team),
                is_error=False, category='Submission'
            )

    admin = is_admin(db.session, event_name, flask_login.current_user.name)
    return render_template(
        'sandbox.html',
        submission_names=sandbox_submission.f_names,
        code_form=code_form,
        submit_form=submit_form, upload_form=upload_form,
        event=event,
        admin=admin
    )
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
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,
                               flask_login.current_user.name
                           ))
            body += ('Click on this link to approve the sign-up request: {}'
                     .format(url_approve))
            send_mail(admin.email, subject, body)
        return redirect_to_user("Sign-up request is sent to event admins.",
                                is_error=False, category='Request sent')
    sign_up_team(db.session, event.name, flask_login.current_user.name)
    return redirect_to_sandbox(
        event,
        '{} is signed up for {}.'
        .format(flask_login.current_user.firstname, event),
        is_error=False,
        category='Successful sign-up'
    )
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
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,
                    'Submission {} already exists. Please change the name.'
                    .format(new_submission_name)
                )
            except MissingExtensionError:
                return redirect_to_sandbox(
                    event, 'Missing extension'
                )
            except TooEarlySubmissionError as e:
                return redirect_to_sandbox(event, str(e))

            logger.info('{} submitted {} for {}.'
                        .format(flask_login.current_user.name,
                                new_submission.name, event_team))
            if event.is_send_submitted_mails:
                admin_users = User.query.filter_by(access_level='admin')
                for admin in admin_users:
                    subject = 'Submission {} sent for training'.format(
                        new_submission.name
                    )
                    body = """A new submission have been submitted:
                    event: {}
github paris-saclay-cds / ramp-board / ramp-frontend / ramp_frontend / views / ramp.py View on Github external
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,
                    'Submission {} already exists. Please change the name.'
                    .format(new_submission_name)
                )
            except MissingExtensionError:
                return redirect_to_sandbox(
                    event, 'Missing extension'
                )
            except TooEarlySubmissionError as e:
                return redirect_to_sandbox(event, str(e))

            logger.info('{} submitted {} for {}.'
                        .format(flask_login.current_user.name,
                                new_submission.name, event_team))
            if event.is_send_submitted_mails:
                admin_users = User.query.filter_by(access_level='admin')
                for admin in admin_users:
                    subject = 'Submission {} sent for training'.format(
                        new_submission.name
                    )
                    body = """A new submission have been submitted:
                    event: {}
                    user: {}
                    submission: {}
                    submission path: {}
                    """.format(event_team.event.name,