Example #1
0
def generate_report_id():
    document_id = get_report_id_document()
    database = get_database_object()
    document_object = database[document_id]
    old_id = document_object['highest_report_id']
    new_id = old_id + 1
    document_object['highest_report_id'] = new_id
    database[document_id] = document_object
    return new_id
Example #2
0
def get_report_id_document():
    query = query_database_by_document_type('report_id')
    results = query.rows
    if len(results) == 1:
        document_id = (results[0].value)['_id']
    else:
        if len(results) > 1:
            for row in results:
                delete_document_by_id(row.id)
        document_id = uuid4().hex
        highest_report_id = find_highest_report_id()
        database = get_database_object()
        database[document_id] = {'document_type': 'report_id',
                                 'highest_report_id': highest_report_id}
    return document_id
Example #3
0
def save_report_from_post_data(post_data):
    document_id = uuid4().hex
    report_location = post_data['location']
    report_timestamp = post_data['datetime']
    report_id = generate_report_id()
    report_latitude = post_data['latitude']
    report_longtitude = post_data['longtitude']
    report_title = post_data['title']
    report_description = post_data['description']
    new_document = {'document_type': 'report',
                    'location': report_location,
                    'report_id': report_id,
                    'timestamp': report_timestamp,
                    'latitude': report_latitude,
                    'longtitude': report_longtitude,
                    'title': report_title,
                    'description': report_description,}
    database = get_database_object()
    database[document_id] = new_document
    return report_id
Example #4
0
def execute_query(mapping_function):
    database = get_database_object()
    return database.query(mapping_function)