def as_dict(self): representation = HALRepresentation({}) representation.add_embed('events', [ HALEventRepresentation(e, 'events.event').as_dict() for e in self.events ]) if self.day and self.month and self.year: representation.add_links( get_nav_links(self.endpoint, self.start, self.count, self.size, day=self.day, month=self.month, year=self.year)) representation.add_link( 'self', url_for(self.endpoint, day=self.day, month=self.month, year=self.year)) else: representation.add_links( get_nav_links(self.endpoint, self.start, self.count, self.size)) representation.add_link('self', url_for(self.endpoint)) return representation.as_dict()
def as_dict(self): base = super(HALCourseRepresentation, self).as_dict() presentations = base.pop('presentations') representation = HALRepresentation(base) representation.add_embed('presentations', presentations) representation.add_link('self', url_for(self.endpoint, id=self.course.id)) return representation.as_dict()
def as_dict(self): base = super(HALTypesRepresentation, self).as_dict() representation = HALRepresentation(base) representation.add_link("self", url_for(self.endpoint)) representation.add_curie("hl", RELATIONS_CURIE) representation.add_link("hl:search", url_for("places.search") + "?type={type}") return representation.as_dict()
def as_dict(self): representation = HALRepresentation({"query": self.search, "size": self.size}) url_kwargs = {} if self.search: url_kwargs["q"] = self.search if self.type: url_kwargs["type"] = self.type if self.type_exact: url_kwargs["type_exact"] = self.type_exact if self.facets: url_kwargs["facet"] = self.facets.keys() if self.other_args: url_kwargs.update(self.other_args) representation.add_link("self", url_for(self.endpoint, start=self.start, count=self.count, **url_kwargs)) representation.add_links(get_nav_links(self.endpoint, self.start, self.count, self.size, **url_kwargs)) representation.add_embed("pois", [HALPOIRepresentation(r, "places.poidetail").as_dict() for r in self.results]) if self.facets: for field_name, facet_counts in self.facets.items(): curie = FACET_CURIE friendly_name = field_name if field_name in FACET_RENAME: curie, friendly_name = FACET_RENAME[field_name] for val, count in facet_counts.items(): kwargs = {"value": val, "count": count} if field_name in FACET_BY_TYPE: kwargs["title"] = find_type_name(val) kwargs["name"] = val url_kwargs[field_name] = val representation.update_link( "%s:%s" % (curie, friendly_name), url_for(self.endpoint, **url_kwargs), **kwargs ) del url_kwargs[field_name] return representation.as_dict()
def as_dict(self): base = super(HALWebcamRepresentation, self).as_dict() representation = HALRepresentation(base) representation.add_link('self', url_for(self.endpoint, slug=self.webcam.slug)) if self.webcam.poi: # TODO remove hardcoded endpoint for places representation.add_link('poi', url_for('places.poidetail', ident=self.webcam.poi)) return representation.as_dict()
def as_dict(self): representation = HALRepresentation(self.notification.as_dict()) followups = [HALFollowUpRepresentation(fu, self.notification, 'notifications.followp_details').as_dict() for fu in self.notification.followups] if followups: representation.add_embed('followups', followups) representation.add_link('self', url_for(self.endpoint, ident=self.notification.uuid)) return representation.as_dict()
def as_dict(self): representation = HALRepresentation({}) halified = [] for notification in self.notifications: halified.append(HALNotificationRepresentation(notification, 'notifications.notification_details').as_dict()) representation.add_embed('notifications', halified) representation.add_link('self', url_for(self.endpoint)) return representation.as_dict()
def as_dict(self): representation = HALRepresentation({}) representation.add_embed('webcams', [ HALWebcamRepresentation(w, 'webcams.webcam').as_dict() for w in self.webcams ]) representation.add_link('self', url_for('webcams.webcams')) return representation.as_dict()
def as_dict(self): values = {} values[<XXX>] = <XXX> values['_attribution'] = self.attribution values['_last_updated'] = self.last_updated representation = HALRepresentation(values) representation.add_link('self', url_for(self.endpoint)) return representation.as_dict()
def get_routes(): path = request.path representation = HALRepresentation({}) representation.add_curie('hl', TRANSPORT_CURIE) representation.add_link('self', '{bp}'.format(bp=path)) representation.add_link('hl:p-r', '{bp}park-and-rides'.format(bp=path), title='Park and Rides Real-Time Information') response = make_response(representation.as_json(), 200) response.headers['Content-Type'] = "application/json" return response
def get_routes(): path = request.path representation = HALRepresentation({}) representation.add_curie('hl', 'http://moxie.readthedocs.org/en/latest/http_api/contact.html#{rel}') representation.add_link('self', '{bp}'.format(bp=path)) representation.add_link('hl:search', '{bp}search?q={{q}}&medium={{medium}}'.format(bp=path), templated=True, title='Search') response = make_response(representation.as_json(), 200) response.headers['Content-Type'] = "application/json" return response
def as_dict(self): base = super(HALWebcamRepresentation, self).as_dict() representation = HALRepresentation(base) representation.add_link('self', url_for(self.endpoint, slug=self.webcam.slug)) if self.webcam.poi: # TODO remove hardcoded endpoint for places representation.add_link( 'poi', url_for('places.poidetail', ident=self.webcam.poi)) return representation.as_dict()
def handle_request(self): ctx = _app_ctx_stack.top services = ctx.app.blueprints self.browser_url = ctx.app.config.get('HAL_BROWSER_REDIRECT', None) representation = HALRepresentation({}) representation.add_link('self', '/') representation.add_curie('app', APPS_CURIE) for service, conf in services.iteritems(): representation.add_link('app:{app}'.format(app=service), '{prefix}/'.format(prefix=conf.url_prefix)) return representation
def as_dict(self): response = { 'query': self.query, } # Need to have the '.' before 'course' to correctly pick the URL courses = [HALCourseRepresentation(r, '.course').as_dict() for r in self.courses] representation = HALRepresentation(response) representation.add_embed('courses', courses) representation.add_link('self', url_for(self.endpoint, q=self.query)) representation.add_links(get_nav_links(self.endpoint, self.start, self.count, self.size, q=self.query)) return representation.as_dict()
def as_dict(self): representation = HALRepresentation({}) representation.add_embed('events', [HALEventRepresentation(e, 'events.event').as_dict() for e in self.events]) if self.day and self.month and self.year: representation.add_links(get_nav_links(self.endpoint, self.start, self.count, self.size, day=self.day, month=self.month, year=self.year)) representation.add_link('self', url_for(self.endpoint, day=self.day, month=self.month, year=self.year)) else: representation.add_links(get_nav_links(self.endpoint, self.start, self.count, self.size)) representation.add_link('self', url_for(self.endpoint)) return representation.as_dict()
def as_dict(self): values = {} if self.observation: values['observation'] = self.observation.as_dict() else: values['observation'] = None values['forecasts'] = [f.as_dict() for f in self.forecasts] values['_attribution'] = self.attribution values['_last_updated'] = self.last_updated representation = HALRepresentation(values) representation.add_link('self', url_for(self.endpoint)) return representation.as_dict()
def as_dict(self): base = super(HALPresentationRepresentation, self).as_dict() representation = HALRepresentation(base) courses_service = CourseService.from_context() try: courses_service.get_provider(self.presentation) except ProviderException: logger.debug('No single provider found for: %s' % self.presentation.id) else: representation.add_link('book', url_for('.presentation_booking', id=self.presentation.id)) if self.presentation.location: representation.add_link('poi', url_for('places.poidetail', ident=self.presentation.location)) return representation.as_dict()
def get_routes(): path = request.path representation = HALRepresentation({}) representation.add_curie('hl', PLACES_CURIE) representation.add_link('self', '{bp}'.format(bp=path)) representation.add_link('hl:search', '{bp}search?q={{q}}'.format(bp=path), templated=True, title='Search') representation.add_link('hl:types', '{bp}types'.format(bp=path), title='List of types') representation.add_link('hl:detail', '{bp}{{id}}'.format(bp=path), templated=True, title='POI detail') representation.add_link('hl:rti', '{bp}{{id}}/rti/{{type}}'.format(bp=path), templated=True, title='Real-Time Information for a given POI') response = make_response(representation.as_json(), 200) response.headers['Content-Type'] = "application/json" return response
def test_hal_json_helper_representation(self): representation = HALRepresentation({'a':'b'}) representation.add_link('self', '/a/b') representation.add_link('list', '/list', templated=True) representation.update_link('child', '/child/1') representation.update_link('child', '/child/2') representation.add_curie('cu', 'http://curie.com') representation.add_embed('rel', [HALRepresentation({'embed': 'yes'}, links={'self':{'href':'a'}}).as_dict()]) self.assertDictContainsSubset({'_links': { 'self': {'href': '/a/b'}, 'list': {'href': '/list', 'templated': True}, 'child': [{'href': '/child/1'}, {'href': '/child/2'}], 'curie': {'href': 'http://curie.com', 'name': 'cu', 'templated': True}}}, representation.as_dict()) self.assertDictContainsSubset( {'_embedded': {'rel': [{'embed': 'yes', '_links': {'self': {'href': 'a'}}}]}}, representation.as_dict())
def get_routes(): path = request.path representation = HALRepresentation({}) representation.add_curie('hl', CURIE_ENDPOINT) representation.add_link('self', '{bp}'.format(bp=path)) representation.add_link('hl:bookings', '{bp}bookings'.format(bp=path), title="Bookings") representation.add_link('hl:subjects', '{bp}subjects'.format(bp=path), title="Subjects") representation.add_link('hl:search', '{bp}search?q={{q}}'.format(bp=path), templated=True, title='Search') representation.add_link('hl:course', '{bp}course/{{id}}'.format(bp=path), templated=True, title='Course details') response = make_response(representation.as_json(), 200) response.headers['Content-Type'] = "application/json" return response
def get_routes(): path = request.path representation = HALRepresentation({}) representation.add_curie('hl', 'http://moxie.readthedocs.org/en/latest/http_api/library.html#{rel}') representation.add_link('self', '{bp}'.format(bp=path)) representation.add_link('hl:search', '{bp}search?title={{title}}&author={{author}}&isbn={{isbn}}'.format(bp=path), templated=True, title='Search') representation.add_link('hl:item', '{bp}item:{{id}}'.format(bp=path), templated=True, title='POI detail') response = make_response(representation.as_json(), 200) response.headers['Content-Type'] = "application/json" return response
def get_routes(): path = request.path representation = HALRepresentation({}) representation.add_curie('hl', 'http://moxie.readthedocs.org/en/latest/http_api/oxford_dates.html#{rel}') representation.add_link('self', '{bp}'.format(bp=path)) representation.add_link('hl:today', '{bp}today'.format(bp=path), title='Today date') representation.add_link('hl:date', '{bp}{{yyyy}}-{{mm}}-{{dd}}'.format(bp=path), templated=True, title="Format arbitrary date") response = make_response(representation.as_json(), 200) response.headers['Content-Type'] = "application/json" return response
def get_routes(): path = request.path representation = HALRepresentation({}) representation.add_curie( 'hl', 'http://moxie.readthedocs.org/en/latest/http_api/events.html#{rel}') representation.add_link('self', '{bp}'.format(bp=path)) representation.add_link('hl:search', '{bp}search'.format(bp=path), title="Search events") representation.add_link('hl:event', '{bp}event/{{id}}'.format(bp=path), templated=True, title="Event") response = make_response(representation.as_json(), 200) response.headers['Content-Type'] = "application/json" return response
def as_dict(self): rivers = RiversStatusRepresentation(self.rivers, self.last_updated).as_dict() representation = HALRepresentation(rivers) representation.add_link('self', url_for(self.endpoint)) return representation.as_dict()
def as_dict(self): base = super(HALPOIRepresentation, self).as_dict() representation = HALRepresentation(base) representation.add_link("self", url_for(self.endpoint, ident=self.poi.id)) if self.poi.files: reps = [FileRepresentation(r).as_dict() for r in self.poi.files] representation.add_embed("files", reps) try: poi_service = POIService.from_context() except NoConfiguredService: poi_service = None if poi_service and self.add_parent_children_links: # Merging all IDs (parent and children) into one set to # do only one query to the service pois_ids = set(self.poi.children) pois_ids.update(self.poi.parent) if self.poi.primary_place: pois_ids.add(self.poi.primary_place) if pois_ids: pois_objects = poi_service.get_places_by_identifiers(pois_ids) # ease lookup by having a dict with ID as key if pois_objects: pois = dict((poi.id, poi) for poi in pois_objects) else: pois = {} def add_link(relation, method, identifier): """Add a link w/ or w/o title depending if we found a POI :param relation: link rel (parent or child) :param method: method to apply (add_link or update if it should be an array) :param identifier: ID of the POI for lookup """ poi = pois.get(identifier, None) if poi and poi.name: method( relation, url_for(self.endpoint, ident=identifier), title=poi.name, type=poi.type, type_name=poi.type_name, ) else: method(relation, url_for(self.endpoint, ident=identifier)) if self.poi.parent: for parent in self.poi.parent: add_link("parent", representation.update_link, parent) if self.poi.primary_place: add_link("primary_place", representation.add_link, self.poi.primary_place) if self.poi.children: for child in self.poi.children: add_link("child", representation.update_link, child) try: transport_service = TransportService.from_context() except NoConfiguredService: # Transport service not configured so no RTI information logger.warning("No configured Transport service", exc_info=True) else: try: provider = transport_service.get_provider(self.poi) except ProviderException: logger.debug("No single provider found for: %s" % self.poi.id) else: representation.add_curie("rti", RTI_CURIE) for rtitype, title in provider.provides.items(): representation.add_link( "rti:%s" % rtitype, url_for("places.rti", ident=self.poi.id, rtitype=rtitype), title=title ) return representation.as_dict()
def as_dict(self): base = super(HALEventRepresentation, self).as_dict() representation = HALRepresentation(base) representation.add_link('self', url_for(self.endpoint, ident=self.event.signature)) return representation.as_dict()
def as_dict(self): representation = HALRepresentation({"count": self.count}) representation.add_link("self", url_for(self.endpoint, ident=",".join(self.pois_ids))) representation.add_embed("pois", [HALPOIRepresentation(r, "places.poidetail").as_dict() for r in self.results]) return representation.as_dict()
def as_dict(self): representation = HALRepresentation({}) representation.add_embed('webcams', [HALWebcamRepresentation(w, 'webcams.webcam').as_dict() for w in self.webcams]) representation.add_link('self', url_for('webcams.webcams')) return representation.as_dict()
def as_dict(self): base = super(HALEventRepresentation, self).as_dict() representation = HALRepresentation(base) representation.add_link( 'self', url_for(self.endpoint, ident=self.event.signature)) return representation.as_dict()
def as_dict(self): persons = PersonsRepresentation(self.persons).as_dict() representation = HALRepresentation(persons) representation.add_link('self', url_for(self.endpoint, q=self.query, medium=self.medium, match=self.match)) return representation.as_dict()
def as_dict(self): representation = HALRepresentation(self.followup.as_dict()) representation.add_link('self', url_for(self.endpoint, ident=self.notification.uuid, id=self.followup.id)) return representation.as_dict()