def handle(self, *args, **options): book_name = options[self.BOOK_NAME][0] if not book_name: raise CommandError("You must specify book name.") try: book = models.Book.objects.get(url_title__iexact=book_name) except models.Book.DoesNotExist: raise CommandError('Book "%s" does not exist.' % book_name) if options['new_book_title']: book.title = options['new_book_title'] if options['new_book_url']: rename_book(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 save(self, *args, **kwargs): if self.instance.pk and self.has_changed(): book = Book.objects.get( url_title__iexact=self.initial['url_title']) rename_book(book, self.cleaned_data['title'], self.cleaned_data['url_title']) return super(BookRenameForm, self).save(*args, **kwargs)
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 booktype.utils.book import rename_book rename_book(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 booktype.utils.book import rename_book rename_book(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): book_name = options[self.BOOK_NAME][0] if not book_name: raise CommandError("You must specify book name.") try: book = models.Book.objects.get(url_title__iexact=book_name) except models.Book.DoesNotExist: raise CommandError('Book "%s" does not exist.' % book_name) if options['new_book_title']: book.title = options['new_book_title'] if options['new_book_url']: rename_book(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 save(self, *args, **kwargs): if self.instance.pk and self.has_changed(): book = Book.objects.get(url_title__iexact=self.initial['url_title']) rename_book( book, self.cleaned_data['title'], self.cleaned_data['url_title'] ) return super(BookRenameForm, self).save(*args, **kwargs)