Ejemplo n.º 1
0
def edit_line(request):
    if not request.user.is_superuser:
        raise Http404

    class CheckForm(forms.Form):
        pagenum = forms.ModelChoiceField(queryset=BookPage.objects.all())
        linenum = forms.IntegerField(min_value=0)
        pageline = forms.CharField(max_length=2000)
    if request.method != "POST":
        raise HttpResponse(status_code=405)
    form = CheckForm(request.POST)
    if form.is_valid():
        import re
        new_lines = re.sub(r"\n+", '\n', form.cleaned_data["pageline"], flags=re.S).split('\n')
        page = form.cleaned_data["pagenum"]
        page_contents = BookPage.content_text(page.get_content()).split('\n')
        line_number = form.cleaned_data["linenum"]
        # # Diff信息
        # import difflib
        # content_line = page_contents[line_number]
        # dif = difflib.Differ()
        # diffline = ("\n".join(
        #     list(dif.compare(content_line.splitlines(1), form.cleaned_data["pageline"].splitlines(1)))
        # )).replace(" ", " ").replace("-", "-").replace("?", "?").replace("+", "+")
        # print diffline
        page_contents[line_number] = form.cleaned_data["pageline"]
        page_contents = page_contents[:line_number] + new_lines + page_contents[line_number + 1:]
        new_content = BookPage.content_html("\n".join(page_contents))
        page.set_content(new_content)
        return ajax_success(new_content)
    else:
        return ajax_error(form.errors.as_json())
Ejemplo n.º 2
0
def edit_line(request):
    if not request.user.is_superuser:
        raise Http404

    class CheckForm(forms.Form):
        pagenum = forms.ModelChoiceField(queryset=BookPage.objects.all())
        linenum = forms.IntegerField(min_value=0)
        pageline = forms.CharField(max_length=2000)

    if request.method != "POST":
        raise HttpResponse(status_code=405)
    form = CheckForm(request.POST)
    if form.is_valid():
        page = form.cleaned_data["pagenum"]
        page_contents = page.content.split("\n")
        line_number = form.cleaned_data["linenum"]
        for i, e in enumerate(page_contents):
            if i == line_number:
                dif = difflib.Differ()
                diffline = ("\n".join(
                    list(
                        dif.compare(
                            e.splitlines(1),
                            form.cleaned_data["pageline"].splitlines(1))))
                            ).replace(" ", " ").replace("-", "-").replace(
                                "?", "?").replace("+", "+")
                repr(diffline)
                # print diffline
                page_contents[i] = form.cleaned_data["pageline"]
        page.content = "\n".join(page_contents)
        page.save()
        return ajax_success(form.cleaned_data["pageline"])
    else:
        return ajax_error(form.errors.as_json())
Ejemplo n.º 3
0
def book_jt(request):
    bookid = request.GET['book_id']
    book = get_object_or_404(Book, id=bookid)
    jt = JingTui()
    jt.add(book)
    jt.save()
    return ajax_success()
Ejemplo n.º 4
0
def load_nall_page(request, page_id=0):
    bookpage = BookPage.objects.get(pk=page_id)
    book = Book.objects.get(is_deleted=False, book_number=bookpage.book_number)
    bookpages = []
    next_page_number = bookpage.next_number
    # 使用链式获取比排序后截取快
    for i in range(10):
        try:
            next_page = BookPage.objects.get(page_number=next_page_number)
        except:
            break
        else:
            bookpages.append(next_page)
            next_page_number = next_page.next_number

    data = render_to_string(
        'book/pagecontent.jade',
        {
            'bookpages': bookpages,
            'book': book,
            'invert': request.session.get('invert', False),
        },
        context_instance=RequestContext(request)
    )
    return ajax_success(data)
Ejemplo n.º 5
0
def edit_line(request):
    if not request.user.is_superuser:
        raise Http404

    class CheckForm(forms.Form):
        pagenum = forms.ModelChoiceField(queryset=BookPage.objects.all())
        linenum = forms.IntegerField(min_value=0)
        pageline = forms.CharField(max_length=2000)
    if request.method != "POST":
        raise HttpResponse(status_code=405)
    form = CheckForm(request.POST)
    if form.is_valid():
        import re
        new_lines = re.sub(r"\n+", '\n', form.cleaned_data["pageline"], flags=re.S).split('\n')
        page = form.cleaned_data["pagenum"]
        page_contents = BookPage.content_text(page.get_content()).split('\n')
        line_number = form.cleaned_data["linenum"]
        # # Diff信息
        # import difflib
        # content_line = page_contents[line_number]
        # dif = difflib.Differ()
        # diffline = ("\n".join(
        #     list(dif.compare(content_line.splitlines(1), form.cleaned_data["pageline"].splitlines(1)))
        # )).replace(" ", " ").replace("-", "-").replace("?", "?").replace("+", "+")
        # print diffline
        page_contents[line_number] = form.cleaned_data["pageline"]
        page_contents = page_contents[:line_number] + new_lines + page_contents[line_number + 1:]
        new_content = BookPage.content_html("\n".join(page_contents))
        page.set_content(new_content)
        return ajax_success(new_content)
    else:
        return ajax_error(form.errors.as_json())
