Exemple #1
0
def favorite(request, response):
    id = param(request, "id", int)
    book = _get_book(id)
    try:
        request.user.book_favorite_set.create(book=book)
    except:
        raise AjaxError("你已经收藏过了。")
Exemple #2
0
def favorite(request, response):
    id = param(request, 'id', int)
    book = _get_book(id)
    try:
        request.user.book_favorite_set.create(book=book)
    except:
        raise AjaxError('你已经收藏过了。')
Exemple #3
0
def set_rate(request, response):
    id = param(request, 'id', int)
    rate = param(request, 'rate', int)
    if rate == 0 or rate > BOOK_RATE_MAX or rate < BOOK_RATE_MIN:
        raise AjaxError(u'评分不正确')
    book = _get_book(id)
    if book.check_rated(request.user):
        raise AjaxError(u'你已经给此小说评过分了')
    
    book.book_rate_set.create(user=request.user, rate=rate) # 记录已评分
    
    # 计算帖子平均分值
    #sum = book.book_rate_set.aggregate(models.Sum('rate'))[ 'rate__sum' ] or 0
    #count = book.rate_count + 1
    Book.objects.filter(pk=book.pk).update(rate_score=models.F('rate_score')+rate,
                                           rate_count=models.F('rate_count')+1)
Exemple #4
0
def set_rate(request, response):
    id = param(request, 'id', int)
    rate = param(request, 'rate', int)
    if rate == 0 or rate > BOOK_RATE_MAX or rate < BOOK_RATE_MIN:
        raise AjaxError(u'评分不正确')
    book = _get_book(id)
    if book.check_rated(request.user):
        raise AjaxError(u'你已经给此小说评过分了')

    book.book_rate_set.create(user=request.user, rate=rate)  # 记录已评分

    # 计算帖子平均分值
    #sum = book.book_rate_set.aggregate(models.Sum('rate'))[ 'rate__sum' ] or 0
    #count = book.rate_count + 1
    Book.objects.filter(pk=book.pk).update(
        rate_score=models.F('rate_score') + rate,
        rate_count=models.F('rate_count') + 1)
Exemple #5
0
def validate_username_uniqueness(request, response):
    username = param(request, "username", unicode)
    try:
        _validate_username(username)
        _validate_username_uniqueness(username)
        return {"message": u"用户名可以使用", "valid": True}
    except ValidationError, e:
        return {"message": u",".join(e.messages), "valid": False}
Exemple #6
0
def validate_username_uniqueness(request, response):
    username = param(request, 'username', unicode)
    try:
        _validate_username(username)
        _validate_username_uniqueness(username)
        return {'message':u'用户名可以使用', 'valid':True}
    except ValidationError, e:
        return {'message':u','.join(e.messages), 'valid':False}
Exemple #7
0
def save_point(request, response):
    chapter_id = param(request, "chapter_id", int)
    try:
        chapter = Chapter.objects.select_related("book").get(pk=chapter_id)
    except:
        raise AjaxError(u"Chapter 不存在")
    point, is_create = ReadPoint.objects.get_or_create(user=request.user, book=chapter.book)
    point.chapter = chapter
    point.save()
Exemple #8
0
def save_point(request, response):
    chapter_id = param(request, 'chapter_id', int)
    try:
        chapter = Chapter.objects.select_related('book').get(pk=chapter_id)
    except:
        raise AjaxError(u'Chapter 不存在')
    point, is_create = ReadPoint.objects.get_or_create(user=request.user,
                                                       book=chapter.book)
    point.chapter = chapter
    point.save()
Exemple #9
0
def delete_point(request, response):
    id = param(request, "id", int)
    request.user.book_readpoint_set.filter(id=id).delete()
Exemple #10
0
def stat(request, response):
    id = param(request, "id", int)
    Book.objects.filter(pk=id).update(views=models.F("views") + 1)
Exemple #11
0
def delete_favorite(request, response):
    id = param(request, 'id', int)
    request.user.book_favorite_set.filter(id=id).delete()
Exemple #12
0
def delete_chapter(request, response):
    id = param(request, 'id', int)
    Chapter.objects.filter(id=id).delete()
Exemple #13
0
def delete_point(request, response):
    id = param(request, 'id', int)
    request.user.book_readpoint_set.filter(id=id).delete()
Exemple #14
0
def search_book(request, response):
    title = param(request, 'title', unicode)
    if title:
        s = Book.search.query('@title %s' % title).set_options(passages=True, mode='SPH_MATCH_EXTENDED2').all()[0:10]
        if s:
            return [{'id':v.id, 'title':v.sphinx['passages']['title'], 'author':v.author} for v in s]
Exemple #15
0
def search_book(request, response):
    title = param(request, "title", unicode)
    if title:
        s = Book.search.query("@title %s" % title).set_options(passages=True, mode="SPH_MATCH_EXTENDED2").all()[0:10]
        if s:
            return [{"id": v.id, "title": v.sphinx["passages"]["title"], "author": v.author} for v in s]
Exemple #16
0
def stat(request, response):
    id = param(request, 'id', int)
    Book.objects.filter(pk=id).update(views=models.F('views') + 1)
Exemple #17
0
def delete_chapter(request, response):
    id = param(request, "id", int)
    Chapter.objects.filter(id=id).delete()
Exemple #18
0
def delete_favorite(request, response):
    id = param(request, "id", int)
    request.user.book_favorite_set.filter(id=id).delete()
Exemple #19
0
def stat(request, response):
    id = param(request, 'id', int)
    Book.objects.filter(pk=id).update(views=models.F('views') + 1)