Esempio n. 1
0
def get_all_events():
    connection = query_db.get_connection(current_db_location())

    json = '{"events": ['

    if connection is not None:
        events = query_db.get_all_events(connection)
        connection.close()
        if len(events) > 0:
            for count, event in enumerate(events, start=1):
                if event:
                    # Get the event date and change the date format back to dd-mm-yyyy.
                    unformatted_date = event.date
                    formatted_date = Event.date_format_ddmmyyyy(unformatted_date)
                    event.date = formatted_date
                    json += event.jsonify()

                    # Add comma after json object created
                    # up until the last one, then add }
                    if count is not len(events):
                        json += ',' + "\r\n"
                    else:
                        json += ' ] }'
        else:
            json = empty_json_for_array("events")
        return Response(status=SUCCESS_CODE, response=json, mimetype='application/json')
    # Failure
    return Response(status=FAILURE_CODE)
Esempio n. 2
0
def get_upcoming_event():
    connection = query_db.get_connection(current_db_location())
    if connection is not None:

        event = query_db.get_upcoming_event(connection)
        connection.close()

        if event:
            # Get the event date and change the date format back to dd-mm-yyyy.
            unformatted_date = event.date
            formatted_date = Event.date_format_ddmmyyyy(unformatted_date)
            event.date = formatted_date
            json = event.jsonify()
        else:
            json = empty_json_for_object("event")
        return Response(status=SUCCESS_CODE, response=json, mimetype='application/json')
    # Failure
    return Response(status=FAILURE_CODE)