Ejemplo n.º 6
0
def book_ft(request):
    bookid = request.GET['book_id']
    book = get_object_or_404(Book, id=bookid)
    ft = FengTui()
    ft.add(book)
    ft.save()
    return ajax_success()
Ejemplo n.º 7
0
def edit_line(request):
    if not request.user.is_superuser:
        raise Http404

    class CheckForm(forms.Form):
        pagenum = forms.ModelChoiceField(queryset=BookPage.objects.all())
        linenum = forms.IntegerField(min_value=0)
        pageline = forms.CharField(max_length=2000)
    if request.method != "POST":
        raise HttpResponse(status_code=405)
    form = CheckForm(request.POST)
    if form.is_valid():
        page = form.cleaned_data["pagenum"]
        page_contents = page.content.split("\n")
        line_number = form.cleaned_data["linenum"]
        for i, e in enumerate(page_contents):
            if i == line_number:
                dif = difflib.Differ()
                diffline = ("\n".join(
                    list(dif.compare(e.splitlines(1), form.cleaned_data["pageline"].splitlines(1)))
                )
                ).replace(" ", " ").replace("-", "-").replace("?", "?").replace("+", "+")
                repr(diffline)
                # print diffline
                page_contents[i] = form.cleaned_data["pageline"]
        page.content = "\n".join(page_contents)
        page.save()
        return ajax_success(form.cleaned_data["pageline"])
    else:
        return ajax_error(form.errors.as_json())
Ejemplo n.º 8
0
def page_task_check(request, page_id=0):
    if not request.user.is_superuser:
        raise Http404
    get_object_or_404(BookPage, pk=page_id)
    status = cache.get("pagetask-%s" % page_id)
    if status:
        return ajax_success(data={'status': status})
    else:
        return ajax_error('未知的任务')
Ejemplo n.º 9
0
def page_task_check(request, page_id=0):
    if not request.user.is_superuser:
        raise Http404
    get_object_or_404(BookPage, pk=page_id)
    status = cache.get("pagetask-%s" % page_id)
    if status:
        return ajax_success(data={'status': status})
    else:
        return ajax_error('未知的任务')
Ejemplo n.º 10
0
def page_fix_pic(request, page_id=0):
    if not request.user.is_superuser:
        raise Http404
    bookpage = get_object_or_404(BookPage, pk=page_id)
    title = bookpage.title
    book_title = bookpage.book.title
    update_page.delay(page_id, book_title, title)
    cache.set("pagetask-%s" % page_id, 'RUN', 600)
    return ajax_success()
Ejemplo n.º 11
0
def page_fix_pic(request, page_id=0):
    if not request.user.is_superuser:
        raise Http404
    bookpage = get_object_or_404(BookPage, pk=page_id)
    title = bookpage.title
    book_title = bookpage.book.title
    update_page.delay(page_id, book_title, title)
    cache.set("pagetask-%s" % page_id, 'RUN', 600)
    return ajax_success()
Ejemplo n.º 12
0
def mb_load(request):
    C = {}
    books = Book.objects.filter(is_deleted=False).order_by('book_number')
    p = Paginator(books, 15)
    try:
        page = p.page(int(request.GET.get('p', 1)))
    except:
        page = p.page(1)
    C['books'] = page.object_list
    data = render_to_string('bookhtml5/searchload.html', C)
    return ajax_success(data=data)
Ejemplo n.º 13
0
def mb_load(request):
    C = {}
    books = Book.objects.filter(is_deleted=False).order_by('book_number')
    p = Paginator(books, 15)
    try:
        page = p.page(int(request.GET.get('p', 1)))
    except:
        page = p.page(1)
    C['books'] = page.object_list
    data = render_to_string('bookhtml5/searchload.html', C)
    return ajax_success(data=data)
Ejemplo n.º 14
0
def del_bookmark(request, bookmark_id):
    if request.method == 'POST':
        try:
            bookmark = BookMark.objects.get(pk=bookmark_id, user=request.user)
            book = bookmark.book
            bookmark.delete()
            book.get_bookrank().sub_fav()
        except:
            return ajax_error("无法删除此书签!")
        return ajax_success(data="删除成功!")
    else:
        raise Http404
Ejemplo n.º 15
0
def del_bookmark(request, bookmark_id):
    if request.method == 'POST':
        try:
            bookmark = BookMark.objects.get(pk=bookmark_id, user=request.user)
            book = bookmark.book
            bookmark.delete()
            book.get_bookrank().sub_fav()
        except:
            return ajax_error("无法删除此书签!")
        return ajax_success(data="删除成功!")
    else:
        raise Http404
