Exemple #1
0
    def get(self, contributor, navitia, id=None):
        self.navitia = navitia
        if id:
            return marshal(
                {'disruption': models.Disruption.get(id, contributor.id)},
                one_disruption_fields)
        else:
            args = self.parsers['get'].parse_args()
            page_index = args['start_page']
            if page_index == 0:
                abort(400, message="page_index argument value is not valid")
            items_per_page = args['items_per_page']
            if items_per_page == 0:
                abort(400,
                      message="items_per_page argument value is not valid")
            publication_status = args['publication_status[]']
            tags = args['tag[]']
            uri = args['uri']
            statuses = args['status[]']

            g.current_time = args['current_time']
            result = models.Disruption.all_with_filter(
                page_index=page_index,
                items_per_page=items_per_page,
                contributor_id=contributor.id,
                publication_status=publication_status,
                tags=tags,
                uri=uri,
                statuses=statuses)
            response = {
                'disruptions': result.items,
                'meta': make_pager(result, 'disruption')
            }
            return marshal(response, disruptions_fields)
Exemple #2
0
    def get(self, contributor, disruption_id, navitia, id=None):
        self.navitia = navitia
        if id:
            response = models.Impact.get(id, contributor.id)
            return marshal({'impact': response}, one_impact_fields)
        else:
            if not id_format.match(disruption_id):
                return marshal({'error': {
                    'message': "disruption_id invalid"
                }}, error_fields), 400
            args = self.parsers['get'].parse_args()
            page_index = args['start_page']
            if page_index == 0:
                abort(400, message="page_index argument value is not valid")
            items_per_page = args['items_per_page']
            if items_per_page == 0:
                abort(400,
                      message="items_per_page argument value is not valid")

            result = models.Impact.all(page_index=page_index,
                                       items_per_page=items_per_page,
                                       disruption_id=disruption_id,
                                       contributor_id=contributor.id)
            response = {
                'impacts': result.items,
                'meta': make_pager(result,
                                   'impact',
                                   disruption_id=disruption_id)
            }
            return marshal(response, impacts_fields)
Exemple #3
0
    def get(self, contributor, navitia, id=None):
        self.navitia = navitia
        if id:
            return marshal(
                {'disruption': models.Disruption.get(id, contributor.id)},
                one_disruption_fields
            )
        else:
            args = self.parsers['get'].parse_args()
            page_index = args['start_page']
            if page_index == 0:
                abort(400, message="page_index argument value is not valid")
            items_per_page = args['items_per_page']
            if items_per_page == 0:
                abort(400, message="items_per_page argument value is not valid")
            publication_status = args['publication_status[]']
            tags = args['tag[]']
            uri = args['uri']
            statuses = args['status[]']

            g.current_time = args['current_time']
            result = models.Disruption.all_with_filter(
                page_index=page_index,
                items_per_page=items_per_page,
                contributor_id=contributor.id,
                publication_status=publication_status,
                tags=tags,
                uri=uri,
                statuses=statuses
            )
            response = {'disruptions': result.items, 'meta': make_pager(result, 'disruption')}
            return marshal(response, disruptions_fields)
Exemple #4
0
    def _get_disruptions(self, contributor_id, args):

        self._validate_arguments_for_disruption_list(args)
        g.current_time = args['current_time']
        page_index = args['start_page']
        items_per_page = args['items_per_page']
        publication_status = args['publication_status[]']
        ends_after_date = args['ends_after_date']
        ends_before_date = args['ends_before_date']
        tags = args['tag[]']
        uri = args['uri']
        line_section = args['line_section']
        statuses = args['status[]']

        result = models.Disruption.all_with_filter(
            page_index=page_index,
            items_per_page=items_per_page,
            contributor_id=contributor_id,
            publication_status=publication_status,
            ends_after_date=ends_after_date,
            ends_before_date=ends_before_date,
            tags=tags,
            uri=uri,
            line_section=line_section,
            statuses=statuses)

        response = {
            'disruptions': result.items,
            'meta': make_pager(result, 'disruption')
        }
        '''
        The purpose is to remove any database-loaded state from all current objects so that the next access of
        any attribute, or any query execution, will retrieve new state, freshening those objects which are still
        referenced outside of the session with the most recent available state.
        '''
        for o in result.items:
            models.db.session.expunge(o)
        return marshal(response, disruptions_fields)
Exemple #5
0
    def get(self, contributor, disruption_id, navitia, id=None):
        self.navitia = navitia
        if id:
            response = models.Impact.get(id, contributor.id)
            return marshal({'impact': response}, one_impact_fields)
        else:
            if not id_format.match(disruption_id):
                return marshal({'error': {'message': "disruption_id invalid"}},
                           error_fields), 400
            args = self.parsers['get'].parse_args()
            page_index = args['start_page']
            if page_index == 0:
                abort(400, message="page_index argument value is not valid")
            items_per_page = args['items_per_page']
            if items_per_page == 0:
                abort(400, message="items_per_page argument value is not valid")

            result = models.Impact.all(page_index=page_index,
                                       items_per_page=items_per_page,
                                       disruption_id=disruption_id,
                                       contributor_id=contributor.id)
            response = {'impacts': result.items, 'meta': make_pager(result, 'impact', disruption_id=disruption_id)}
            return marshal(response, impacts_fields)
Exemple #6
0
 def output(self, key, disruption):
     return make_pager(disruption.impacts.paginate(1, 20),
                       'impact',
                       disruption_id=disruption.id)
Exemple #7
0
 def output(self, key, disruption):
     return make_pager(disruption.impacts.paginate(1, 20),
                       'impact',
                       disruption_id=disruption.id)