Exemplo n.º 1
0
def comment(post_pk):
	new_comment = model.add_comment(request.form.get('user_id'),request.form.get('post_pk'),request.form.get('comment'))
	comment_timestamp = format_date(new_comment.timestamp)
	return jsonify({
		'comment_author': new_comment.user.first_name,
		'comment_content': new_comment.content,
		'comment_pk': new_comment.comment_pk,
		'comment_timestamp': comment_timestamp})
Exemplo n.º 2
0
def comment(post_pk):
    new_comment = model.add_comment(request.form.get('user_id'),
                                    request.form.get('post_pk'),
                                    request.form.get('comment'))
    comment_timestamp = format_date(new_comment.timestamp)
    return jsonify({
        'comment_author': new_comment.user.first_name,
        'comment_content': new_comment.content,
        'comment_pk': new_comment.comment_pk,
        'comment_timestamp': comment_timestamp
    })
Exemplo n.º 3
0
def ajax():
    # Utility entry point for various functions that are triggered by the javascript.
    action = request.args['action']
    log_access('ajax', 'query' + request.query_string)

    # AutoSaveForm is used to recover any edits on the calls when users browser closes for an unintended reason.
    if action == 'setautosaveform':
        model.set_autosave_form(request.args['key'], json.dumps(request.form))

    elif action == 'getautosaveform':
        return model.get_autosave_form(request.args['key'])

    elif action == 'deleteautosaveform':
        model.delete_autosave_form(request.args['key'])

    # Templates are quick text blobs used for editing the calls.
    elif action == 'gettemplatelist':
        return json.dumps(model.get_template_list())

    elif action == 'addtemplate':
        id = model.add_template(request.form)
        return json.dumps(model.get_template(id))

    elif action == 'settemplate':
        model.set_template(request.form)
        return json.dumps(model.get_template(request.form['id']))

    elif action == 'deletetemplate':
        model.delete_template(request.form['id'])

    elif action == 'startemplate':
        return json.dumps(model.star_template(request.form['id']))

    elif action == 'getresidentsstarredtemplates':
        return json.dumps(model.get_residents_starred_templates())

    # Commenting related functions
    elif action == 'addcomment':
        model.add_comment(request.args['key'], request.form['comment'])
        return json.dumps(model.get_comments(request.args['key']))

    elif action == 'deletecomment':
        id = request.args['comment_id']
        comment = model.get_comment(id)
        if session['user_auth_level'] >= 10000 or comment['username'] == session['user_username']: # administrator
            model.delete_comment(id)

    elif action == 'savecomment':
        id = request.args['comment_id']
        comment = model.get_comment(id)
        if session['user_auth_level'] >= 10000 or comment['username'] == session['user_username']: # administrator
            model.edit_comment(id, request.form['comment'])

    elif action == 'getcomments':
        call_id = request.args['key']
        comments = model.get_comments(call_id)
        for comment in comments:
            comment['blob'] = text_process(comment['blob'])
        return json.dumps(comments)

    # Deletes a call record.
    elif action == 'deletecalllog':
        key = request.args['key']
        if session['user_auth_level'] >= 10000 \
                or (model.is_call_log_owner(session['user_id'], key) and model.get_call_log(key)['created'] >= datetime.today() - timedelta(days=config.DISABLE_EDIT_AGE)): #  administrator
            model.delete_call_log(key)

    # Returns calls of a specific patient by the patients hospital number.
    elif action == 'searchforpatientnumber':
        key = request.args['key']
        key = key.strip()
        return json.dumps(model.get_calls_by_patient_number(key))

    # Tag related
    elif action == 'deletetag':
        model.delete_tag(request.args['tag'])

    elif action == 'saveTagChange':
        model.save_tag_change_for_call(int(request.args['id']), request.args['tag'], int(request.args['added']))

    # Liking a call, currently there is no limit on how many times you can like a record.
    elif action == 'like':
        key = int(request.args['id'])
        model.like_call_log(key)
        call = model.get_call_log(key)
        return str(call['liked'])

    # Flags a record
    elif action == 'flag':
        key = int(request.args['id'])
        flag = int(request.args['flag'])
        flag_state = model.get_flag(request.args['id'])
        if flag_state == flag:
            model.delete_flag(request.args['id'])
        else:
            model.set_flag(key, flag)

        return str(model.get_flag(request.args['id']))

    return '1'