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): 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): 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()