def articles_delete(request, oauth_params, board_id=None, article_id=None): r""" **/articles/delete/<board_id>/<article_id>** 게시물을 삭제 method * DELETE * oauth required note * 사진게시판 및 익명게시판은 지원하지 않음 * 인증된 사용자 본인의 게시물만 삭제 가능 example * request (oauth 인증 관련 parameter는 예제에서 생략) .. parsed-literal:: DELETE /articles/delete/board_test/20 HTTP/1.1 * response (success case) .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "status": "ok" } """ try: oauth_token = oauth_params["oauth_token"] except KeyError as e: raise AuthError(e) if board_id.startswith("photo"): raise NotImplementedYet("사진게시판 게시물 삭제 기능은 지원하지 않습니다.") if board_id == "board_anonymous": raise NotImplementedYet("익명게시판 게시물 삭제 기능은 지원하지 않습니다.") user_id = Token.get_user_id(oauth_token) Article.delete(board_id, article_id, user_id) ret = dumps({"status": "ok"}) return HttpResponse(ret, content_type="application/json")
def articles_delete(request, oauth_params, board_id=None, article_id=None): r""" **/articles/delete/<board_id>/<article_id>** 게시물을 삭제 method * DELETE * oauth required note * 사진게시판 및 익명게시판은 지원하지 않음 * 인증된 사용자 본인의 게시물만 삭제 가능 example * request (oauth 인증 관련 parameter는 예제에서 생략) .. parsed-literal:: DELETE /articles/delete/board_test/20 HTTP/1.1 * response (success case) .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "status": "ok" } """ try: oauth_token = oauth_params['oauth_token'] except KeyError as e: raise AuthError(e) if board_id.startswith('photo'): raise NotImplementedYet('사진게시판 게시물 삭제 기능은 지원하지 않습니다.') if board_id == 'board_anonymous': raise NotImplementedYet('익명게시판 게시물 삭제 기능은 지원하지 않습니다.') user_id = Token.get_user_id(oauth_token) Article.delete(board_id, article_id, user_id) ret = dumps({'status': 'ok'}) return HttpResponse(ret, content_type='application/json')
def articles_update(request, oauth_params, board_id=None, article_id=None): r""" **/articles/update/<board_id>/<article_id>** 게시물을 수정 method * POST * oauth required parameters * **title** (필수) * **message** (필수) note * 사진게시판 및 익명게시판은 지원하지 않는다. example * request (oauth 인증 관련 parameter는 예제에서 생략) .. parsed-literal:: POST /articles/update/board_alumni99/3598 HTTP/1.1 Host: api.caucse.net Content-Type: application/x-www-form-urlencoded title=...&message=... * response .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "status": "ok", "article": { "board_id": "board_alumni99", "hits": 0, "total_comments": 0, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" }, "title": "title!!!", "comments": [], "content": "message changed!!!!!", "reg_date": "2011-01-20T09:21:18", "file": "", "id": 3598 } } """ if not board_id: board_id = request.POST["board_id"] if not article_id: article_id = request.POST["article_id"] title = request.POST["title"] message = request.POST["message"] oauth_token = oauth_params["oauth_token"] user_id = Token.get_user_id(oauth_token) if board_id.startswith("photo"): raise NotImplementedYet("사진게시판 게시 기능은 지원하지 않습니다.") if board_id == "board_anonymous": raise NotImplemented("익명게시판 게시 기능은 지원하지 않습니다.") article = Article.update(board_id=board_id, article_id=article_id, user_id=user_id, title=title, message=message) # return result ret = dumps({"status": "ok", "article": article}) return HttpResponse(ret, content_type="application/json")
def articles_show(request, oauth_params, board_id=None, article_id=None): r""" **/articles/show/<board_id>/<article_id>** 게시물 및 게시물에 달린 커멘트의 내용을 반환 method * GET * oauth required example * response (oauth 인증 관련 parameter는 예제에서 생략) .. parsed-literal:: GET /articles/show/board_test/100 HTTP/1.1 * response .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "board_id": "board_alumni99", "hits": 28, "total_comments": 3, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" }, "title": "RE : 수학여행!!!", "comments": [ { "board_id": "board_alumni99", "content": "커멘트 테스트 하는 중....", "reg_date": "2011-01-19", "id": 17253, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" } }, { "board_id": "board_alumni99", "content": "커멘트 테스트 하는 중....", "reg_date": "2011-01-19", "id": 17254, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" } }, { "board_id": "board_alumni99", "content": "커멘트 테스트 하는 중....", "reg_date": "2011-01-19", "id": 17255, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" } } ], "content": "수학여행 가자고~~", "reg_date": "2001-04-05T22:55:23", "file": "", "id": 100 } """ if not board_id: board_id = request.GET["board_id"] if not article_id: article_id = int(request.GET["article_id"]) oauth_token = oauth_params["oauth_token"] user_id = Token.get_user_id(oauth_token) article = Article.get(board_id, article_id, user_id) ret = dumps(article) return HttpResponse(ret, content_type="application/json")
def articles_create(request, oauth_params, board_id=None): r""" **/articles/create/<board_id>** 게시물을 등록 method * POST * oauth required parameters * **title** (필수) * **message** (필수) note * 사진게시판 및 익명게시판은 지원하지 않는다. example * request (oauth 인증 관련 parameter는 예제에서 생략) .. parsed-literal:: POST /articles/create/board_test HTTP/1.1 Host: api.caucse.net Content-Type: application/x-www-form-urlencoded title=...&message=... * response (success case) .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "status": "ok", "article": { "board_id": "board_alumni99", "hits": 0, "total_comments": 0, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" }, "title": "title", "comments": [], "content": "message 한글 메시지 테스트.", "reg_date": "2011-01-20T09:16:13.394124", "file": "", "id": 3591 } } * response (failure case) .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "status": "error", "message": "사진게시판 게시 기능은 지원하지 않습니다.", "type": "<type 'exceptions.NotImplementedError'>" } """ try: if not board_id: board_id = request.POST["board_id"] title = request.POST["title"] message = request.POST["message"] except KeyError as e: raise RequiredParameterDoesNotExist(e) oauth_token = oauth_params["oauth_token"] if board_id.startswith("photo"): raise NotImplementedYet("사진게시판 게시 기능은 지원하지 않습니다.") if board_id == "board_anonymous": raise NotImplementedYet("익명게시판 게시 기능은 지원하지 않습니다.") user_id = Token.get_user_id(oauth_token) article = Article.post(board_id=board_id, user_id=user_id, title=title, message=message) # return result ret = dumps({"status": "ok", "article": article}) return HttpResponse(ret, content_type="application/json")
def articles_list(request, oauth_params, board_id=None): r""" **/articles/list/<board_id>** 게시물의 리스트와 질의 조건를 반환 method * GET * oauth required parameters * page (default=0): 0 부터 count * per_page (default=20): 한 페이지에 조회할 게시물 갯수 * q (default=""): 제목, 내용, 이름, id 를 검색할 검색어 example * request (oauth parameter는 예제에서 생략) .. parsed-literal:: GET /articles/list/board_test?page=2&per_page=15&q=... HTTP/1.1 * response .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "articles": [ { "board_id": "board_alumni99", "hits": 0, "total_comments": 0, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" }, "title": "title", "comments": [], "content": "message 한글 메시지 테스트.", "reg_date": "2011-01-20T09:21:17", "file": "", "id": 3595 }, ... { "board_id": "board_alumni99", "hits": 0, "total_comments": 0, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" }, "title": "title!!!", "comments": [], "content": "message changed!!!!!", "reg_date": "2011-01-20T09:12:08", "file": "", "id": 3574 } ], "listinfo": { "board_id": "board_alumni99", "board_title": "99학번 게시판", "total_articles": 3382, "total_pages": 169, "total_matched_articles": 3382, "q": "", "per_page": 20, "page": 0 } } """ page = 0 per_page = 20 q = "" # get request parameter try: if not board_id: board_id = request.GET["board_id"] except KeyError as e: raise RequiredParameterDoesNotExist(e) if request.GET.has_key("page"): page = int(request.GET["page"]) if request.GET.has_key("per_page"): per_page = int(request.GET["per_page"]) if request.GET.has_key("q"): q = request.GET["q"] oauth_token = oauth_params["oauth_token"] user_id = Token.get_user_id(oauth_token) # make json object to return listinfo, articles = Article.get_list(board_id, user_id, page, per_page, q) ret_item = {"listinfo": listinfo, "articles": articles} ret = dumps(ret_item) return HttpResponse(ret, content_type="application/json")
def articles_update(request, oauth_params, board_id=None, article_id=None): r""" **/articles/update/<board_id>/<article_id>** 게시물을 수정 method * POST * oauth required parameters * **title** (필수) * **message** (필수) note * 사진게시판 및 익명게시판은 지원하지 않는다. example * request (oauth 인증 관련 parameter는 예제에서 생략) .. parsed-literal:: POST /articles/update/board_alumni99/3598 HTTP/1.1 Host: api.caucse.net Content-Type: application/x-www-form-urlencoded title=...&message=... * response .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "status": "ok", "article": { "board_id": "board_alumni99", "hits": 0, "total_comments": 0, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" }, "title": "title!!!", "comments": [], "content": "message changed!!!!!", "reg_date": "2011-01-20T09:21:18", "file": "", "id": 3598 } } """ if not board_id: board_id = request.POST['board_id'] if not article_id: article_id = request.POST['article_id'] title = request.POST['title'] message = request.POST['message'] oauth_token = oauth_params['oauth_token'] user_id = Token.get_user_id(oauth_token) if board_id.startswith('photo'): raise NotImplementedYet('사진게시판 게시 기능은 지원하지 않습니다.') if board_id == 'board_anonymous': raise NotImplemented('익명게시판 게시 기능은 지원하지 않습니다.') article = Article.update(board_id=board_id, article_id=article_id, user_id=user_id, title=title, message=message) # return result ret = dumps({'status': 'ok', 'article': article}) return HttpResponse(ret, content_type='application/json')
def articles_show(request, oauth_params, board_id=None, article_id=None): r""" **/articles/show/<board_id>/<article_id>** 게시물 및 게시물에 달린 커멘트의 내용을 반환 method * GET * oauth required example * response (oauth 인증 관련 parameter는 예제에서 생략) .. parsed-literal:: GET /articles/show/board_test/100 HTTP/1.1 * response .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "board_id": "board_alumni99", "hits": 28, "total_comments": 3, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" }, "title": "RE : 수학여행!!!", "comments": [ { "board_id": "board_alumni99", "content": "커멘트 테스트 하는 중....", "reg_date": "2011-01-19", "id": 17253, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" } }, { "board_id": "board_alumni99", "content": "커멘트 테스트 하는 중....", "reg_date": "2011-01-19", "id": 17254, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" } }, { "board_id": "board_alumni99", "content": "커멘트 테스트 하는 중....", "reg_date": "2011-01-19", "id": 17255, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" } } ], "content": "수학여행 가자고~~", "reg_date": "2001-04-05T22:55:23", "file": "", "id": 100 } """ if not board_id: board_id = request.GET['board_id'] if not article_id: article_id = int(request.GET['article_id']) oauth_token = oauth_params['oauth_token'] user_id = Token.get_user_id(oauth_token) article = Article.get(board_id, article_id, user_id) ret = dumps(article) return HttpResponse(ret, content_type='application/json')
def articles_create(request, oauth_params, board_id=None): r""" **/articles/create/<board_id>** 게시물을 등록 method * POST * oauth required parameters * **title** (필수) * **message** (필수) note * 사진게시판 및 익명게시판은 지원하지 않는다. example * request (oauth 인증 관련 parameter는 예제에서 생략) .. parsed-literal:: POST /articles/create/board_test HTTP/1.1 Host: api.caucse.net Content-Type: application/x-www-form-urlencoded title=...&message=... * response (success case) .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "status": "ok", "article": { "board_id": "board_alumni99", "hits": 0, "total_comments": 0, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" }, "title": "title", "comments": [], "content": "message 한글 메시지 테스트.", "reg_date": "2011-01-20T09:16:13.394124", "file": "", "id": 3591 } } * response (failure case) .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "status": "error", "message": "사진게시판 게시 기능은 지원하지 않습니다.", "type": "<type 'exceptions.NotImplementedError'>" } """ try: if not board_id: board_id = request.POST['board_id'] title = request.POST['title'] message = request.POST['message'] except KeyError as e: raise RequiredParameterDoesNotExist(e) oauth_token = oauth_params['oauth_token'] if board_id.startswith('photo'): raise NotImplementedYet('사진게시판 게시 기능은 지원하지 않습니다.') if board_id == 'board_anonymous': raise NotImplementedYet('익명게시판 게시 기능은 지원하지 않습니다.') user_id = Token.get_user_id(oauth_token) article = Article.post(board_id=board_id, user_id=user_id, title=title, message=message) # return result ret = dumps({'status': 'ok', 'article': article}) return HttpResponse(ret, content_type='application/json')
def articles_list(request, oauth_params, board_id=None): r""" **/articles/list/<board_id>** 게시물의 리스트와 질의 조건를 반환 method * GET * oauth required parameters * page (default=0): 0 부터 count * per_page (default=20): 한 페이지에 조회할 게시물 갯수 * q (default=""): 제목, 내용, 이름, id 를 검색할 검색어 example * request (oauth parameter는 예제에서 생략) .. parsed-literal:: GET /articles/list/board_test?page=2&per_page=15&q=... HTTP/1.1 * response .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "articles": [ { "board_id": "board_alumni99", "hits": 0, "total_comments": 0, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" }, "title": "title", "comments": [], "content": "message 한글 메시지 테스트.", "reg_date": "2011-01-20T09:21:17", "file": "", "id": 3595 }, ... { "board_id": "board_alumni99", "hits": 0, "total_comments": 0, "author": { "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "name": "이덕준", "id": "gochi" }, "title": "title!!!", "comments": [], "content": "message changed!!!!!", "reg_date": "2011-01-20T09:12:08", "file": "", "id": 3574 } ], "listinfo": { "board_id": "board_alumni99", "board_title": "99학번 게시판", "total_articles": 3382, "total_pages": 169, "total_matched_articles": 3382, "q": "", "per_page": 20, "page": 0 } } """ page = 0 per_page = 20 q = "" # get request parameter try: if not board_id: board_id = request.GET['board_id'] except KeyError as e: raise RequiredParameterDoesNotExist(e) if request.GET.has_key('page'): page = int(request.GET['page']) if request.GET.has_key('per_page'): per_page = int(request.GET['per_page']) if request.GET.has_key('q'): q = request.GET['q'] oauth_token = oauth_params['oauth_token'] user_id = Token.get_user_id(oauth_token) # make json object to return listinfo, articles = Article.get_list(board_id, user_id, page, per_page, q) ret_item = {'listinfo': listinfo, 'articles': articles} ret = dumps(ret_item) return HttpResponse(ret, content_type='application/json')