Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
    def save_chapter_list_to_db(self, chapter_dick_list):
        """保存章节信息到数据库"""
        new_urls = self.check_chapters(chapter_dick_list)
        logging.info("即将保存《{}》的{}条新章节到数据库".format(self.book, len(new_urls)))
        need_create = []
        for index, chapter_dict in enumerate(chapter_dick_list, 0):
            chapter_title = list(chapter_dict.keys())[0]
            chapter_link = list(chapter_dict.values())[0]

            if chapter_link in new_urls:
                chapter = Chapter(
                    title=chapter_title,
                    origin_addr=chapter_link,
                    order=index,
                    book_type=self.book.book_type,
                    book_id=self.book.id,
                    number=index,
                )
                need_create.append(chapter)

            if len(need_create) >= 200:
                self.bulk_create_chapter(need_create)
                need_create = []

        self.bulk_create_chapter(need_create)
Ejemplo n.º 4
0
    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()
Ejemplo n.º 5
0
    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()
Ejemplo n.º 6
0
def save_book(book_url):
    bookInfo = download(book_url)
    chapter_list = bookInfo['chapters']
    Novel.objects.create(name=bookInfo['name'],
                         description=bookInfo['description'],
                         imgSrc=bookInfo['imgSrc'],
                         author=bookInfo['author'],
                         biqugePath=bookInfo['biqugePath'],
                         updateTime=bookInfo['updateTime'],
                         latestChapter=bookInfo['latestChapter'])
    book_id = Novel.objects.get(name=bookInfo['name']).id
    querySetList = []
    for chapter in chapter_list:
        querySetList.append(
            Chapter(novel_id_id=book_id,
                    no=chapter_list.index(chapter) + 1,
                    name=chapter['name'],
                    context_url=chapter['context_url']))
    Chapter.objects.bulk_create(querySetList)
Ejemplo n.º 7
0
def update_book(book_url):
    bookInfo = download(book_url)
    chapters = bookInfo['chapters']
    lastChapterOnSearch = chapters[-1]
    Novel_now = Novel.objects.filter(name=bookInfo['name'])  # 当前操作的小说对象
    Novel_now.update(updateTimeOnServer=timezone.now())
    novel_id = Novel_now.values('id')[0]['id']
    lastChapterOnDb = list(
        Chapter.objects.filter(novel_id=novel_id).values())[-1]
    if lastChapterOnSearch['name'] != lastChapterOnDb['name']:
        Novel_now.update(latestChapter=bookInfo['latestChapter'],
                         updateTime=bookInfo['updateTime'])
        index = lastChapterOnDb['no']
        len = chapters.__len__()
        queryList = []
        for i in range(index, len):
            queryList.append(
                Chapter(novel_id_id=novel_id,
                        no=i + 1,
                        name=chapters[i]['name'],
                        context_url=chapters[i]['context_url']))
        Chapter.objects.bulk_create(queryList)