示例#1
0
 def post(self):
     user = get_user(username=get_jwt_identity())
     check_permissions(user, [
         CreateAvatar(),
     ])
     ret = generic_post(
         schema=AvatarSchema(),
         data=request.form,
     )
     return ret
示例#2
0
 def post(self):
     data = request.form.to_dict()
     #default avatar to be chosen
     if not 'avatar_id' in data:
         data['avatar_id'] = Avatar.query.first().avatar_id
     CreateUser(attributes=set(data.keys())).check(None)
     ret = generic_post(
         schema=UserSchema(),
         data=data,
     )
     return ret
示例#3
0
 def post(self):
     user = get_user(username=get_jwt_identity())
     check_permissions(user, [
         CreateSubforum(),
     ])
     data = request.form.to_dict()
     if not 'position' in data:
         subforum = Subforum.query.order_by(-Subforum.position).first()
         position = 1 if subforum is None else (subforum.position + 1)
         data['position'] = position
     ret = generic_post(
         schema=SubforumSchema(),
         data=data,
     )
     return ret
示例#4
0
 def post(self, subforum_id):
     subforum = get_obj(Subforum.query.filter_by(subforum_id=subforum_id),
                        'subforum does not exist')
     user = get_user(username=get_jwt_identity())
     check_permissions(user, [
         CreateTopicInSubforum(subforum),
     ])
     check_post_time_interval(user, Topic)
     #validating/updating data
     data = request.form.to_dict()
     data['user_id'] = user.user_id
     data['subforum_id'] = subforum.subforum_id
     schema = TopicSchema()
     errors = schema.validate(data)
     if errors:
         return mk_errors(400, fmt_validation_error_messages(errors))
     ret = generic_post(
         schema=schema,
         data=data,
     )
     #updating number of topics by user
     user.n_topics += 1
     user.save()
     return ret
示例#5
0
 def post(self, topic_id):
     topic = get_obj(
         Topic.query.filter_by(topic_id=topic_id), 'topic does not exist')
     user = get_user(username=get_jwt_identity())
     check_permissions(user, [
         CreatePostInTopic(topic),
     ])
     check_post_time_interval(user, Post)
     #validating/updating data
     data = request.form.to_dict()
     data['user_id'] = user.user_id
     data['topic_id'] = topic.topic_id
     schema = PostSchema()
     errors = schema.validate(data)
     if errors:
         return mk_errors(400, fmt_validation_error_messages(errors))
     ret = generic_post(
         schema=schema,
         data=data,
     )
     #updating number of posts by user
     user.n_posts += 1
     user.save()
     return ret