コード例 #1
0
def scriptcontent():
    resource_id = request.form['resource_id']
    if resource_id == 'Demo':
        latest_version = ScriptData.get_latest_version('Demo')
        lines = [["Fade in:", 1], ["INT. ", 0]]
        if latest_version is not None:
            lines = json.loads(latest_version.data)
        return jsonify(title='Duck Soup', lines=lines,
                       notes=[], sharedwith=[], contacts=[], autosave='true')

    user_email = get_current_user_email_with_default()
    permission = Screenplay.get_users_permission(resource_id, user_email)
    if permission not in ['owner', 'collab']:
        return 'not found'

    title = Screenplay.get_title(resource_id)
    latest_version = ScriptData.get_latest_version(resource_id)
    sharedwith = Screenplay.get_all_collaborators(resource_id)

    user = current_user.name
    unread_notes = UnreadNote.query. \
                       filter_by(resource_id=resource_id, user=user).all()
    unread_msg_ids = set([n.msg_id for n in unread_notes])
    note_rows = Note.get_by_resource_id(resource_id)
    notes = [note.to_dict(unread_msg_ids) for note in note_rows]

    return jsonify(title=title,
                   lines=json.loads(latest_version.data),
                   lastSavedVersionNumber=latest_version.version,
                   notes=notes,
                   sharedwith=sharedwith,
                   autosave='true')
コード例 #2
0
def compare_versions():
    resource_id_1 = request.form['v_o_id']
    resource_id_2 = request.form['v_t_id']
    version_1 = request.form['v_o']
    version_2 = request.form['v_t']
    html_1 = ScriptData.get_html_for_version(resource_id_1, version_1)
    html_2 = ScriptData.get_html_for_version(resource_id_2, version_2)
    if len(html_1) < 10000 and len(html_2) < 10000:
        return diff(html_1, html_2)
    begining_string = ''
    while '</p>' in html_1:
        first_tag = html_1.index('</p>') + 4
        if html_1[:first_tag] == html_2[:first_tag]:
            begining_string += html_1[:first_tag]
            html_1 = html_1[first_tag:]
            html_2 = html_2[first_tag:]
        else:
            break

    end_string = ''
    while '</p>' in html_1:
        last_tag_start = html_1.rfind('<p CLASS=')
        length_of_tag = len(html_1) - last_tag_start
        if html_1[-length_of_tag:] == html_2[-length_of_tag:]:
            end_string = end_string + html_1[-length_of_tag:]
            html_1 = html_1[:-length_of_tag]
            html_2 = html_2[:-length_of_tag]
        else:
            break

    return begining_string + diff(html_1, html_2) + end_string
コード例 #3
0
def compare_versions():
    resource_id_1 = request.form['v_o_id']
    resource_id_2 = request.form['v_t_id']
    version_1 = request.form['v_o']
    version_2 = request.form['v_t']
    html_1 = ScriptData.get_html_for_version(resource_id_1, version_1)
    html_2 = ScriptData.get_html_for_version(resource_id_2, version_2)
    if len(html_1) < 10000 and len(html_2) < 10000:
        return diff(html_1, html_2)
    begining_string = ''
    while '</p>' in html_1:
        first_tag = html_1.index('</p>') + 4
        if html_1[:first_tag] == html_2[:first_tag]:
            begining_string += html_1[:first_tag]
            html_1 = html_1[first_tag:]
            html_2 = html_2[first_tag:]
        else:
            break

    end_string = ''
    while '</p>' in html_1:
        last_tag_start = html_1.rfind('<p CLASS=')
        length_of_tag = len(html_1) - last_tag_start
        if html_1[-length_of_tag:] == html_2[-length_of_tag:]:
            end_string = end_string + html_1[-length_of_tag:]
            html_1 = html_1[:-length_of_tag]
            html_2 = html_2[:-length_of_tag]
        else:
            break

    return begining_string  + diff(html_1, html_2) + end_string
コード例 #4
0
ファイル: flask_editor.py プロジェクト: tacoen/rawscripts
def scriptcontent():
    resource_id = request.form['resource_id']
    if resource_id == 'Demo':
        latest_version = ScriptData.get_latest_version('Demo')
        return jsonify(title='Duck Soup', lines=json.loads(latest_version.data),
                       spelling=[],
                       notes=[], sharedwith=[], contacts=[], autosave='true')

    user_email = get_current_user_email_with_default()
    screenplay = UsersScripts.query.filter_by(resource_id=resource_id,
                                              user=user_email).first()
    if not screenplay:
        return 'not found'

    latest_version = ScriptData.get_latest_version(resource_id)
    sharedwith = UsersScripts.get_all_collaborators(resource_id)

    user = current_user.name
    unread_notes = UnreadNote.query. \
                       filter_by(resource_id=resource_id, user=user).all()
    unread_msg_ids = set([n.msg_id for n in unread_notes])
    note_rows = Note.get_by_resource_id(resource_id)
    notes = [note.to_dict(unread_msg_ids) for note in note_rows]

    return jsonify(title=screenplay.title,
                   lines=json.loads(latest_version.data),
                   lastSavedVersionNumber=latest_version.version,
                   notes=notes,
                   sharedwith=sharedwith,
                   autosave='true')
コード例 #5
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 = 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)
コード例 #6
0
def get_version_html():
    resource_id = request.form['resource_id']
    version = request.form['version']
    if version == 'latest':
        version = ScriptData.get_last_version_number(resource_id).version
    return ScriptData.get_html_for_version(resource_id, version)
コード例 #7
0
def get_version_html():
    resource_id = request.form['resource_id']
    version = request.form['version']
    if version == 'latest':
        version = ScriptData.get_last_version_number(resource_id).version
    return ScriptData.get_html_for_version(resource_id, version)