def createBook(user, bookTitle, status="imported", bookURL=None): """ Creates book. @todo: Do something about status. @type user: C{django.contrib.auth.models.User} @param user: Booki user who will be book owner @type bookTitle: C{string} @param bookTitle: Title for the book. If bookURL is omitted it will slugify title for the url version @type status: C{string} @param status: String name for the status (optional) @type bookURL: C{string} @param bookURL: URL title for the book (optional) @rtype: C{booki.editor.models.Book} @return: Returns book object """ if bookURL: url_title = bookURL else: url_title = bookiSlugify(bookTitle) book = models.Book(url_title=url_title, title=bookTitle, owner=user, published=datetime.datetime.now()) book.save() # put this in settings file status_default = ["published", "not published", "imported"] n = len(status_default) for statusName in status_default: status = models.BookStatus(book=book, name=statusName, weight=n) status.save() n -= 1 # not use "not published" but first in the list maybe, or just status book.status = models.BookStatus.objects.get(book=book, name="not published") book.save() version = models.BookVersion(book=book, major=1, minor=0, name='initial', description='') version.save() book.version = version book.save() logBookHistory(book=book, version=version, user=user, kind='book_create') import booki.editor.signals booki.editor.signals.book_created.send(sender=user, book=book) return book
def create_book(user, book_title, status=None, book_url=None): """ Creates book. @type user: C{django.contrib.auth.models.User} @param user: Booktype user who will be book owner @type book_title: C{string} @param book_title: Title for the book. If book_url is omitted it will slugify title for the url version @type status: C{string} @param status: String name for the status (optional) @type book_url: C{string} @param book_url: URL title for the book (optional) @rtype: C{booki.editor.models.Book} @return: Returns book object """ if book_url: url_title = book_url[:100] else: url_title = booktype_slugify(book_title[:100]) book = models.Book(url_title=url_title, title=book_title, owner=user, created=datetime.datetime.now(), published=datetime.datetime.now(), hidden=False, description='', cover=None) book.save() status_list = config.get_configuration('CHAPTER_STATUS_LIST') n = len(status_list) default_status = status if status else get_default_book_status() for status_elem in status_list: status = models.BookStatus(book=book, name=status_elem['name'], weight=n, color=status_elem['color']) status.save() n -= 1 # not use "not published" but first in the list maybe, or just status book.status = models.BookStatus.objects.get(book=book, name=default_status) book.save() track_changes = config.get_configuration('BOOK_TRACK_CHANGES', False) version = models.BookVersion(book=book, major=1, minor=0, name='initial', description='', created=datetime.datetime.now(), track_changes=track_changes) version.save() book.version = version book.save() logBookHistory(book=book, version=version, user=user, kind='book_create') booki.editor.signals.book_created.send(sender=user, book=book) return book