class UserService(object): def __init__(self): self.ulity = Ulity() def isLogin(self, session_id): session_set = Session.objects.filter(SESSION_ID=session_id) if len(session_set) == 0: return Constant.ERROR_LOGIN_NOLOGIN return session_set[0].SESSION_NAME def login(self, userid, password): user_set_exists = User.objects.filter(USER_ID=userid) if len(user_set_exists) == 0: return Constant.ERROR_LOGIN_NOEXISTS password = self.ulity.encodeMd5(password) user_set_correct = User.objects.filter(USER_ID=userid, USER_PASSWORD=password) if len(user_set_correct) == 0: return Constant.ERROR_LOGIN_INCORRECT return Constant.SUCCESS_LOGIN def register(self, user): user_set = User.objects.filter(USER_ID=user.USER_ID) if len(user_set) != 0: return Constant.ERROR_REGISTER_EXISTS try: user.USER_PASSWORD = self.ulity.encodeMd5(user.USER_PASSWORD) user.save() return Constant.SUCCESS_REGISTER except Exception, e: return Constant.REGISTER + str(e)
def __init__(self): self.uservice = UserService() self.ulity = Ulity() self.musicservice = MusicService()
class MusicControler(object): def __init__(self): self.uservice = UserService() self.ulity = Ulity() self.musicservice = MusicService() @csrf_exempt def createMusicControler(self, request): if request.method == 'POST': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_CREATEMUSICLIST return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) req = simplejson.loads(request.body) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_CREATEMUSICLIST response['data'] = {} response['data']['error'] = is_login else: music = Music(MUSIC_NAME=is_login, MUSIC_LIST=','.join(req["musicname"])) create_musiclist_message = self.musicservice.createMusicList(music) if create_musiclist_message != Constant.SUCCESS_CREATEMUSICLIST: response["message"] = Constant.FAIL_CREATEMUSICLIST response["data"] = {} response["data"]["error"] = create_musiclist_message else: response["message"] = Constant.SUCCESS_CREATEMUSICLIST response["musicid"] = music.MUSIC_ID status = 200 return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def deleteMusicControler(self, request): if request.method == 'DELETE': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_DELETEMUSICLIST return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) req = simplejson.loads(request.body) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_DELETEMUSICLIST response['data'] = {} response['data']['error'] = is_login else: music_id = req["musicid"] delete_musiclist_message = self.musicservice.deleteMusicList(music_id, is_login) if delete_musiclist_message != Constant.SUCCESS_DELETEMUSICLIST: response["message"] = Constant.FAIL_DELETEMUSICLIST response["data"] = {} response["data"]["error"] = delete_musiclist_message else: response["message"] = Constant.SUCCESS_DELETEMUSICLIST status = 200 return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def updateMusicControler(self, request): if request.method == 'PUT': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_UPDATEMUSICLIST return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) req = simplejson.loads(request.body) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_UPDATEMUSICLIST response['data'] = {} response['data']['error'] = is_login else: music = Music(MUSIC_ID=req["musicid"],MUSIC_NAME=is_login, MUSIC_LIST=','.join(req["musicname"])) update_musiclist_message = self.musicservice.updateMusicList(music) if update_musiclist_message != Constant.SUCCESS_UPDATEMUSICLIST: response["message"] = Constant.FAIL_UPDATEMUSICLIST response["data"] = {} response["data"]["error"] = update_musiclist_message else: response["message"] = Constant.SUCCESS_UPDATEMUSICLIST response["musicid"] = music.MUSIC_ID status = 200 return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def getAllMusicControler(self, request): if request.method == 'GET': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_GETMUSICLIST return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_GETMUSICLIST response['data'] = {} response['data']['error'] = is_login else: [get_musiclist_message,music_set] = self.musicservice.getMusciList(is_login) if music_set is not None: for music in music_set: music_json = {} music_json["musicid"] = music.MUSIC_ID music_json["musicname"] = music.MUSIC_LIST music_json["musicuser"] = music.MUSIC_NAME response[music.MUSIC_ID] = music_json status = 200 else: response['message'] = Constant.FAIL_GETMUSICLIST response['data'] = {} response['data']['error'] = get_musiclist_message return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def difMethodMusicControler(self, request): if request.method == 'PUT': return self.updateMusicControler(request) if request.method == 'DELETE': return self.deleteMusicControler(request) if request.method == 'POST': return self.createMusicControler(request) if request.method == 'GET': return self.getAllMusicControler(request)
def __init__(self): self.ulity = Ulity()
def __init__(self): self.uservice = UserService() self.ulity = Ulity() self.articleservice = ArticleService()
class ArticleControler: def __init__(self): self.uservice = UserService() self.ulity = Ulity() self.articleservice = ArticleService() @csrf_exempt def createArticleControler(self, request): if request.method == 'POST': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_CREATEARTICLE return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) req = simplejson.loads(request.body) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_CREATEARTICLE response['data'] = {} response['data']['error'] = is_login else: article = Article(ARTICLE_TITLE=req["title"], ARTICLE_AUTHOR=is_login, ARTICLE_CONTENT=req["content"]) create_article_message = self.articleservice.createArticle(article) if create_article_message != Constant.SUCCESS_CREATEARTICLE: response["message"] = Constant.FAIL_CREATEARTICLE response["data"] = {} response["data"]["error"] = create_article_message else: response["message"] = Constant.SUCCESS_CREATEARTICLE response["articleid"] = article.ARTICLE_ID status = 200 return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def deleteArticleControler(self, request): if request.method == 'DELETE': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_DELETEARTICLE return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) req = simplejson.loads(request.body) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_DELETEARTICLE response['data'] = {} response['data']['error'] = is_login else: article_id = req["articleid"] delete_article_message = self.articleservice.deleteArticle(article_id, is_login) if delete_article_message != Constant.SUCCESS_DELETEARTICLE: response["message"] = Constant.FAIL_DELETEARTICLE response["data"] = {} response["data"]["error"] = delete_article_message else: response["message"] = Constant.SUCCESS_DELETEARTICLE status = 200 return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt # def updateArticleControler(self, request): # if request.method == 'PUT': # [sessionid, response] = self.ulity.isEmptySession(request.session) # if sessionid == None: # response["message"] = Constant.FAIL_UPDATEARTICLE # return HttpResponse(simplejson.dumps(response)) # is_login = self.uservice.isLogin(sessionid) # req = simplejson.loads(request.body) # if is_login == Constant.ERROR_LOGIN_NOLOGIN: # response['message'] = Constant.FAIL_UPDATEARTICLE # response['data'] = {} # response['data']['error'] = is_login # else: # article = Article(ARTICLE_TITLE=req["title"], ARTICLE_AUTHOR=is_login, ARTICLE_CONTENT=req["content"]) # update_article_message = self.articleservice.updateArticle(article) # if update_article_message != Constant.SUCCESS_UPDATEPLAN: # response["message"] = Constant.FAIL_UPDATEARTICLE # response["data"] = {} # response["data"]["error"] = update_article_message # else: # response["message"] = Constant.SUCCESS_UPDATEARTICLE # response["planid"] = article.ARTICLE_ID # return HttpResponse(simplejson.dumps(response)) @csrf_exempt def getAllArticleControler(self, request): if request.method == 'GET': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_GETALLARTICLE return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_GETALLARTICLE response['data'] = {} response['data']['error'] = is_login else: [get_allarticle_message, article_set] = self.articleservice.getAllArticle(is_login) if article_set is not None: for article in article_set: article_json = {} article_json["articleid"] = article.ARTICLE_ID article_json["title"] = article.ARTICLE_TITLE article_json["author"] = article.ARTICLE_AUTHOR article_json["addtime"] = article.ADD_DATETIME.strftime('%Y-%m-%d %H:%M') response[article.ARTICLE_ID] = article_json status = 200 else: response['message'] = Constant.FAIL_GETALLARTICLE response['data'] = {} response['data']['error'] = get_allarticle_message return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def difMethodArticleControler(self, request): # if request.method == 'PUT': # return self.updateArticleControler(request) if request.method == 'DELETE': return self.deleteArticleControler(request) if request.method == 'POST': return self.createArticleControler(request) if request.method == 'GET': return self.getAllArticleControler(request)
def __init__(self): self.uservice = UserService() self.ulity = Ulity() self.commentservice = CommentsService()
class CommentControler(object): def __init__(self): self.uservice = UserService() self.ulity = Ulity() self.commentservice = CommentsService() @csrf_exempt def createCommentControler(self, request): if request.method == 'POST': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_CREATECOMMENT return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) req = simplejson.loads(request.body) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_CREATECOMMENT response['data'] = {} response['data']['error'] = is_login else: comment = Comment(ARTICLE_ID=req["articleid"], COMMENT_AUTHOR=is_login, COMMENT_CONTENT=req["content"]) create_comment_message = self.commentservice.createComment( comment) if create_comment_message != Constant.SUCCESS_CREATECOMMENT: response["message"] = Constant.FAIL_CREATECOMMENT response["data"] = {} response["data"]["error"] = create_comment_message else: response["message"] = Constant.SUCCESS_CREATECOMMENT response["commentid"] = comment.COMMENT_ID status = 200 return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def deleteCommentControler(self, request): if request.method == 'DELETE': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_DELETECOMMENT return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) req = simplejson.loads(request.body) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_DELETECOMMENT response['data'] = {} response['data']['error'] = is_login else: delete_comment_message = self.commentservice.deleteComment( req["commentid"], req["articleid"], is_login) if delete_comment_message != Constant.SUCCESS_DELETECOMMENT: response["message"] = Constant.FAIL_DELETECOMMENT response["data"] = {} response["data"]["error"] = delete_comment_message else: response["message"] = Constant.SUCCESS_DELETECOMMENT status = 200 return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def getAllCommentControler(self, request): if request.method == 'GET': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_GETALLCOMMENTS return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_GETALLCOMMENTS response['data'] = {} response['data']['error'] = is_login else: [get_allcomment_message, comment_set] = self.commentservice.getAllComment( request.GET.get("articleid")) if comment_set is not None: for comment in comment_set: comment_json = {} comment_json["commentid"] = comment.COMMENT_ID comment_json["articleid"] = comment.ARTICLE_ID comment_json["author"] = comment.COMMENT_AUTHOR comment_json["content"] = comment.COMMENT_CONTENT comment_json[ "addtime"] = comment.ADD_DATETIME.strftime( '%Y-%m-%d %H:%M') response[comment.COMMENT_ID] = comment_json status = 200 else: response['message'] = Constant.FAIL_GETALLCOMMENTS response['data'] = {} response['data']['error'] = get_allcomment_message return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def difMethodCommentControler(self, request): if request.method == 'DELETE': return self.deleteCommentControler(request) if request.method == 'POST': return self.createCommentControler(request) if request.method == 'GET': return self.getAllCommentControler(request)
def __init__(self): self.uservice = UserService() self.ulity = Ulity() self.planservice = PlanService()
class PlanControler(object): def __init__(self): self.uservice = UserService() self.ulity = Ulity() self.planservice = PlanService() @csrf_exempt def createPlanControler(self, request): if request.method == 'POST': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_CREATEPLAN return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) req = simplejson.loads(request.body) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_CREATEPLAN response['data'] = {} response['data']['error'] = is_login else: partner = req["partner"] partner_str = ','.join(partner) plan = Plan(PLAN_USER=is_login, PLAN_NAME=req["planname"], RUN_DATETIME=datetime.datetime.strptime( req["runtime"], '%Y-%m-%d %H:%M'), PARTNER=partner_str, PLACE=req["place"]) create_plan_message = self.planservice.createPlan(plan) if create_plan_message != Constant.SUCCESS_CREATEPLAN: response["message"] = Constant.FAIL_CREATEPLAN response["data"] = {} response["data"]["error"] = create_plan_message else: response["message"] = Constant.SUCCESS_CREATEPLAN response["planid"] = plan.PLAN_ID status = 200 return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def deletePlanControler(self, request): if request.method == 'DELETE': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_DELETEPLAN return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) req = simplejson.loads(request.body) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_DELETEPLAN response['data'] = {} response['data']['error'] = is_login else: plan_id = req["planid"] delete_plan_message = self.planservice.deletePlan( plan_id, is_login) if delete_plan_message != Constant.SUCCESS_DELETEPLAN: response["message"] = Constant.FAIL_DELETEPLAN response["data"] = {} response["data"]["error"] = delete_plan_message else: response["message"] = Constant.SUCCESS_DELETEPLAN status = 200 return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def updatePlanControler(self, request): if request.method == 'PUT': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_UPDATEPLAN return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) req = simplejson.loads(request.body) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_UPDATEPLAN response['data'] = {} response['data']['error'] = is_login else: partner = req["partner"] partner_str = ','.join(partner) plan = Plan(PLAN_ID=req["planid"], PLAN_USER=is_login, PLAN_NAME=req["planname"], RUN_DATETIME=datetime.datetime.strptime( req["runtime"], '%Y-%m-%d %H:%M'), PARTNER=partner_str, PLACE=req["place"]) update_plan_message = self.planservice.updatePlan(plan) if update_plan_message != Constant.SUCCESS_UPDATEPLAN: response["message"] = Constant.FAIL_UPDATEPLAN response["data"] = {} response["data"]["error"] = update_plan_message else: response["message"] = Constant.SUCCESS_UPDATEPLAN response["planid"] = plan.PLAN_ID status = 200 return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def getAllPlanControler(self, request): if request.method == 'GET': status = 200 [sessionid, response] = self.ulity.isEmptySession(request.session) if sessionid == None: response["message"] = Constant.FAIL_GETALLPLANS return HttpResponse(content=simplejson.dumps(response), status=status) is_login = self.uservice.isLogin(sessionid) if is_login == Constant.ERROR_LOGIN_NOLOGIN: response['message'] = Constant.FAIL_GETALLPLANS response['data'] = {} response['data']['error'] = is_login else: [get_allplan_message, plan_set] = self.planservice.getAllPlans(is_login) if plan_set is not None: for plan in plan_set: plan_json = {} plan_json["planid"] = plan.PLAN_ID plan_json["planname"] = plan.PLAN_NAME plan_json["author"] = plan.PLAN_NAME plan_json["runtime"] = plan.RUN_DATETIME.strftime( '%Y-%m-%d %H:%M') plan_json["partner"] = plan.PARTNER.split(',') plan_json["place"] = plan.PLACE plan_json["addtime"] = plan.ADD_DATETIME.strftime( '%Y-%m-%d %H:%M') response[plan.PLAN_ID] = plan_json status = 200 else: response['message'] = Constant.FAIL_GETALLPLANS response['data'] = {} response['data']['error'] = get_allplan_message return HttpResponse(content=simplejson.dumps(response), status=status) @csrf_exempt def difMethodPlanControler(self, request): if request.method == 'PUT': return self.updatePlanControler(request) if request.method == 'DELETE': return self.deletePlanControler(request) if request.method == 'POST': return self.createPlanControler(request) if request.method == 'GET': return self.getAllPlanControler(request)