예제 #1
0
def db_spammer(amount, teg_list=None):

    if teg_list is None:
        teg_list = ['Science', 'Math', 'Style', 'Drugs', 'Tech', 'Linux']

    nickname = [
        'FightForDobro', 'iLikeIceCream', 'Yoda', 'Albert Hoffman',
        'Alexander Theodore Shulgin', 'Timothy Francis Leary'
    ]

    if len(User.objects().to_json()) == 2:

        for i in nickname:

            user_dict = {
                'nickname': i,
                'name': get_first_name(),
                'surname': get_last_name()
            }

            User(**user_dict).save()

    for _ in range(amount):

        teg_obj = Teg(teg_title=choice(teg_list))

        post_dict = {
            'post_title': lorem.sentence(),
            'content': lorem.paragraph(),
            'teg': teg_obj,
        }

        user = User.objects(nickname=choice(nickname)).get()

        user.create_post(**post_dict)
예제 #2
0
    def delete(self, p_id):

        user_data = request.json[0].pop('author')
        user = User.objects(id=user_data['id']).get()
        user.delete_post(p_id)

        return {'Post deleted successful': request.json[0]}
예제 #3
0
    def post(self):

        user_data = request.json[0].pop('author')
        user = User.objects(id=user_data['id']).get()
        user.create_post(**request.json[0])

        return {'Post create successful': request.json[0]}
예제 #4
0
    def get(self, nickname=None):

        if nickname:
            user = User.objects(nickname=nickname).get()
            return PostScheme().dump(Post.objects(author=user), many=True)

        objects = User.objects
        return UserScheme().dump(objects, many=True)
예제 #5
0
    def delete(self, nickname):

        obj = User.objects(nickname=nickname).get()
        obj.delete()

        return {nickname: 'DELETED'}
예제 #6
0
    def put(self, nickname):

        obj = User.objects(nickname=nickname).get()
        obj.update(**request.json)

        return UserScheme().dump(obj.reload())
예제 #7
0
    def post(self):

        obj = User(**request.json)
        obj.save()
        return UserScheme().dump(obj.reload())