Esempio n. 1
0
    def post(self):
        """
        create a space
        /environment/

        :return:
        """
        super(SpaceAPI, self).post()

        form = SpaceForm(request.form, csrf_enabled=False)
        # return self.render_json(code=-1, data = form.form2dict())
        if form.validate_on_submit():
            # create space
            space_new = SpaceModel()
            data = form.form2dict()
            id = space_new.add(data)
            if not id:
                return self.render_json(code=-1)

            current_app.logger.info(request.json)
            # create group
            data['role'] = OWNER
            members = [data]
            MemberModel(group_id=id).update_group(members=members)
            return self.render_json(data=space_new.item())
        else:
            return self.render_json(code=-1, message=form.errors)
Esempio n. 2
0
    def put(self, space_id, action=None):
        """
        update environment
        /environment/<int:id>

        :return:
        """
        super(SpaceAPI, self).put()

        if action and action == 'switch':
            return self.switch(space_id)
        current_app.logger.info(json.loads(request.form['members']))
        form = SpaceForm(request.form, csrf_enabled=False)
        form.set_id(space_id)
        if form.validate_on_submit():
            space = SpaceModel().get_by_id(space_id)
            data = form.form2dict()
            current_app.logger.info(data)

            # a new type to update a model
            ret = space.update(data)
            # create group
            if 'members' in request.form:
                MemberModel(group_id=space_id).update_group(members=json.loads(request.form['members']))
            return self.render_json(data=space.item())
        else:
            return self.render_json(code=-1, message=form.errors)
Esempio n. 3
0
    def put(self, space_id, action=None):
        """
        update environment
        /environment/<int:id>

        :return:
        """
        super(SpaceAPI, self).put()

        if action and action == 'switch':
            return self.switch(space_id)
        current_app.logger.info(json.loads(request.form['members']))
        form = SpaceForm(request.form, csrf_enabled=False)
        form.set_id(space_id)
        if form.validate_on_submit():
            space = SpaceModel().get_by_id(space_id)
            data = form.form2dict()
            current_app.logger.info(data)

            # a new type to update a model
            ret = space.update(data)
            # create group
            if 'members' in request.form:
                MemberModel(group_id=space_id).update_group(members=json.loads(request.form['members']))
            return self.render_json(data=space.item())
        else:
            return self.render_json(code=-1, message=form.errors)
Esempio n. 4
0
    def post(self):
        """
        create a space
        /environment/

        :return:
        """
        super(SpaceAPI, self).post()

        form = SpaceForm(request.form, csrf_enabled=False)
        # return self.render_json(code=-1, data = form.form2dict())
        if form.validate_on_submit():
            # create space
            space_new = SpaceModel()
            data = form.form2dict()
            id = space_new.add(data)
            if not id:
                return self.render_json(code=-1)

            current_app.logger.info(request.json)
            # create group
            data['role'] = OWNER
            members = [data]
            MemberModel(group_id=id).update_group(members=members)
            return self.render_json(data=space_new.item())
        else:
            return self.render_json(code=-1, message=form.errors)
Esempio n. 5
0
    def update(self, space_id):
        form = SpaceForm(request.form, csrf=False)
        form.set_id(space_id)
        if form.validate_on_submit():
            space = SpaceModel().get_by_id(space_id)
            data = form.form2dict()
            current_app.logger.info(data)
            member_model = MemberModel(group_id=space_id)
            old_owner = space.user_id
            new_owner = data['user_id']
            # a new type to update a model
            space.update(data)

            if str(old_owner) != str(new_owner):
                # owner has changed
                member_model.change_owner(old_owner, new_owner)

            # create group
            current_owner = {"user_id": new_owner, "role": OWNER}
            if 'members' in request.form:
                members = json.loads(request.form['members'])
                members.append(current_owner)
                member_model.update_group(members=members)
            return self.render_json(data=space.item())
        else:
            return self.render_error(code=Code.form_error, message=form.errors)
Esempio n. 6
0
    def update(self, space_id):
        form = SpaceForm(request.form, csrf_enabled=False)
        form.set_id(space_id)
        if form.validate_on_submit():
            space = SpaceModel().get_by_id(space_id)
            data = form.form2dict()
            current_app.logger.info(data)

            # a new type to update a model
            ret = space.update(data)
            # create group
            if 'members' in request.form:
                MemberModel(group_id=space_id).update_group(members=json.loads(request.form['members']))
            return self.render_json(data=space.item())
        else:
            return self.render_json(code=-1, message=form.errors)
Esempio n. 7
0
    def update(self, space_id):
        form = SpaceForm(request.form, csrf=False)
        form.set_id(space_id)
        if form.validate_on_submit():
            space = SpaceModel().get_by_id(space_id)
            data = form.form2dict()
            current_app.logger.info(data)

            # a new type to update a model
            ret = space.update(data)
            # create group
            if 'members' in request.form:
                MemberModel(group_id=space_id).update_group(members=json.loads(request.form['members']))
            return self.render_json(data=space.item())
        else:
            return self.render_error(code=Code.form_error, message=form.errors)
Esempio n. 8
0
    def update(self, space_id):
        form = SpaceForm(request.form, csrf=False)
        form.set_id(space_id)
        if form.validate_on_submit():
            space = SpaceModel().get_by_id(space_id)
            data = form.form2dict()
            current_app.logger.info(data)

            # a new type to update a model
            ret = space.update(data)
            # create group
            member = {"user_id": data['user_id'], "role": OWNER}
            if 'members' in request.form:
                members = json.loads(request.form['members'])
                members.append(member)
            MemberModel(group_id=space_id).update_group(members=members)
            return self.render_json(data=space.item())
        else:
            return self.render_error(code=Code.form_error, message=form.errors)