Beispiel #1
0
    def _register_into_rest(cls):
        """
        Регистрация ресурсов в РЕСТе.
        """
        self = cls()
        cls.attr_response_post = cls.attr_response_post or cls.attr_json
        cls.attr_response_put = cls.attr_response_put or cls.attr_json
        type1 = type(
            cls.__name__ + "Item",
            (BaseTokeniseResource, ),
            {
                "get": marshal_with({'items': fields.List(fields.Nested(cls.attr_json)),
                                     'count': fields.Integer,
                                     'max': fields.Integer})(self.get_items.__func__).__get__(self, cls),
                "put": marshal_with(cls.attr_response_put)(self.put.__func__).__get__(self, cls),
                "parent": self
            }
        )

        type2 = type(
            cls.__name__ + "Items",
            (BaseTokeniseResource, ),
            {
                "get": marshal_with(cls.attr_json)(self.get.__func__).__get__(self, cls),
                "post": marshal_with(cls.attr_response_post)(self.post.__func__).__get__(self, cls),
                "delete": self.delete,
                "parent": self
            }
        )

        return type1, type2
Beispiel #2
0
    def _register_into_rest(cls):
        self = cls()
        type1 = type(
            cls.__name__ + "Item",
            (BaseTokeniseResource, ),
            {
                "get": marshal_with(cls.attr_json)(self.get.__func__).__get__(
                    self, cls),
                "post": marshal_with(cls.attr_response_post)(
                    self.post.__func__).__get__(self, cls),
            }
        )

        return (
            (cls.prefix_url_without_id, type1),
        )
Beispiel #3
0
 def wrapper(func):
     doc = {
         'responses': {
             code: (description, [fields]) if as_list else (description, fields)
         }
     }
     # doc = {'model': [fields]} if as_list else {'model': fields}
     # doc['default_code'] = code
     # doc['description'] = description
     func.__apidoc__ = merge(getattr(func, '__apidoc__', {}), doc)
     resolved = getattr(fields, 'resolved', fields)
     return restful.marshal_with(resolved, **kwargs)(func)
Beispiel #4
0
 def __init__(self, *args, **kwargs):
     Uri.__init__(self, is_collection, "stop_points", *args, **kwargs)
     self.collections = [
         ("stop_points",
          NonNullList(fields.Nested(stop_point, display_null=False))),
         ("pagination", PbField(pagination)),
         ("error", PbField(error))
     ]
     collections = marshal_with(OrderedDict(self.collections),
                                display_null=False)
     self.method_decorators.insert(1, collections)
     self.parsers["get"].add_argument("original_id", type=unicode,
                     description="original uri of the object you"
                             "want to query")
Beispiel #5
0
 def __init__(self):
     Uri.__init__(self, is_collection, "poi_types")
     self.collections = [
         ("poi_types",
          NonNullList(fields.Nested(poi_type, display_null=False))),
         ("pagination", PbField(pagination)), ("error", PbField(error)),
         ("disruptions", DisruptionsField),
         ("feed_publishers",
          NonNullList(fields.Nested(feed_publisher,
                                    display_null=False)))
     ]
     collections = marshal_with(OrderedDict(self.collections),
                                display_null=False)
     self.method_decorators.insert(1, collections)
Beispiel #6
0
 def __init__(self):
     Uri.__init__(self, is_collection, "journey_pattern_points")
     self.collections = [
         ("journey_pattern_points",
          NonNullList(
              fields.Nested(journey_pattern_point,
                            display_null=False))),
         ("pagination", PbField(pagination)),
         ("error", PbField(error)),
         ("disruptions", DisruptionsField),
     ]
     collections = marshal_with(OrderedDict(self.collections),
                                display_null=False)
     self.method_decorators.insert(1, collections)
Beispiel #7
0
 def _register_into_rest(cls):
     self = cls()
     type1 = type(
         cls.__name__ + "Item",
         (BaseTokeniseResource, ),
         {
             "get": marshal_with({'items': fields.List(fields.Nested(
                 cls.attr_json)),
                                  'count': fields.Integer,
                                  'max': fields.Integer})(
                 self.get.__func__).__get__(self, cls),
             "parent": self
         }
     )
     return type1
Beispiel #8
0
 def __init__(self):
     Uri.__init__(self, is_collection, "datasets")
     self.collections = [
         ("datasets",
          NonNullList(fields.Nested(dataset, display_null=False))),
         ("pagination", PbField(pagination)), ("error", PbField(error)),
         ("disruptions",
          fields.List(NonNullNested(disruption_marshaller),
                      attribute="impacts")),
         ("feed_publishers",
          NonNullList(fields.Nested(feed_publisher,
                                    display_null=False)))
     ]
     collections = marshal_with(OrderedDict(self.collections),
                                display_null=False)
     self.method_decorators.insert(1, collections)
Beispiel #9
0
 def __init__(self):
     Uri.__init__(self, is_collection, "line_groups")
     self.collections = [
         ("line_groups",
          NonNullList(fields.Nested(line_group,
                                    display_null=False))),
         ("pagination", PbField(pagination)),
         ("error", PbField(error)),
         ("disruptions", DisruptionsField),
     ]
     collections = marshal_with(OrderedDict(self.collections),
                                display_null=False)
     self.method_decorators.insert(1, collections)
     self.parsers["get"].add_argument("original_id", type=unicode,
                     description="original uri of the object you"
                             "want to query")
