Exemplo n.º 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')
Exemplo n.º 2
0
def notes_submit_message():
    resource_id = request.form['resource_id']
    thread_id = str(request.form['thread_id'])
    content = request.form['content']
    msg_id = request.form['msg_id'] # only if this edits a previous message
    user = get_current_user_email_with_default()
    if resource_id == 'Demo':
        output = json.dumps([content, msg_id, user, thread_id])
        return Response(output, mimetype='text/plain')

    thread = Note.get_by_thread_id(thread_id)
    msgs = json.loads(thread.data)
    was_new_message = True
    for msg in msgs:
        _content, _user, _id = msg
        if _id == msg_id and _user == user:
            msg[0] = content
            was_new_message = False

    if was_new_message:
        msg_id = str(datetime.utcnow())
        msgs.append([content, user, msg_id])

    thread.data = json.dumps(msgs)
    thread.updated = datetime.utcnow()
    new_note_notification(resource_id, user, thread_id, msg_id)
    db.session.commit()
    if request.form['fromPage'] == 'mobileviewnotes':
        return Response('sent', mimetype='text/plain')
    output = json.dumps([content, msg_id, user, thread_id])
    return Response(output, mimetype='text/plain')
Exemplo n.º 3
0
def notes_submit_message():
    resource_id = request.form['resource_id']
    thread_id = str(request.form['thread_id'])
    content = request.form['content']
    msg_id = request.form['msg_id']  # only if this edits a previous message
    user = get_current_user_email_with_default()
    if resource_id == 'Demo':
        output = json.dumps([content, msg_id, user, thread_id])
        return Response(output, mimetype='text/plain')

    thread = Note.get_by_thread_id(thread_id)
    msgs = json.loads(thread.data)
    was_new_message = True
    for msg in msgs:
        _content, _user, _id = msg
        if _id == msg_id and _user == user:
            msg[0] = content
            was_new_message = False

    if was_new_message:
        msg_id = str(datetime.utcnow())
        msgs.append([content, user, msg_id])

    thread.data = json.dumps(msgs)
    thread.updated = datetime.utcnow()
    new_note_notification(resource_id, user, thread_id, msg_id)
    db.session.commit()
    if request.form['fromPage'] == 'mobileviewnotes':
        return Response('sent', mimetype='text/plain')
    output = json.dumps([content, msg_id, user, thread_id])
    return Response(output, mimetype='text/plain')
Exemplo n.º 4
0
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')
Exemplo n.º 5
0
    def get_fields_by_resource_id(resource_id):
        obj = TitlePageData.get_by_resource_id(resource_id)
        if not obj:
            defaults = {
                'title': Screenplay.get_title(resource_id),
                'written_by': 'Written By\n\n',
                'contact': get_current_user_email_with_default()
            }
            return defaults

        fields = [ 'title', 'written_by', 'contact' ]
        return dict((field, getattr(obj, field)) for field in fields)
Exemplo n.º 6
0
def titlepage_save():
    user_email = get_current_user_email_with_default()
    resource_id = request.form['resource_id']
    permission = Screenplay.get_users_permission(resource_id, user_email)
    if permission != 'owner':
        return redirect(url_for('scriptlist'))

    obj = TitlePageData.get_or_create(resource_id)
    fields = [ 'title', 'written_by', 'contact' ]
    for field in fields:
        if field in request.form:
            setattr(obj, field, request.form[field][:64*12])
    db.session.commit()
    return Response('1', mimetype='text/plain')
Exemplo n.º 7
0
def titlepage():
    resource_id = request.args.get('resource_id')
    if not current_user.is_authenticated() and resource_id != 'Demo':
        return redirect(url_for('welcome'))

    user_email = get_current_user_email_with_default()

    permission = Screenplay.get_users_permission(resource_id, user_email)
    if permission != 'owner' and resource_id != 'Demo':
        return redirect(url_for('scriptlist'))

    fields = TitlePageData.get_fields_by_resource_id(resource_id)
    screenplay_title = Screenplay.get_title(resource_id)
    return render_template('titlepage.html', user=user_email,
                           screenplay_title=screenplay_title, **fields)
Exemplo n.º 8
0
def notes_new_thread():
    resource_id = request.form['resource_id']
    row = int(request.form['row'])
    col = int(request.form['col'])
    thread_id = str(request.form['thread_id'])
    content = request.form['content']
    msg_id = str(datetime.utcnow())
    user = get_current_user_email_with_default()
    if resource_id != "Demo":
        message = [content, user, msg_id]
        data = json.dumps([message])
        note = Note(resource_id=resource_id, thread_id=thread_id,
                    data=data, row=row, col=col)
        db.session.add(note)
        new_note_notification(resource_id, user, thread_id, msg_id)
        db.session.commit()

    if request.form['fromPage'] == 'mobileviewnotes':
        return Response('sent', mimetype='text/plain')
    dump = json.dumps([row, col, thread_id, msg_id, user])
    return Response(dump, mimetype='text/plain')
Exemplo n.º 9
0
def editor():
    resource_id = request.args.get('resource_id')
    if not current_user.is_authenticated() and resource_id != 'Demo':
        return redirect(url_for('welcome'))

    user_email = get_current_user_email_with_default()

    permission = Screenplay.get_users_permission(resource_id, user_email)
    if permission is None and resource_id != 'Demo':
        return redirect(url_for('scriptlist'))

    notification = ShareNotify.query. \
                       filter_by(resource_id=resource_id, user=user_email).first()
    if notification:
        notification.opened = True
        notification.timeopened = datetime.utcnow()
        db.session.commit()

    EOV = 'editor' if permission == 'owner' else 'viewer'
    sign_out = '/user/sign-out'
    return render_template('editor.html', user=user_email, mode="PRO",
                           resource_id=resource_id, EOV=EOV, sign_out=sign_out)
Exemplo n.º 10
0
def notes_new_thread():
    resource_id = request.form['resource_id']
    row = int(request.form['row'])
    col = int(request.form['col'])
    thread_id = str(request.form['thread_id'])
    content = request.form['content']
    msg_id = str(datetime.utcnow())
    user = get_current_user_email_with_default()
    if resource_id != "Demo":
        message = [content, user, msg_id]
        data = json.dumps([message])
        note = Note(resource_id=resource_id,
                    thread_id=thread_id,
                    data=data,
                    row=row,
                    col=col)
        db.session.add(note)
        new_note_notification(resource_id, user, thread_id, msg_id)
        db.session.commit()

    if request.form['fromPage'] == 'mobileviewnotes':
        return Response('sent', mimetype='text/plain')
    dump = json.dumps([row, col, thread_id, msg_id, user])
    return Response(dump, mimetype='text/plain')