コード例 #1
0
 def wrapper(*args, **kwargs):
     response = f(*args, **kwargs)
     if isinstance(response, tuple):
         data, code, header = unpack(response)
     else:
         data = response
     collection = None
     kwargs["_external"] = True
     templated = True
     for key in data.keys():
         if key in collections_to_resource_type.keys():
             collection = key
         if key in resource_type_to_collection.keys():
             collection = resource_type_to_collection[key]
     if collection is None:
         return response
     kwargs["uri"] = collection + '/'
     if "id" in kwargs.keys():
         kwargs["uri"] += kwargs["id"]
         del kwargs["id"]
         templated = False
     else:
         kwargs["uri"] += '{' + collection + ".id}"
     if collection in ['stop_areas', 'stop_points', 'lines', 'routes',
                       'addresses'] and "region" in kwargs:
         for api in ['route_schedules', 'stop_schedules',
                     'arrivals', 'departures', "places_nearby"]:
             data['links'].append({
                 "href": url_for("v1." + api, **kwargs),
                 "rel": api,
                 "templated": templated
             })
     if collection in ['stop_areas', 'stop_points', 'addresses']:
         data['links'].append({
             "href": url_for("v1.journeys", **kwargs),
             "rel": "journeys",
             "templated": templated
         })
     #for lines we add the link to the calendars
     if 'region' in kwargs:
         if collection == 'lines':
             data['links'].append({
                 "href": url_for("v1.calendars", **kwargs),
                 "rel": "calendars",
                 "templated": templated
             })
         if collection in ['stop_areas', 'lines', 'networks']:
             data['links'].append({
                 "href": url_for("v1.traffic_reports", **kwargs),
                 "rel": "disruptions",
                 "templated": templated
             })
     if isinstance(response, tuple):
         return data, code, header
     else:
         return data
コード例 #2
0
 def wrapper(*args, **kwargs):
     objects = f(*args, **kwargs)
     if objects[1] != 200:
         return objects
     if isinstance(objects, tuple):
         data, code, header = unpack(objects)
     else:
         data = objects
     self.get_objets(data)
     data = self.prepare_objetcs(objects, True)
     kwargs = self.prepare_kwargs(kwargs, data)
     uri_id = None
     if "id" in kwargs.keys() and\
        "collection" in kwargs.keys() and \
        kwargs["collection"] in data.keys():
         uri_id = kwargs["id"]
     for obj in self.data:
         if obj in resource_type_to_collection.keys():
             kwargs["collection"] = resource_type_to_collection[obj]
         else:
             kwargs["collection"] = obj
         if kwargs["collection"] in collections_to_resource_type.keys():
             if not uri_id:
                 kwargs["id"] = "{" + obj + ".id}"
             endpoint = "v1." + kwargs["collection"] + "."
             endpoint += "id" if "region" in kwargs.keys() or\
                 "lon" in kwargs.keys()\
                                 else "redirect"
             collection = kwargs["collection"]
             to_pass = {
                 k: v
                 for k, v in kwargs.iteritems() if k != "collection"
             }
             data["links"].append(
                 create_external_link(url=endpoint,
                                      rel=collection,
                                      _type=obj,
                                      templated=True,
                                      **to_pass))
     if isinstance(objects, tuple):
         return data, code, header
     else:
         return data
コード例 #3
0
 def wrapper(*args, **kwargs):
     objects = f(*args, **kwargs)
     if objects[1] != 200:
         return objects
     if isinstance(objects, tuple):
         data, code, header = unpack(objects)
     else:
         data = objects
     self.get_objets(data)
     data = self.prepare_objetcs(objects, True)
     kwargs = self.prepare_kwargs(kwargs, data)
     uri_id = None
     if "id" in kwargs.keys() and\
        "collection" in kwargs.keys() and \
        kwargs["collection"] in data.keys():
         uri_id = kwargs["id"]
     for obj in self.data:
         if obj in resource_type_to_collection.keys():
             kwargs["collection"] = resource_type_to_collection[obj]
         else:
             kwargs["collection"] = obj
         if kwargs["collection"] in collections_to_resource_type.keys():
             if not uri_id:
                 kwargs["id"] = "{" + obj + ".id}"
             endpoint = "v1." + kwargs["collection"] + "."
             endpoint += "id" if "region" in kwargs.keys() or\
                 "lon" in kwargs.keys()\
                                 else "redirect"
             del kwargs["collection"]
             url = url_for(endpoint, _external=True, **kwargs)
             data["links"].append({
                 "href": url,
                 "rel": obj,
                 "templated": True
             })
     if isinstance(objects, tuple):
         return data, code, header
     else:
         return data