def add_chapters(book_instance, chapters, status, this_user): for chapter in chapters: new_chapter = Chapter(book=book_instance, text_id=chapter['text'], number=chapter['number'], part=chapter['part']) new_chapter.save() # If the current user is the owner of the chapter-document, make sure # that everyone with access to the book gets at least read access. if this_user == new_chapter.text.owner: for bar in BookAccessRight.objects.filter(book=book_instance): if len(new_chapter.text.accessright_set.filter( user=bar.user)) == 0: AccessRight.objects.create( document_id=new_chapter.text.id, user_id=bar.user.id, rights='read', ) if this_user != book_instance.owner and len( new_chapter.text.accessright_set.filter( user=book_instance.owner)) == 0: AccessRight.objects.create( document_id=new_chapter.text.id, user_id=book_instance.owner.id, rights='read', ) return status
async def handler_content(self, res, chapter: Chapter): content = self.parser(res) logging.info('处理<<{}>>{},正文信息:{}...'.format(chapter.book, chapter, content[:15])) if chapter.book_type == BOOK_TYPE_DESC.Comic: imgs = [] for key in content.keys(): imgs.insert(int(key), content[key]) img_objs = await self.save_image(imgs, IMAGE_TYPE_DESC.CHAPER_CONTENT, self.headers) # 如果能获取到所有img对象则保存 if len(img_objs) and None not in img_objs: content = img_objs try: chapter.save_content(content) chapter.active = True chapter.save() except OSError: logging.error('处理<<{}>>单章节正文信息 失败 : {}'.format( chapter.book, chapter)) chapter.active = False chapter.save() pass
def update_book(request, pk): if request.method == 'POST': updatebookform = UpdateBookForm(request.POST) if updatebookform.is_valid(): chapter = Chapter() chapter.book_from = Book.objects.get(pk=pk) chapter.volume_from = updatebookform.cleaned_data['volume_from'] chapter.name = updatebookform.cleaned_data['name'] chapter.contents = updatebookform.cleaned_data['content'] word_num = float(process_chapter_num(updatebookform.cleaned_data['content'])) chapter.word_num = word_num chapter.save() signals.book_updated_signal.send( sender=chapter.__class__, chapter=chapter, book=Book.objects.get(pk=pk), ) return redirect(reverse('author:index')) else: updatebookform = UpdateBookForm() updatebookform.fields['volume_from'].queryset = Volume.objects.filter(book_from__pk=pk) context = dict() context['updatebookform'] = updatebookform context['book'] = Book.objects.get(pk=pk) return render(request, 'author_area/manage/update_book.html', context)
def handler_content(self, content, chapter: Chapter): logging.info("处理--{}--<<{}>>{},正文信息:{}...".format( self.wait_done, chapter.book, chapter, content[:10])) if chapter.book_type == BOOK_TYPE_DESC.Comic: imgs = [] for key in content.keys(): imgs.insert(int(key), content[key]) img_objs = self.save_image(imgs, IMAGE_TYPE_DESC.CHAPER_CONTENT, self.headers) # 如果能获取到所有img对象则保存 if len(img_objs) and None not in img_objs: content = img_objs try: if not content: raise OSError chapter.save_content(content) chapter.active = True chapter.save() except OSError: logging.error("处理<<{}>>单章节正文信息 失败 : {}".format( chapter.book, chapter)) chapter.active = False chapter.save() pass
def add_chapters(book_instance, chapters, status, this_user): for chapter in chapters: new_chapter = Chapter( book=book_instance, text_id=chapter["text"], number=chapter["number"], part=chapter["part"] ) new_chapter.save() # If the current user is the owner of the chapter-document, make sure that everyone with access to the book gets at least read access. if this_user == new_chapter.text.owner: for bar in BookAccessRight.objects.filter(book=book_instance): if len(new_chapter.text.accessright_set.filter(user=bar.user)) == 0: AccessRight.objects.create(text_id=new_chapter.text.id, user_id=bar.user.id, rights="r") if ( this_user != book_instance.owner and len(new_chapter.text.accessright_set.filter(user=book_instance.owner)) == 0 ): AccessRight.objects.create(text_id=new_chapter.text.id, user_id=book_instance.owner.id, rights="r") return status
def _save_all_chapter_db(self, comic, chapter_list): logger.info('_save_all_chapter_db for comic') for index, chapter_dict in enumerate(chapter_list, 0): chapter_title = list(chapter_dict.keys())[0] chapter_link = list(chapter_dict.values())[0] logger.info('{}_ -chapter-__{}'.format(chapter_title, chapter_link)) chapter_obj = Chapter.normal.filter(book=comic, book_type=BOOK_TYPE_DESC.Comic, title=chapter_title).first() if not chapter_obj: chapter_obj = Chapter() chapter_obj.comic = comic chapter_obj.title = chapter_title chapter_obj.order = index chapter_obj.origin_addr = chapter_link chapter_obj.save()
def _save_all_chapter_db(self, book, chapter_list): logger.info('_save_all_chapter_db') for index, chapter_dict in enumerate(chapter_list, 0): chapter_title = list(chapter_dict.keys())[0] chapter_link = list(chapter_dict.values())[0] logger.info('{}_ -chapter-__{}'.format(chapter_title, chapter_link)) chapter_obj = Chapter.normal.filter(book=book, title=chapter_title).first() if not chapter_obj: chapter_obj = Chapter() chapter_obj.book = book chapter_obj.title = chapter_title chapter_obj.order = index chapter_obj.origin_addr = chapter_link chapter_obj.save()
def make_chapter_public(self, request, queryset): from django.db.models import Max antal=0 for userchapter in queryset: highest_index = Chapter.objects.aggregate(Max('index')) index = highest_index['index__max']+1 chapter = Chapter(title=userchapter.title, summary=userchapter.summary, summary_html=userchapter.summary_html, body=userchapter.body, body_html=userchapter.body_html, mod_date=userchapter.pub_date, pub_date=userchapter.pub_date, index=index, author=userchapter.author, user_created=True, visible=True, picture=userchapter.picture, picture_description=userchapter.picture_description, tags_string=userchapter.tags_string) chapter.save() userchapter.delete() antal+=1 self.message_user(request, '%s successfully made public.' % antal)