Beispiel #1
0
def edit_post(post_id):
    data = UpdateCoursePostSchema().fill()
    post = CoursePost.get(post_id)
    post.update_self(data)
    UserBehavior.add(g.wechat_user.id, UserBehaviorType.edit_course_post,
                     dict(post_id=post_id))
    return normal_jsonify({'status': 'ok'})
Beispiel #2
0
def get_share_post_image(post_id):
    data = GetSharePostImageSchema().fill()

    path = data.get('path', 'pages/common/splash/splash')
    supply = data.get('supply', None)
    demand = data.get('demand', None)
    student_id = data.get('student_id', None)

    post = CoursePost.get(post_id)
    if not post:
        raise PostNotFoundError()
    student = Student.get(post.student_id)
    if not student:
        raise UserNotFoundError()

    supply_course_name = None
    demand_course_name = None
    supply_course = Course.get(supply) if supply else None
    demand_course = Course.get(demand) if demand else None
    if supply_course:
        supply_course_name = supply_course.name
    if demand_course:
        demand_course_name = demand_course.name

    img_io = create_share_post_image(student, path, supply_course_name,
                                     demand_course_name)
    img_io.seek(0)
    return send_file(img_io, mimetype='image/jpeg')
Beispiel #3
0
def edit_post_status(post_id):
    data = UpdateCoursePostStatusSchema().fill()
    status = PostStatus(data['status'])
    post = CoursePost.get(post_id)
    post.update_status(status)
    UserBehavior.add(g.wechat_user.id, UserBehaviorType.markdone_course_post,
                     dict(post_id=post_id, status=status.value))
    return normal_jsonify({'status': 'ok'})
Beispiel #4
0
def get_post(post_id):
    post = CoursePost.get(post_id)
    student = Student.get(g.wechat_user.id)
    if student.id != post.student_id:
        post.pv += 1
    has_viewed_contact = True if ViewRecord.gets(student.id,
                                                 post_id) else False
    UserBehavior.add(g.wechat_user.id, UserBehaviorType.view_course_post,
                     dict(post_id=post_id))
    return normal_jsonify(
        dict(post=post.dump(), has_viewed_contact=has_viewed_contact))
Beispiel #5
0
def get_my_post():
    student = Student.get(g.wechat_user.id)
    if not student:
        return normal_jsonify({}, 'Student Not Found', 404)
    data = student_schema.GetMyCoursePostSchema().fill()
    start = data.get('start', 0)
    limit = data.get('limit', 10)
    order = OrderType(data.get('order', 0))
    posts = CoursePost.gets_by_student(student.id,
                                       limit=limit,
                                       offset=start,
                                       order=order)
    return jsonify([post.dump() for post in posts])
Beispiel #6
0
def create_post():
    data = CreateCoursePostSchema().fill()
    student_id = data['student_id']
    supply = data['supply']
    demand = data['demand']
    switch = PostMobileSwitch(data['switch'])
    mobile = data['mobile']
    wechat = data['wechat']
    message = data['message']
    post = CoursePost.add(student_id, supply, demand, switch, mobile, wechat,
                          message)
    UserBehavior.add(g.wechat_user.id, UserBehaviorType.create_course_post,
                     dict(post_id=post.id))
    return normal_jsonify(post.dump())
Beispiel #7
0
def get_posts():
    data = GetCoursePostSchema().fill()
    start = data.get('start', 0)
    limit = data.get('limit', 10)
    order = OrderType(data.get('order', 0))
    supply = data.get('supply', None)
    demand = data.get('demand', None)
    closed = data.get('closed', 1)
    posts = CoursePost.gets(limit=limit,
                            offset=start,
                            order=order,
                            closed=closed,
                            supply=supply,
                            demand=demand)
    if posts:
        return normal_jsonify([post.dump() for post in posts])
    return normal_jsonify([])
Beispiel #8
0
def clear_user(id_):
    data = request.args
    pwd = data.get('pwd')
    if pwd != RAW_SALT:
        return normal_jsonify({'status': 'failed'})
    from black_market.model.user.student import Student
    from black_market.model.wechat.session import WechatSession
    from black_market.model.post.course import CoursePost
    student = Student.get(id_)
    name = student.username
    wechat_user = student.wechat_user
    wechat_session = WechatSession.get_by_open_id(wechat_user.open_id)

    posts = CoursePost.gets_by_student(student.id, limit=100, offset=0)
    for post in posts:
        post.delete()

    student.delete()
    wechat_user.delete()
    wechat_session.delete()
    return normal_jsonify({'status': 'Student %s has been removed.' % name})
Beispiel #9
0
def get_post_from_fuzzy(fuzzy_post_id):
    post_id = CoursePost.defuzzy(fuzzy_post_id)
    post = CoursePost.get(post_id)
    post.pv += 1
    return normal_jsonify(dict(post=post.share_dump()))
Beispiel #10
0
 def posts(self, limit=10, offset=0):
     from black_market.model.post.course import CoursePost
     return CoursePost.gets_by_student(self.id, limit, offset)
Beispiel #11
0
 def post(self):
     from black_market.model.post.course import CoursePost
     return CoursePost.get(self.post_id)