Exemple #1
0
def save_screenplay():
    resource_id = request.form['resource_id']
    if resource_id == 'Demo':
        return Response('demo', mimetype='text/plain')

    failed = Response('0', mimetype='text/plain')

    user_email = current_user.name
    permission = UsersScripts.get_users_permission(resource_id, user_email)
    if permission != 'owner':
        return failed

    latest_version_number = Screenplay.get_latest_version_number(resource_id)
    new_version_number = latest_version_number + 1

    expected_version_number = request.form.get('expected_version_number', None)
    if expected_version_number is not None:
        expected_version_number = int(expected_version_number)
        if Screenplay.version_exists(resource_id, expected_version_number):
            return failed
        if expected_version_number > (latest_version_number + 5):
            return failed
        new_version_number = expected_version_number

    data = request.form['data']
    # set some limit on how much data can be saved
    if len(data) > 800 * 1000:
        return failed
    autosave  = (int(request.form['autosave']) == 1)
    now = datetime.utcnow()
    new_save = ScriptData(resource_id=resource_id,
                          data=data,
                          version=new_version_number,
                          timestamp=now,
                          export='[[],[]]',
                          tag='',
                          autosave=autosave)
    db.session.add(new_save)
    screenplays = UsersScripts.query.filter_by(resource_id=resource_id).all()
    for screenplay in screenplays:
        screenplay.last_updated = now
    db.session.commit()
    if expected_version_number is None:
        return Response('1', mimetype='text/plain')
    return jsonify(success=True, versionSaved=new_version_number)
def save_screenplay():
    resource_id = request.form['resource_id']
    if resource_id == 'Demo':
        return Response('demo', mimetype='text/plain')

    failed = Response('0', mimetype='text/plain')

    user_email = current_user.name
    permission = Screenplay.get_users_permission(resource_id, user_email)
    if permission != 'owner':
        return failed

    latest_version_number = Screenplay.get_latest_version_number(resource_id)
    new_version_number = latest_version_number + 1

    expected_version_number = request.form.get('expected_version_number', None)
    if expected_version_number is not None:
        expected_version_number = int(expected_version_number)
        if Screenplay.version_exists(resource_id, expected_version_number):
            return failed
        if expected_version_number > (latest_version_number + 5):
            return failed
        new_version_number = expected_version_number

    data = request.form['data']
    # set some limit on how much data can be saved
    if len(data) > 800 * 1000:
        return failed
    autosave  = (int(request.form['autosave']) == 1)
    now = datetime.utcnow()
    new_save = ScriptData(resource_id=resource_id,
                          data=data,
                          version=new_version_number,
                          timestamp=now,
                          export='[[],[]]',
                          tag='',
                          autosave=autosave)
    db.session.add(new_save)
    Screenplay.set_last_updated(resource_id, now)
    db.session.commit()
    return jsonify(success=True, versionSaved=new_version_number)
def duplicate_screenplay():
    resource_id = request.form['resource_id']
    version = Screenplay.get_latest_version_number(resource_id)
    screenplay = Screenplay.duplicate(resource_id, version, current_user.name)
    url = '/editor?resource_id=' + screenplay.resource_id
    return Response(url, mimetype='text/plain')
def duplicate_screenplay():
    resource_id = get_resource_id_from_request()
    version = Screenplay.get_latest_version_number(resource_id)
    screenplay = Screenplay.duplicate(resource_id, version, current_user.name)
    url = '/editor?resource_id=' + screenplay.resource_id
    return Response(url, mimetype='text/plain')