示例#1
0
def delete_answer():
	try:
		comment_id = request.args.get('id', -1)
		if comment_id == -1:
			return response_error(MESSAGE.ANSWER_INVALID_INPUT, CODE.ANSWER_INVALID_INPUT)

		review = answer_bl.review_type(comment_id)
		if review is None:
			return response_error(MESSAGE.ANSWER_INVALID_INPUT, CODE.ANSWER_INVALID_INPUT)

		comment = db.session.query(Comment).filter(Comment.id==comment_id).first()
		rating = db.session.query(Rating).filter(Rating.id.in_(db.session.query(Comment.rating_id).filter(Comment.id==comment_id))).first()

		db.session.delete(comment)
		db.session.delete(rating)
	
		object_id = rating.object_id
		review_type = review.name
		if review_type == CONST.Type['People']:
			user = User.find_user_by_id(object_id)
			if user is not None:
				user.rating_count = people_bl.count_rating_for_object(user, CONST.Type['People'])
				user.comment_count = people_bl.count_comments_for_object(user, CONST.Type['People'])
				db.session.flush()

		elif review_type == CONST.Type['Team']:
			team = Team.find_team_by_id(object_id)
			if team is not None:
				team.rating_count = people_bl.count_rating_for_object(team, CONST.Type['Team'])
				team.comment_count = people_bl.count_comments_for_object(team, CONST.Type['Team'])
				db.session.flush()

		elif review_type == CONST.Type['Company']:
			company = Company.find_company_by_id(object_id)
			if company is not None:
				company.rating_count = people_bl.count_rating_for_object(company, CONST.Type['Company'])
				company.comment_count = people_bl.count_comments_for_object(company, CONST.Type['Company'])
				db.session.flush()

		db.session.commit()
		return response_ok()
	except Exception, ex:
		db.session.rollback()
		return response_error(ex.message)
示例#2
0
def update_rating_and_comment_count():
    try:
        teams = db.session.query(Team).all()
        for t in teams:
            rating_count = people_bl.count_rating_for_object(
                t, CONST.Type['Team'])
            comment_count = people_bl.count_comments_for_object(
                t, CONST.Type['Team'])

            t.comment_count = comment_count
            t.rating_count = rating_count
            db.session.flush()

        db.session.commit()
        return response_ok()
    except Exception, ex:
        db.session.rollback()
        return response_error(ex.message)
示例#3
0
def update_rating_and_comment_count():
    try:
        users = db.session.query(User).all()
        for u in users:
            rating_count = people_bl.count_rating_for_object(
                u, CONST.Type['People'])
            comment_count = people_bl.count_comments_for_object(
                u, CONST.Type['People'])

            u.comment_count = comment_count
            u.rating_count = rating_count
            db.session.flush()

        db.session.commit()
        return response_ok()
    except Exception, ex:
        db.session.rollback()
        return response_error(ex.message)
示例#4
0
def update_rating_and_comment_count():
    try:
        companies = db.session.query(Company).all()
        for c in companies:
            rating_count = people_bl.count_rating_for_object(
                c, CONST.Type['Company'])
            comment_count = people_bl.count_comments_for_object(
                c, CONST.Type['Company'])

            c.comment_count = comment_count
            c.rating_count = rating_count
            db.session.flush()

        db.session.commit()
        return response_ok()
    except Exception, ex:
        db.session.rollback()
        return response_error(ex.message)
示例#5
0
def submit_answer():
	try:
		current_user = get_jwt_identity()
		user = db.session.query(User).filter(User.email==func.binary(current_user)).first()
		if user is None:
			return response_error(MESSAGE.USER_INVALID_EMAIL, CODE.USER_INVALID_EMAIL)
		
		data = request.json
		if data is None:
			return response_error(MESSAGE.INVALID_DATA, CODE.INVALID_DATA)
			
		review_type = request.args.get('type', '')
		object_id = request.args.get('id', -1)
		
		if len(review_type) == 0 or \
			object_id == -1:
			return response_error(MESSAGE.ANSWER_INVALID_INPUT, CODE.ANSWER_INVALID_INPUT)

		result = answer_bl.is_valid_object_id(review_type, object_id)
		if result is None:
			return response_error(MESSAGE.ANSWER_INVALID_INPUT, CODE.ANSWER_INVALID_INPUT)

		rt = db.session.query(ReviewType).filter(ReviewType.name==func.binary(review_type)).first()
		ratings = data['ratings']
		if ratings is not None:
			for r in ratings:
				if answer_bl.is_answer_question(user.id, review_type, object_id, r['question_id']):
					return response_error(MESSAGE.ANSWER_QUESTION_ALREADY, CODE.ANSWER_QUESTION_ALREADY)

				rating = Rating(
					point=r['rating'],
					question_id=r['question_id'],
					object_id=object_id,
					user_id=user.id
				)
				db.session.add(rating)
				db.session.flush()

				comment = r['comment']
				if comment is not None:
					c = Comment(
						desc=comment,
						rating_id=rating.id
					)
					db.session.add(c)
					db.session.flush()

		else:
			return response_error(MESSAGE.ANSWER_INVALID_INPUT, CODE.ANSWER_INVALID_INPUT)	

		if review_type == CONST.Type['People']:
			user = User.find_user_by_id(object_id)
			if user is not None:
				user.rating_count = people_bl.count_rating_for_object(user, CONST.Type['People'])
				user.comment_count = people_bl.count_comments_for_object(user, CONST.Type['People'])
				db.session.flush()

		elif review_type == CONST.Type['Team']:
			team = Team.find_team_by_id(object_id)
			if team is not None:
				team.rating_count = people_bl.count_rating_for_object(team, CONST.Type['Team'])
				team.comment_count = people_bl.count_comments_for_object(team, CONST.Type['Team'])
				db.session.flush()

		elif review_type == CONST.Type['Company']:
			company = Company.find_company_by_id(object_id)
			if company is not None:
				company.rating_count = people_bl.count_rating_for_object(company, CONST.Type['Company'])
				company.comment_count = people_bl.count_comments_for_object(company, CONST.Type['Company'])
				db.session.flush()

		db.session.commit()
		return response_ok()
	except Exception, ex:
		db.session.rollback()
		return response_error(ex.message)