Example #1
0
def edit_request_info():
    """
    Edits the title and agency description of a FOIL request through an API PUT method.
    Retrieves updated edited content from AJAX call on view_request page and stores changes into database.

    :return: JSON Response with updated content: either request title or agency description)
    """
    edit_request = flask_request.form
    request_id = flask_request.form.get('pk')
    current_request = Requests.query.filter_by(id=request_id).first()
    previous_value = {}
    new_value = {}
    type_ = ''
    val = edit_request['value'].strip()
    if edit_request['name'] == 'title':
        previous_value['title'] = current_request.title
        new_value['title'] = val
        type_ = event_type.REQ_TITLE_EDITED
    elif edit_request['name'] == 'agency_request_summary':
        previous_value[
            'agency_request_summary'] = current_request.agency_request_summary
        new_value['agency_request_summary'] = val
        type_ = event_type.REQ_AGENCY_REQ_SUM_EDITED
    update_object({edit_request['name']: val if val else None}, Requests,
                  current_request.id)
    create_request_info_event(request_id, type_, previous_value, new_value)
    return jsonify(edit_request), 200
Example #2
0
def edit_request_info():
    """
    Edits the title and agency request summary of a FOIL request through an API PUT method.
    Retrieves updated edited content from AJAX call on view_request page and stores changes into database.

    :return: JSON Response with updated content: either request title or agency request summary)
    """
    edit_request = flask_request.form
    request_id = flask_request.form.get('pk')
    current_request = Requests.query.filter_by(id=request_id).first()
    previous_value = {}
    new_value = {}
    type_ = ''
    val = edit_request['value'].strip()
    if edit_request['name'] == 'title':
        previous_value['title'] = current_request.title
        new_value['title'] = val
        type_ = event_type.REQ_TITLE_EDITED
    elif edit_request['name'] == 'agency_request_summary':
        previous_value['agency_request_summary'] = current_request.agency_request_summary
        new_value['agency_request_summary'] = val
        type_ = event_type.REQ_AGENCY_REQ_SUM_EDITED
    update_object({edit_request['name']: val if val else None},
                  Requests,
                  current_request.id)
    create_request_info_event(request_id,
                              type_,
                              previous_value,
                              new_value)
    return jsonify(edit_request), 200
Example #3
0
def edit_privacy():
    """
    Edits the privacy privacy options of a request's title and agency description.
    Retrieves updated privacy options from AJAX call on view_request page and stores changes into database.

    :return: JSON Response with updated title and agency description privacy options
    """
    request_id = flask_request.form.get('id')
    current_request = Requests.query.filter_by(id=request_id).first()
    privacy = {}
    previous_value = {}
    new_value = {}
    title = flask_request.form.get('title')
    agency_request_summary = flask_request.form.get('agency_request_summary')
    type_ = ''
    if title is not None:
        privacy['title'] = title == 'true'
        previous_value['privacy'] = current_request.privacy['title']
        new_value['privacy'] = privacy['title']
        type_ = event_type.REQ_TITLE_PRIVACY_EDITED
    elif agency_request_summary is not None:
        privacy['agency_request_summary'] = agency_request_summary == 'true'
        previous_value['privacy'] = current_request.privacy[
            'agency_request_summary']
        new_value['privacy'] = privacy['agency_request_summary']
        type_ = event_type.REQ_AGENCY_REQ_SUM_PRIVACY_EDITED
    update_object({'privacy': privacy}, Requests, current_request.id)
    create_request_info_event(request_id, type_, previous_value, new_value)
    return jsonify(privacy), 200
Example #4
0
def edit_privacy():
    """
    Edits the privacy privacy options of a request's title and agency request summary.
    Retrieves updated privacy options from AJAX call on view_request page and stores changes into database.

    :return: JSON Response with updated title and agency request summary privacy options
    """
    request_id = flask_request.form.get('id')
    current_request = Requests.query.filter_by(id=request_id).first()
    privacy = {}
    previous_value = {}
    new_value = {}
    title = flask_request.form.get('title')
    agency_request_summary = flask_request.form.get('agency_request_summary')
    type_ = ''
    if title is not None:
        privacy['title'] = title == 'true'
        previous_value['privacy'] = current_request.privacy['title']
        new_value['privacy'] = privacy['title']
        type_ = event_type.REQ_TITLE_PRIVACY_EDITED
    elif agency_request_summary is not None:
        privacy['agency_request_summary'] = agency_request_summary == 'true'
        previous_value['privacy'] = current_request.privacy['agency_request_summary']
        new_value['privacy'] = privacy['agency_request_summary']
        type_ = event_type.REQ_AGENCY_REQ_SUM_PRIVACY_EDITED
    update_object({'privacy': privacy},
                  Requests,
                  current_request.id)
    create_request_info_event(request_id,
                              type_,
                              previous_value,
                              new_value)
    return jsonify(privacy), 200