Beispiel #1
0
 def get(self):
     data = GroupUser.parser.parse_args()
     group = GroupModel.find_by_name(data.group_name)
     print(group.members)
     # for u in group.members:
     #     print(u.username)
     return {'users': group.get_users()}
Beispiel #2
0
 def delete(self, name):
     group = GroupModel.find_by_name(name)
     if group:
         group.delete_from_db()
     else:
         return {'error': 'Group not found'}, 404
     return {'success': 'group deleted'}, 202
Beispiel #3
0
 def put(self, name):
     data = json.loads(request.data)
     group = GroupModel.find_by_name(name)
     if group:
         group.update(**data)
     else:
         return {'error': 'Group not found'}, 404
     return group.json(), 201
    def post(self, name):
        if GroupModel.find_by_name(name):
            return {'message': "A group with name '{}' already exists.".format(name)}, 400

        group = GroupModel(name)
        try:
            group.save_to_db()
        except Exception as e:
            return {"message": f"An error occurred: {e}"}, 500

        return group.json(), 201
Beispiel #5
0
    def post(self):
        data = Group.parser.parse_args()

        if GroupModel.find_by_name(data['name']):
            return {'message': 'Group with that name already exists.'}, 400

        group = GroupModel(data['name'], data['description'])

        group.save_to_db()

        return group.json(), 201
Beispiel #6
0
 def post(self, name=None):
     data = json.loads(request.data)
     name = data.get("name", name)
     if GroupModel.find_by_name(name):
         return {
             'error': "A group with name '{}' already exists.".format(name)
         }, 400
     group = GroupModel(**data)
     try:
         group.save_to_db()
     except:
         return {"error": "An error occurred creating the group."}, 500
     return group.json(), 201
Beispiel #7
0
    def post(cls):
        group_json = request.get_json()

        if GroupModel.find_by_name(group_json["name"]):
            return {
                "message": NAME_ALREADY_EXISTS.format(group_json["name"])
            }, 400

        group_json["created_at"] = str(datetime.utcnow())
        group_json["updated_at"] = str(datetime.utcnow())
        group = group_schema.load(group_json)

        try:
            group.save_to_db()
        except:
            return {"message": ERROR_INSERTING.format("inserting")}, 500

        return group_schema.dump(group), 201
Beispiel #8
0
    def post(self):
        user = UserModel.find_by_username(current_identity.username)

        data = GroupUser.parser.parse_args()
        group = GroupModel.find_by_name(data.group_name)

        # check if group exit in user.
        # r=1
        # for u in group.members:
        #     if u.username == user.username:
        #         r=0
        # return {'group': data.group_name, 'status': '1User already a member of this group.'}
        # if r==1:
        group.members.append(user)
        group.save_to_db()

        # checking if a user is already a member of this group.
        # for u in user.groups:
        #     if u.name == data.group_name:
        #         return {'group': data.group_name, 'status': 'User already a member of this group.'}
        user.groups.append(group)
        user.save_to_db()
        return {'group': data.group_name, 'status': 'added'}
 def delete(self, name):
     group = GroupModel.find_by_name(name)
     if group:
         group.delete_from_db()
         return {'message': 'Group deleted.'}
     return {'message': 'Group not found.'}, 404
Beispiel #10
0
 def get(self, name):
     group = GroupModel.find_by_name(name)
     if group:
         return group.json()
     return {'message': 'Group not found'}, 404
Beispiel #11
0
 def get(self, name):
     group = GroupModel.find_by_name(name)
     if group:
         # if we have found the group then return all the posts in this groups.
         return {'post': group.get_posts()}
     return {'message': 'Group not found'}, 404
Beispiel #12
0
 def get(self, name):
     group = GroupModel.find_by_name(name)
     return {'group_id': group.id}
Beispiel #13
0
 def get(self, name):
     group = GroupModel.find_by_name(name)
     if group:
         return group.childingroup()