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!')})
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 })
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 })
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!')})
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)
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)
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')
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 })
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})
def user_books(request, object_id): user = User.objects.get(pk=int(object_id)) return render_template(request, 'users/user_book.html', {'person':user})
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})
def license(request): return render_template(request, 'license.html')
def index(request): return render_template(request, 'index.html')
def user_detail(request, object_id): person = User.objects.get(pk=int(object_id)) return render_template(request, 'users/user_detail.html', {'person': person})
def index(request): return render_template(request, 'zipbooks/index.html')
def user_detail(request, object_id): person = User.objects.get(pk=int(object_id)) return render_template(request, 'users/user_detail.html', {'person':person})
def _f(request, *args, **kwargs): if func: result = func(request, *args, **kwargs) else: result = {} return render_template(request, templatename, result)
def help(request): return render_template(request, 'help.html')
def user_books(request, object_id): user = User.objects.get(pk=int(object_id)) return render_template(request, 'users/user_book.html', {'person': user})
def content(request, book_id): book = Book.objects.get(pk=int(book_id)) return render_template(request, 'books/content.html', {'book': book})
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')
def booklist(request): user = request.user return render_template(request, 'books/list.html')