def api_calendars(): """ Retrieve calendars ================== The ``/api/calendars/`` endpoint returns the meetings meeting the provided criteria. Response format --------------- Sample response: .. code-block:: javascript { "calendars": [ { "calendar_multiple_meetings": false, "calendar_description": "test", "calendar_editor_group": "packager2", "calendar_admin_group": "packager", "calendar_contact": "test", "calendar_regional_meetings": false, "calendar_name": "test" }, { "calendar_multiple_meetings": false, "calendar_description": "asd", "calendar_editor_group": "", "calendar_admin_group": "", "calendar_contact": "asd", "calendar_regional_meetings": false, "calendar_name": "Another test" } ] } """ @flask.after_this_request def callback(response): return check_callback(response) calendars = fedocallib.get_calendars(SESSION) output = {"calendars": [calendar.to_json() for calendar in calendars]} return flask.Response( response=json.dumps(output), status=200, mimetype='application/json' )
def api_calendars(): """ Retrieve calendars ================== The ``/api/calendars/`` endpoint returns the meetings meeting the provided criteria. Response format --------------- Sample response: .. code-block:: javascript { "calendars": [ { "calendar_description": "test", "calendar_editor_group": "packager2", "calendar_admin_group": "packager", "calendar_contact": "test", "calendar_name": "test" }, { "calendar_description": "asd", "calendar_editor_group": "", "calendar_admin_group": "", "calendar_contact": "asd", "calendar_name": "Another test" } ] } """ @flask.after_this_request def callback(response): """ Handle case the query was an JQuery ajax call. """ return check_callback(response) calendars = fedocallib.get_calendars(SESSION) output = {"calendars": [calendar.to_json() for calendar in calendars]} return flask.Response( response=json.dumps(output), status=200, mimetype='application/json' )
def api_meetings(): """ Retrieve meetings ================= The ``/api/meetings/`` endpoint returns the meetings meeting the provided criteria. Response format ---------------- Sample response: .. code-block:: javascript { "meetings": [ { "meeting_time_start": "23:00:00", "meeting_information": "", "meeting_time_stop": "23:00:00", "calendar_name": "test", "meeting_date_end": "2013-05-27", "meeting_manager": "pingou2,", "meeting_date": "2013-05-27", "meeting_name": "test1.5", "meeting_location": "None" }, { "meeting_time_start": "06:00:00", "meeting_information": "", "meeting_time_stop": "07:00:00", "calendar_name": "test", "meeting_date_end": "2013-05-28", "meeting_manager": "pingou,", "meeting_date": "2013-05-28", "meeting_name": "test3", "meeting_location": null } ], "arguments": { "start": "2013-05-04", "calendar": "test", "end": "2013-11-30", "region": null } } The ``arguments`` item in the root dictionary contains all possible arguments, and displays the value used (the default if the argument was not provided). Time arguments -------------- Below is a table describing what timeframe messages are received from depending on what combination of time options you provide. ========= ======= ================= ``start`` ``end`` Message timeframe ========= ======= ================= no no the last 30 days and the coming 180 days **yes** no from ``start`` until the coming 180 days no **yes** the last 30 days until ``end`` **yes** **yes** between ``start`` and ``end`` ========= ======= ================= ``start`` Return results starting at date ``start`` (prefered format is "+%Y-%m-%d" see ``date "+%Y-%m-%d"``). Default: 30 days ago ``date "+%Y-%m-%d" -d "30 days ago"`` ``end`` Return results ending at date ``end`` (prefered format is "+%Y-%m-%d" see ``date "+%Y-%m-%d"``). Default: coming 180 days ``date "+%Y-%m-%d" -d "180 days"`` Filter arguments ---------------- ``calendar`` Restrict the meetings to a specific calendar. Default: all calendars ``region`` Restrict the meeting to a specific region. If the calendar does not have support for regions enabled, no meetings will be found matching this criteria and no meetings will be returned. Default: all regions """ @flask.after_this_request def callback(response): """ Handle case the query was an JQuery ajax call. """ return check_callback(response) startd = flask.request.args.get('start', None) if startd is None: startd = datetime.date.today() - datetime.timedelta(days=30) else: try: startd = parser.parse(startd).date() except ValueError: output = {"meetings": [], "error": "Invalid start date format: %s" % startd} return flask.Response( response=json.dumps(output), status=400, mimetype='application/json') endd = flask.request.args.get('end', None) if endd is None: endd = datetime.date.today() + datetime.timedelta(days=180) else: try: endd = parser.parse(endd).date() except ValueError: output = {"meetings": [], "error": "Invalid end date format: %s" % endd} return flask.Response( response=json.dumps(output), status=400, mimetype='application/json') calendar_name = flask.request.args.get('calendar', None) location = flask.request.args.get('location', None) region = flask.request.args.get('region', None) location = location or region if calendar_name: calendarobj = Calendar.by_id(SESSION, calendar_name) if not calendarobj: output = {"meetings": [], "error": "Invalid calendar provided: %s" % calendar_name} return flask.Response( response=json.dumps(output), status=400, mimetype='application/json') status = 200 meetings = [] try: if calendar_name: if location: #print "calendar and region" meetings = fedocallib.get_meetings_by_date_and_location( SESSION, calendar_name, startd, endd, location) else: #print "calendar and no region" meetings = fedocallib.get_by_date( SESSION, calendarobj, startd, endd) else: meetings = [] if location: #print "no calendar and region" meetings.extend( fedocallib.get_by_date_at_location( SESSION, location, startd, endd) ) else: #print "no calendar and no region" for calendar in fedocallib.get_calendars(SESSION): meetings.extend(fedocallib.get_by_date( SESSION, calendar, startd, endd)) except SQLAlchemyError, err: # pragma: no cover status = 500 LOG.debug('Error in api_meetings') LOG.exception(err)
def api_meetings(): """ Retrieve meetings ================= The ``/api/meetings/`` endpoint returns the meetings meeting the provided criteria. Response format ---------------- Sample response: .. code-block:: javascript { "meetings": [ { "meeting_time_start": "23:00:00", "meeting_information": "", "meeting_time_stop": "23:00:00", "calendar_name": "test", "meeting_date_end": "2013-05-27", "meeting_manager": [ "pingou2" ], "meeting_date": "2013-05-27", "meeting_name": "test1.5", "meeting_location": "None", "meeting_timezone": "UTC" }, { "meeting_time_start": "06:00:00", "meeting_information": "", "meeting_time_stop": "07:00:00", "calendar_name": "test", "meeting_date_end": "2013-05-28", "meeting_manager": [ "pingou" ], "meeting_date": "2013-05-28", "meeting_name": "test3", "meeting_location": null, "meeting_timezone": "UTC" } ], "arguments": { "start": "2013-05-04", "calendar": "test", "end": "2013-11-30", "region": null } } The ``meeting_time_start``, ``meeting_time_end``, ``meeting_date`` and ``meeting_date_end`` contain time in "UTC". The ``meeting_timezone`` indicates the timezone the meeting is registered with. If the ``meeting_timezone`` is not "UTC", the meeting time will change according to DST rules of the specified timezone. The ``arguments`` item in the root dictionary contains all possible arguments, and displays the value used (the default if the argument was not provided). Time arguments -------------- Below is a table describing what timeframe messages are received from depending on what combination of time options you provide. ========= ======= ================= ``start`` ``end`` Message timeframe ========= ======= ================= no no the last 30 days and the coming 180 days **yes** no from ``start`` until the coming 180 days no **yes** the last 30 days until ``end`` **yes** **yes** between ``start`` and ``end`` ========= ======= ================= ``start`` Return results starting at date ``start`` (prefered format is "+%Y-%m-%d" see ``date "+%Y-%m-%d"``). Default: 30 days ago ``date "+%Y-%m-%d" -d "30 days ago"`` ``end`` Return results ending at date ``end`` (prefered format is "+%Y-%m-%d" see ``date "+%Y-%m-%d"``). Default: coming 180 days ``date "+%Y-%m-%d" -d "180 days"`` Filter arguments ---------------- ``calendar`` Restrict the meetings to a specific calendar. Default: all calendars ``region`` Restrict the meeting to a specific region. If the calendar does not have support for regions enabled, no meetings will be found matching this criteria and no meetings will be returned. Default: all regions """ @flask.after_this_request def callback(response): """ Handle case the query was an JQuery ajax call. """ return check_callback(response) startd = flask.request.args.get('start', None) if startd is None: startd = datetime.date.today() - datetime.timedelta(days=30) else: try: startd = parser.parse(startd).date() except (ValueError, TypeError): output = {"meetings": [], "error": "Invalid start date format: %s" % startd} return flask.Response( response=json.dumps(output), status=400, mimetype='application/json') endd = flask.request.args.get('end', None) if endd is None: endd = datetime.date.today() + datetime.timedelta(days=180) else: try: endd = parser.parse(endd).date() except (ValueError, TypeError): output = {"meetings": [], "error": "Invalid end date format: %s" % endd} return flask.Response( response=json.dumps(output), status=400, mimetype='application/json') calendar_name = flask.request.args.get('calendar', None) location = flask.request.args.get('location', None) region = flask.request.args.get('region', None) location = location or region if calendar_name: calendarobj = Calendar.by_id(SESSION, calendar_name) if not calendarobj: output = { "meetings": [], "error": "Invalid calendar provided: %s" % calendar_name} return flask.Response( response=json.dumps(output), status=400, mimetype='application/json') status = 200 meetings = [] try: if calendar_name: if location: # print "calendar and region" meetings = fedocallib.get_meetings_by_date_and_location( SESSION, calendar_name, startd, endd, location) else: # print "calendar and no region" meetings = fedocallib.get_by_date( SESSION, calendarobj, startd, endd) else: meetings = [] if location: # print "no calendar and region" meetings.extend( fedocallib.get_by_date_at_location( SESSION, location, startd, endd) ) else: # print "no calendar and no region" for calendar in fedocallib.get_calendars(SESSION): meetings.extend(fedocallib.get_by_date( SESSION, calendar, startd, endd)) except SQLAlchemyError as err: # pragma: no cover status = 500 LOG.debug('Error in api_meetings') LOG.exception(err) output = {} output['arguments'] = { 'start': startd.strftime('%Y-%m-%d'), 'end': endd.strftime('%Y-%m-%d'), 'calendar': calendar_name, 'location': location, } meetings_json = [] for meeting in meetings: meetings_json.append(meeting.to_json()) output['meetings'] = meetings_json return flask.Response( response=json.dumps(output), status=status, mimetype='application/json' )