示例#1
0
def check_valid_user(request, user_id):
    if request.user.is_anonymous():
        return render_template(request, 'users/user_login.html', {'next':'%s' % request.path})
    try:
        person = User.objects.get(pk=int(user_id))
    except User.DoesNotExist:
        return render_template(request, 'error.html', {'message':_("User ID (%s) is not existed!") % user_id})
    try:
        profile = person.get_profile()
    except:
        #if there is no profile record existed, then create a new record first
        profile = UserProfile(user=person)
        profile.save()
    if person.id != request.user.id:
        return render_template(request, 'error.html', {'message':_('You have no right to view the page!')})
示例#2
0
def user_book_detail(request, object_id, book_id):
    user = User.objects.get(pk=int(object_id))
    book = Book.objects.get(pk=int(book_id))
    return render_template(request, 'users/user_book_detail.html', {
        'person': user,
        'book': book
    })
示例#3
0
def user_chapter(request, object_id, book_id, chapter_id=None):
    if request.GET:
        o = Chapter.objects.get(pk=int(chapter_id))
        result = {
            'id': o.id,
            'content': o.content,
            'abstract': o.abstract,
            'title': o.title,
            'date': o.modifydate.strftime("%b %d,%Y %I:%m %p")
        }
        return ajax.ajax_ok(result)
    else:
        v = ChapterValidator(request, book_id, chapter_id)
        if request.POST:
            flag, obj = v.validate_and_save(request)
            if flag:
                return ajax.ajax_ok(message=_("Success!"))
            return ajax.ajax_fail(obj, message=_("There are some errors!"))
        else:
            user = User.objects.get(pk=int(object_id))
            book = Book.objects.get(pk=int(book_id))
            chapter = Chapter.objects.get(pk=int(chapter_id))
            return render_template(request, 'users/user_chapter.html', {
                'person': user,
                'book': book,
                'chapter': chapter
            })
示例#4
0
def check_valid_user(request, user_id):
    if request.user.is_anonymous():
        return render_template(request, 'users/user_login.html',
                               {'next': '%s' % request.path})
    try:
        person = User.objects.get(pk=int(user_id))
    except User.DoesNotExist:
        return render_template(
            request, 'error.html',
            {'message': _("User ID (%s) is not existed!") % user_id})
    try:
        profile = person.get_profile()
    except:
        #if there is no profile record existed, then create a new record first
        profile = UserProfile(user=person)
        profile.save()
    if person.id != request.user.id:
        return render_template(
            request, 'error.html',
            {'message': _('You have no right to view the page!')})
示例#5
0
def user_edit(request, object_id):
    if request.POST:
        v = ChangeValidator(request, object_id)
        f, obj = v.validate_and_save(request)
        if f:
            return ajax.ajax_ok(message=_('User infomation updated successful!'))
        return ajax.ajax_fail(obj)
    else:
        user = User.objects.get(pk=int(object_id))
        d = {'person':user}
        return render_template(request, 'users/user_edit.html', d)
示例#6
0
def user_edit(request, object_id):
    if request.POST:
        v = ChangeValidator(request, object_id)
        f, obj = v.validate_and_save(request)
        if f:
            return ajax.ajax_ok(
                message=_('User infomation updated successful!'))
        return ajax.ajax_fail(obj)
    else:
        user = User.objects.get(pk=int(object_id))
        d = {'person': user}
        return render_template(request, 'users/user_edit.html', d)
示例#7
0
def user_register(request):
    v = RegisterValidator(request)
    if request.POST:
        f, obj = v.validate_and_save(request)
        if f:
            user = authenticate(username=obj.username, password=obj.password)
            if user and user.is_staff:
                login(request, user)
                user.last_login = datetime.datetime.now()
                user.save()
            return ajax.ajax_ok(True, next=setting('URLROOT') + '/')
        return ajax.ajax_fail(obj)
    else:
        return render_template(request, 'users/register.html')
