def search_result(request): book_name = request.GET['book_name'] bookApi = NaverOpenApiBook() start = 1 pageRowCnt = 10 if request.GET.has_key('curPage'): if int(request.GET['curPage']) > 0: curPage = int(request.GET['curPage']) start = (curPage * pageRowCnt) + 1 resBody = bookApi.searchBaseInfo(book_name, start) rss = objectify.XML(resBody) total_row_cnt = rss.channel.total.text if total_row_cnt > 1000: total_row_cnt = 1000 pageNavigation = PageNavigation(request, total_row_cnt) return render_to_response('book/book_search_result.html', { 'rss' : rss, 'cur_page' : pageNavigation.curPage, 'page_navigation_max_cnt' : pageNavigation.pageNavigationMaxCnt, 'page_row_cnt' : pageNavigation.pageRowCnt, 'page_navigation_html' : pageNavigation.pageNavigationHtml, 'book_list_total_row_cnt' : total_row_cnt, }, context_instance = RequestContext(request));
def search_result(request): book_name = request.GET['book_name'] bookApi = NaverOpenApiBook() start = 1 pageRowCnt = 10 if request.GET.has_key('curPage'): if int(request.GET['curPage']) > 0: curPage = int(request.GET['curPage']) start = (curPage * pageRowCnt) + 1 resBody = bookApi.searchBaseInfo(book_name, start) rss = objectify.XML(resBody) total_row_cnt = rss.channel.total.text if total_row_cnt > 1000: total_row_cnt = 1000 pageNavigation = PageNavigation(request, total_row_cnt) return render_to_response('book/book_search_result.html', { 'rss': rss, 'cur_page': pageNavigation.curPage, 'page_navigation_max_cnt': pageNavigation.pageNavigationMaxCnt, 'page_row_cnt': pageNavigation.pageRowCnt, 'page_navigation_html': pageNavigation.pageNavigationHtml, 'book_list_total_row_cnt': total_row_cnt, }, context_instance=RequestContext(request))
def insert(request): bookApi = NaverOpenApiBook() resBody = bookApi.searchDetailForNaver(request.POST['link']) bSoup = BeautifulSoup(resBody, "html.parser") bookInfoInner = bSoup.find('div', class_='book_info_inner') total_score = bookInfoInner.find( 'div', class_='txt_desc').find('strong').get_text().replace(u'점', '') total_page = 0 emList = bookInfoInner.findAll('em') for emInfo in emList: if unicode(emInfo.get_text().strip()).find(u'페이지') > -1: total_page = emInfo.next_sibling.strip() resBody = bookApi.searchDetailInfo(request.POST['query'], request.POST['isbn'].split(' ')[1]) rss = objectify.XML(resBody) bookFormData = { 'user_score': total_score, 'current_page': 0, 'total_page': total_page, 'isbn': unicode(rss.channel.item[0].isbn).split(' ')[1], 'book_name': unicode(rss.channel.item[0].title), 'author': unicode(rss.channel.item[0].author), 'publisher': unicode(rss.channel.item[0].publisher), 'pub_date': unicode(rss.channel.item[0].pubdate), 'image_url': rss.channel.item[0].image, 'link_naver': rss.channel.item[0].link, 'user': request.session.get('id') } bookForm = BookForm(bookFormData) if bookForm.is_valid(): bookForm.save() else: print bookForm.errors return HttpResponse( '<script>alert("폼 유효성 검사 실패!");history.back();</script>') return HttpResponseRedirect("/book/book_list")
def insert(request): bookApi = NaverOpenApiBook() resBody = bookApi.searchDetailForNaver(request.POST['link']); bSoup = BeautifulSoup(resBody, "html.parser") bookInfoInner = bSoup.find('div', class_='book_info_inner') total_score = bookInfoInner.find('div', class_='txt_desc').find('strong').get_text().replace(u'점', '') total_page = 0 emList = bookInfoInner.findAll('em') for emInfo in emList : if unicode(emInfo.get_text().strip()).find(u'페이지') > -1 : total_page = emInfo.next_sibling.strip() resBody = bookApi.searchDetailInfo(request.POST['query'], request.POST['isbn'].split(' ')[1]) rss = objectify.XML(resBody) bookFormData = { 'user_score' : total_score, 'current_page' : 0, 'total_page' : total_page, 'isbn' : unicode(rss.channel.item[0].isbn).split(' ')[1], 'book_name' : unicode(rss.channel.item[0].title), 'author' : unicode(rss.channel.item[0].author), 'publisher' : unicode(rss.channel.item[0].publisher), 'pub_date' : unicode(rss.channel.item[0].pubdate), 'image_url' : rss.channel.item[0].image, 'link_naver' : rss.channel.item[0].link, 'user' : request.session.get('id') } bookForm = BookForm(bookFormData) if bookForm.is_valid() : bookForm.save() else : print bookForm.errors return HttpResponse('<script>alert("폼 유효성 검사 실패!");history.back();</script>') return HttpResponseRedirect("/book/book_list")