Exemple #1
0
    def __init__(self, api_base_url, access_token=None, json_schemas=None):

        self.api_base_url = api_base_url
        self.access_token = access_token

        self.http_client = http_client.PichayonHTTPClient(
            api_base_url, access_token)

        self.json_schemas = json_schemas

        if not self.json_schemas:
            self.json_schemas = self.get_json_schemas()

        def retrieve_schema(m):
            return self.schemas['definitions'].get(
                m.__resource_class__.__resource_name__, None)

        # self.users = users.UserManager(self,
        #         json_schema=retrieve_schema(users.UserManager))
        # self.rooms = rooms.RoomManager(self,
        #         json_schema=retrieve_schema(rooms.RoomManager))

        self.users = resources.UserManager(self, schema=schemas.UserSchema())
        self.groups = resources.GroupManager(self,
                                             schema=schemas.GroupSchema())
        self.rooms = resources.RoomManager(self, schema=schemas.RoomSchema())
Exemple #2
0
def get(group_id):
    group = None

    schema = schemas.GroupSchema()
    try:
        group = models.Group.objects.get(id=group_id)
    except Exception as e:
        response_dict = request.get_json()
        response_dict.update(e.messages)
        response = render_json(response_dict)
        response.status_code = 404
        abort(response)

    return render_json(schema.dump(group).data)
Exemple #3
0
def create():
    schema = schemas.GroupSchema()

    try:
        group_data = schema.load(request.get_json()).data
    except Exception as e:
        response_dict = request.get_json()
        response_dict.update(e.messages)
        response = render_json(response_dict)
        response.status_code = 400
        abort(response)

    user = current_user._get_current_object()
    group = models.Group(user=user,
                         **group_data)
    group.save()
    return render_json(schema.dump(group).data)
Exemple #4
0
def update(group_id):
    schema = schemas.GroupSchema()

    try:
        group = models.Group.objects.get(id=group_id)
        group_data = schema.load(request.get_json()).data

        group_data.pop('id')
        group.update(**group_data)
    except Exception as e:
        response_dict = request.get_json()
        response_dict.update(e.messages)
        response = render_json(response_dict)
        response.status_code = 400
        abort(response)

    group.save()
    return render_json(schema.dump(group).data)
Exemple #5
0
def list():
    schema = schemas.GroupSchema()
    groups = models.Group.objects()
    return render_json(schema.dump(groups, many=True).data)