Ejemplo n.º 16
0
def del_line(request, page_id=0):
    if request.method != "POST":
        raise HttpResponse(status_code=405)
    if not request.user.is_superuser:
        raise Http404
    page = get_object_or_404(BookPage, pk=page_id)
    page_contents = BookPage.content_text(page.get_content()).split('\n')
    try:
        page_contents.pop(int(request.POST["ln"]))
    except:
        return ajax_error("非法数据!")
    new_content = BookPage.content_html("\n".join(page_contents))
    page.set_content(new_content)
    return ajax_success(new_content)
Ejemplo n.º 17
0
def del_line(request, page_id=0):
    if request.method != "POST":
        raise HttpResponse(status_code=405)
    if not request.user.is_superuser:
        raise Http404
    page = get_object_or_404(BookPage, pk=page_id)
    page_contents = BookPage.content_text(page.get_content()).split('\n')
    try:
        page_contents.pop(int(request.POST["ln"]))
    except:
        return ajax_error("非法数据!")
    new_content = BookPage.content_html("\n".join(page_contents))
    page.set_content(new_content)
    return ajax_success(new_content)
Ejemplo n.º 18
0
def mb_searchload(request):
    C = {}
    books = Book.objects.filter(is_deleted=False).order_by('book_number')
    if request.GET.get('s', ''):
        books = books.filter(title__contains=request.GET['s'].strip())
        C['search'] = True
    else:
        books = []
    p = Paginator(books, 15)
    try:
        page = p.page(int(request.GET.get('p', 1)))
    except:
        page = p.page(1)
    C['books'] = page.object_list
    data = render_to_string('bookhtml5/searchload.html', C)
    return ajax_success(data=data)
Ejemplo n.º 19
0
def mb_searchload(request):
    C = {}
    books = Book.objects.filter(is_deleted=False).order_by('book_number')
    if request.GET.get('s', ''):
        books = books.filter(title__contains=request.GET['s'].strip())
        C['search'] = True
    else:
        books = []
    p = Paginator(books, 15)
    try:
        page = p.page(int(request.GET.get('p', 1)))
    except:
        page = p.page(1)
    C['books'] = page.object_list
    data = render_to_string('bookhtml5/searchload.html', C)
    return ajax_success(data=data)
Ejemplo n.º 20
0
def add_bookmark(request):
    if request.method == 'POST':
        try:
            page = BookPage.objects.get(pk=request.POST.get('pageid', '-1'))
        except:
            return ajax_error("章节错误!")
        obj, created = BookMark.objects.get_or_create(user=request.user,
                                                      book=page.book,
                                                      defaults={"page": page})
        if not created:
            obj.delete()
            obj = BookMark.objects.create(user=request.user,
                                          book=page.book,
                                          page=page)
        else:
            page.book.get_bookrank().add_fav()
        return ajax_success(data="添加成功!")
    else:
        raise Http404
Ejemplo n.º 21
0
def load_nall_page(request, page_id=0):
    bookpage = BookPage.objects.get(pk=page_id)
    book = Book.objects.get(is_deleted=False, book_number=bookpage.book_number)
    bookpages = []
    next_page_number = bookpage.next_number
    # 使用链式获取比排序后截取快
    for i in range(10):
        try:
            next_page = BookPage.objects.get(page_number=next_page_number)
        except:
            break
        else:
            bookpages.append(next_page)
            next_page_number = next_page.next_number

    data = render_to_string(
        'book/pagecontent.jade', {
            'bookpages': bookpages,
            'book': book,
            'invert': request.session.get('invert', False),
        })
    return ajax_success(data)
Ejemplo n.º 22
0
def add_bookmark(request):
    if request.method == 'POST':
        try:
            page = BookPage.objects.get(pk=request.POST.get('pageid', '-1'))
        except:
            return ajax_error("章节错误!")
        obj, created = BookMark.objects.get_or_create(
            user=request.user,
            book=page.book,
            defaults={"page": page}
        )
        if not created:
            obj.delete()
            obj = BookMark.objects.create(
                user=request.user,
                book=page.book,
                page=page
            )
        else:
            page.book.get_bookrank().add_fav()
        return ajax_success(data="添加成功!")
    else:
        raise Http404
Ejemplo n.º 23
0
def book_fix_pic(request, book_id=0):
    if not request.user.is_superuser:
        raise Http404
    book = get_object_or_404(Book, pk=book_id, is_deleted=False)
    update_book_pic_page.delay(book.book_number, 200)
    return ajax_success()
Ejemplo n.º 24
0
def book_fix_pic(request, book_id=0):
    if not request.user.is_superuser:
        raise Http404
    book = get_object_or_404(Book, pk=book_id, is_deleted=False)
    update_book_pic_page.delay(book.book_number, 200)
    return ajax_success()
Ejemplo n.º 25
0
def book_jx(request):
    bookid = request.GET['book_id']
    book = get_object_or_404(Book, id=bookid)
    book.last_page = book.get_last_page()
    book.save()
    return ajax_success()