예제 #1
0
        def wrapper(*args, **kwargs):
            objects = f(*args, **kwargs)
            if has_invalid_reponse_code(objects) or journeys_absent(objects):
                return objects

            if 'tickets' not in objects[0]:
                return objects

            ticket_by_section = defaultdict(list)
            for t in objects[0]['tickets']:
                if "links" in t:
                    for s in t['links']:
                        ticket_by_section[s['id']].append(t['id'])

            for j in objects[0]['journeys']:
                if "sections" not in j:
                    continue
                for s in j['sections']:

                    # them we add the link to the different tickets needed
                    for ticket_needed in ticket_by_section[s["id"]]:
                        s['links'].append(create_internal_link(_type="ticket", rel="tickets", id=ticket_needed))
                    if "ridesharing_journeys" not in s:
                        continue
                    for rsj in s['ridesharing_journeys']:
                        if "sections" not in rsj:
                            continue
                        for rss in rsj['sections']:
                            # them we add the link to the different ridesharing-tickets needed
                            for rs_ticket_needed in ticket_by_section[rss["id"]]:
                                rss['links'].append(
                                    create_internal_link(_type="ticket", rel="tickets", id=rs_ticket_needed)
                                )

            return objects
예제 #2
0
파일: schedule.py 프로젝트: xlqian/navitia
 def get_links(self, obj):
     disruption_links = [
         create_internal_link(_type="disruption", rel="disruptions", id=uri)
         for uri in obj.impact_uris
     ]
     properties_links = pt.make_properties_links(obj.properties)
     return properties_links + disruption_links
예제 #3
0
        def wrapper(*args, **kwargs):
            objects = f(*args, **kwargs)
            if objects[1] != 200:
                return objects
            if "journeys" not in objects[0]:
                return objects
            ticket_by_section = defaultdict(list)
            if 'tickets' not in objects[0]:
                return objects

            for t in objects[0]['tickets']:
                if "links" in t:
                    for s in t['links']:
                        ticket_by_section[s['id']].append(t['id'])

            for j in objects[0]['journeys']:
                if "sections" not in j:
                    continue
                for s in j['sections']:

                    #them we add the link to the different tickets needed
                    for ticket_needed in ticket_by_section[s["id"]]:
                        s['links'].append(
                            create_internal_link(_type="ticket",
                                                 rel="tickets",
                                                 id=ticket_needed))

            return objects
예제 #4
0
    def get_links(self, obj):
        if not hasattr(obj, 'ticket_id'):
            return []

        return [
            create_internal_link(id=value, rel='tickets', _type='ticket')
            for value in obj.ticket_id
        ]
예제 #5
0
    def get_links(self, obj):
        if not hasattr(obj, 'section_id'):
            return None

        return [
            create_internal_link(id=value, rel='sections', _type='section')
            for value in obj.section_id
        ]
예제 #6
0
 def output(self, key, obj):
     ticket_ids = []
     try:
         for t_id in obj.ticket_id:
             ticket_ids.append(t_id)
     except ValueError:
         return None
     response = []
     for value in ticket_ids:
         response.append(
             create_internal_link(_type="ticket", rel="tickets", id=value))
     return response
예제 #7
0
파일: fields.py 프로젝트: Xzya/navitia
 def to_value(self, value):
     return [create_internal_link(_type="disruption", rel="disruptions", id=uri) for uri in value]
예제 #8
0
파일: fields.py 프로젝트: niko64fx/navitia
 def output(self, key, obj):
     return [
         create_internal_link(_type="disruption", rel="disruptions", id=uri)
         for uri in obj.impact_uris
     ]
예제 #9
0
 def output(self, key, obj):
     return [
         create_internal_link(_type="disruption",
                              rel="disruptions",
                              id=d.uri) for d in obj.disruptions
     ]