示例#8
0
def chapter(request, book_id, chapter_num):
    book = Book.objects.get(pk=int(book_id))
    chapter = Chapter.objects.get(num=chapter_num, book=book)
    prev, next = None, None
    nexts = Chapter.objects.filter(num__gt=chapter_num, book=book)
    if nexts:
        next = nexts[0]
    prevs = Chapter.objects.filter(num__lt=chapter_num, book=book)
    if prevs:
        prev = list(prevs)[-1]
    return render_template(
        request, 'books/chapter.html', {
            'book': book,
            'chapter': chapter,
            'next': next,
            'prev': prev,
            'COOKIES': request.COOKIES
        })
示例#9
0
def user_chapter(request, object_id, book_id, chapter_id=None):
    if request.GET:
        o = Chapter.objects.get(pk=int(chapter_id))
        result = {'id':o.id, 'content':o.content, 'abstract':o.abstract,
            'title':o.title, 'date':o.modifydate.strftime("%b %d,%Y %I:%m %p")}
        return ajax.ajax_ok(result)
    else:
        v = ChapterValidator(request, book_id, chapter_id)
        if request.POST:
            flag, obj = v.validate_and_save(request)
            if flag:
                return ajax.ajax_ok(message=_("Success!"))
            return ajax.ajax_fail(obj, message=_("There are some errors!"))
        else:
            user = User.objects.get(pk=int(object_id))
            book = Book.objects.get(pk=int(book_id))
            chapter = Chapter.objects.get(pk=int(chapter_id))
            return render_template(request, 'users/user_chapter.html', 
                {'person':user, 'book':book, 'chapter':chapter})
示例#10
0
def user_books(request, object_id):
    user = User.objects.get(pk=int(object_id))
    return render_template(request, 'users/user_book.html', {'person':user})
示例#11
0
def user_book_detail(request, object_id, book_id):
    user = User.objects.get(pk=int(object_id))
    book = Book.objects.get(pk=int(book_id))
    return render_template(request, 'users/user_book_detail.html', 
        {'person':user, 'book':book})
示例#12
0
def license(request):
    return render_template(request, 'license.html')
示例#13
0
def index(request):
    return render_template(request, 'index.html')
示例#14
0
def index(request):
    return render_template(request, 'index.html')
示例#15
0
def user_detail(request, object_id):
    person = User.objects.get(pk=int(object_id))
    return render_template(request, 'users/user_detail.html',
                           {'person': person})
示例#16
0
def index(request):
    return render_template(request, 'zipbooks/index.html')
示例#17
0
def user_detail(request, object_id):
    person = User.objects.get(pk=int(object_id))
    return render_template(request, 'users/user_detail.html', {'person':person})
示例#18
0
 def _f(request, *args, **kwargs):
     if func:
         result = func(request, *args, **kwargs)
     else:
         result = {}
     return render_template(request, templatename, result)
示例#19
0
def help(request):
    return render_template(request, 'help.html')
示例#20
0
def license(request):
    return render_template(request, 'license.html')
示例#21
0
def user_books(request, object_id):
    user = User.objects.get(pk=int(object_id))
    return render_template(request, 'users/user_book.html', {'person': user})
示例#22
0
def help(request):
    return render_template(request, 'help.html')
示例#23
0
def content(request, book_id):
    book = Book.objects.get(pk=int(book_id))
    return render_template(request, 'books/content.html', {'book': book})
示例#24
0
def login(request):
    if request.POST:
        from apps.users.views.auth import user_login
        return user_login(request)
    else:
        return render_template(request, 'users/user_login.html')
示例#25
0
def booklist(request):
    user = request.user
    return render_template(request, 'books/list.html')
示例#26
0
def login(request):
    if request.POST:
        from apps.users.views.auth import user_login
        return user_login(request)
    else:
        return render_template(request, 'users/user_login.html')