class Name(Resource):
    decorators = [marshal_with(response_body_schema)]

    def get(self):
        "return random Name"
        random_name = name.Name.random_key().get()
        return random_name

    @ndb.transactional
    def post(self):
        "create and return name; maintain no more than 11 names in datastore"
        kwargs = request_parser.parse_args()
        name_key = name.Name(parent=name.root, **kwargs).put()
        new_name = name_key.get()

        if name.Name.query(ancestor=name.root).count() > 10:
            name.Name.random_key(excluding=name_key).delete()

        return new_name
Beispiel #11
0
 def __init__(self):
     Uri.__init__(self, is_collection, "disruptions")
     self.collections = [
         ("pagination", PbField(pagination)), ("error", PbField(error)),
         ("disruptions",
          fields.List(NonNullNested(disruption_marshaller),
                      attribute="impacts")),
         ("feed_publishers",
          NonNullList(fields.Nested(feed_publisher,
                                    display_null=False)))
     ]
     collections = marshal_with(OrderedDict(self.collections),
                                display_null=False)
     self.method_decorators.insert(1, collections)
     self.parsers["get"].add_argument(
         "original_id",
         type=unicode,
         description="original uri of the object you"
         "want to query")
Beispiel #12
0
 def __init__(self):
     Uri.__init__(self, is_collection, "physical_modes")
     self.collections = [
         ("physical_modes",
          NonNullList(fields.Nested(physical_mode,
                                    display_null=False))),
         ("pagination", PbField(pagination)), ("error", PbField(error)),
         ("disruptions",
          fields.List(NonNullNested(disruption_marshaller),
                      attribute="impacts")),
         ("feed_publishers",
          NonNullList(fields.Nested(feed_publisher,
                                    display_null=False)))
     ]
     if current_app.config.get('USE_SERPY', False):
         collections = serialize_with(api.PhysicalModesSerializer)
     else:
         collections = marshal_with(OrderedDict(self.collections),
                                    display_null=False)
     self.method_decorators.insert(1, collections)
Beispiel #13
0
class ActorDetailResource(Resource):
    method_decorators = [marshal_with(actor_fields), auth_to_modify]

    def get(self, actor_id):
        return Actor.query.get_or_404(actor_id)

    def delete(self, actor_id):
        actor = Actor.query.get(actor_id)
        if actor:
            db.session.delete(actor)
            db.session.commit()
        return '', 204

    def put(self, actor_id):
        args = actor_parser.parse_args()
        actor = Actor.query.get(actor_id)
        if not actor:
            actor = Actor(id=actor_id)
            db.session.add(actor)
        actor.name = args['name']
        db.session.commit()
        return actor
Beispiel #14
0
 def __init__(self):
     Uri.__init__(self, is_collection, "line_groups")
     self.collections = [
         ("line_groups",
          NonNullList(fields.Nested(line_group, display_null=False))),
         ("pagination", PbField(pagination)),
         ("error", PbField(error)),
         ("disruptions",
          fields.List(NonNullNested(disruption_marshaller),
                      attribute="impacts")),
     ]
     if current_app.config.get('USE_SERPY', False):
         collections = serialize_with(api.LineGroupsSerializer)
     else:
         collections = marshal_with(OrderedDict(self.collections),
                                    display_null=False)
     self.method_decorators.insert(1, collections)
     self.parsers["get"].add_argument(
         "original_id",
         type=unicode,
         description="original uri of the object you"
         "want to query")
Beispiel #15
0
class SeriesDetailResource(Resource):
    method_decorators = [marshal_with(series_fields), auth_to_modify]

    def get(self, series_id):
        return Series.query.get_or_404(series_id)

    def delete(self, series_id):
        series = Series.query.get(series_id)
        if series:
            db.session.delete(series)
            db.session.commit()
        return '', 204

    def put(self, series_id):
        args = series_parser.parse_args()
        series = Series.query.get(series_id)
        if not series:
            series = Series(id=series_id)
            db.session.add(series)
        series.name = args['name']
        series.debut_year = args['debut_year']
        db.session.commit()
        return series
Beispiel #16
0
class CharacterDetailResource(Resource):
    method_decorators = [marshal_with(character_fields), auth_to_modify]

    def get(self, character_id):
        return Character.query.get_or_404(character_id)

    def delete(self, character_id):
        character = Character.query.get(character_id)
        if character:
            db.session.delete(character)
            db.session.commit()
        return '', 204

    def put(self, character_id):
        args = character_parser.parse_args()
        character = Character.query.get(character_id)
        if not character:
            character = Character(id=character_id)
            db.session.add(character)
        character.name = args['name']
        character.actor_id = args['actor_id']
        character.series_id = args['series_id']
        db.session.commit()
        return character
Beispiel #17
0
def get_serializer(serpy, marshall):
    if jormungandr.USE_SERPY:
        return serialize_with(serpy)
    else:
        return marshal_with(OrderedDict(marshall), display_null=False)
Beispiel #18
0
 def wrapper(func):
     doc = {'model': [fields]} if as_list else {'model': fields}
     doc['default_code'] = code
     func.__apidoc__ = merge(getattr(func, '__apidoc__', {}), doc)
     return restful.marshal_with(fields, **kwargs)(func)
Beispiel #19
0
 def wrapper(func):
     doc = {'model': [fields]} if as_list else {'model': fields}
     doc['default_code'] = code
     func.__apidoc__ = merge(getattr(func, '__apidoc__', {}), doc)
     return restful.marshal_with(fields, **kwargs)(func)
Beispiel #20
0
 def wrapper(func):
     doc = {'model': [fields]} if as_list else {'model': fields}
     func.__apidoc__ = merge(getattr(func, '__apidoc__', {}), doc)
     return restful.marshal_with(fields)(func)