def handle(self, *args, **options): if len(args) != 1: raise CommandError("You must specify book name.") try: book = models.Book.objects.get(url_title__iexact=args[0]) except models.Book.DoesNotExist: raise CommandError('Book "%s" does not exist.' % args[0]) if options['new_book_title']: book.title = options['new_book_title'] if options['new_book_url']: from booki.utils.book import renameBook renameBook(book, book.title, options['new_book_url']) if options['owner']: try: user = User.objects.get(username=options['owner']) except User.DoesNotExist: raise CommandError( 'User "%s" does not exist. Can not finish import.' % options['owner']) book.owner = user book.save()
def handle(self, *args, **options): if len(args) != 1: raise CommandError("You must specify book name.") try: book = models.Book.objects.get(url_title__iexact=args[0]) except models.Book.DoesNotExist: raise CommandError('Book "%s" does not exist.' % args[0]) if options['new_book_title']: book.title = options['new_book_title'] if options['new_book_url']: from booki.utils.book import renameBook renameBook(book, book.title, options['new_book_url']) if options['owner']: try: user = User.objects.get(username=options['owner']) except User.DoesNotExist: raise CommandError('User "%s" does not exist. Can not finish import.' % options['owner']) book.owner = user book.save()
def rename_book(request, bookid): try: book = models.Book.objects.get(url_title__iexact=bookid) except models.Book.DoesNotExist: return pages.ErrorPage(request, "errors/book_does_not_exist.html", {"book_name": bookid}) book_version = book.getVersion(None) if request.method == "POST": frm = BookRenameForm(request.POST, request.FILES) if request.POST["submit"] == _("Cancel"): return HttpResponseRedirect(reverse("control_book", args=[book.url_title])) if frm.is_valid(): from booki.utils.book import renameBook from booki.utils.misc import bookiSlugify title = frm.cleaned_data["title"] URLTitle = frm.cleaned_data["url_title"] if URLTitle.strip() == "": URLTitle = bookiSlugify(title) # this is not the nice way to solve this if book.url_title != URLTitle: try: b = models.Book.objects.get(url_title__iexact=URLTitle) except models.Book.DoesNotExist: renameBook(book, title, URLTitle) book.save() messages.success(request, _("Successfuly renamed book.")) return HttpResponseRedirect(reverse("control_book", args=[book.url_title])) else: renameBook(book, title, URLTitle) book.save() messages.success(request, _("Successfuly renamed book.")) return HttpResponseRedirect(reverse("control_book", args=[book.url_title])) else: frm = BookRenameForm(initial={"title": book.title, "url_title": book.url_title}) return render_to_response( "booktypecontrol/rename_book.html", {"request": request, "admin_options": ADMIN_OPTIONS, "form": frm, "book": book}, context_instance=RequestContext(request), )