def get(self, schedule_id): query = ScheduleItem.query.filter_by(schedule_id=schedule_id).all() if len(query) == 0: return DiaryBuilder.create_error_response( 404, 'Schedule does not exist or has no items') body = DiaryBuilder() body.add_namespace() body.add_control('self', url_for('.itemcollection', schedule_id=schedule_id)) body.add_control('collection', url_for('.scheduleresource', schedule_id=schedule_id)) body.add_control('profile', '/profiles/item/') body.add_control_add_item(schedule_id) body.add_control_events_in(schedule_id) body.add_control_tasks_in(schedule_id) body.add_control_all_schedules() items = [] for item in query: item = item.item item_dict = MasonBuilder(name=item.name, value=item.value, id=item.id) item_dict.add_control( 'self', url_for('.itemresource', schedule_id=schedule_id, item_id=item.id)) item_dict.add_control('profile', '/profiles/item/') items.append(item_dict) body['items'] = items return Response(json.dumps(body, indent=4), status=200, mimetype=MIMETYPE)
def get(self, schedule_id, item_id): query = Item.query.filter_by(id=item_id).first() if query is None: return DiaryBuilder.create_error_response(404, 'Item does not exist') body = DiaryBuilder() body['name'] = query.name body['value'] = query.value body.add_namespace() body.add_control( 'self', url_for('.itemresource', schedule_id=schedule_id, item_id=item_id)) body.add_control('collection', url_for('.itemcollection', schedule_id=schedule_id)) body.add_control('profile', '/profiles/item/') body.add_control_edit_item(schedule_id, item_id) body.add_control_add_item(schedule_id) body.add_control_delete_item(schedule_id, item_id) return Response(json.dumps(body, indent=4), status=200, mimetype=MIMETYPE)