× Warning! This forum is in archival status. New contributions may not work.
Set filename for chapter export
  • Hello,

    When exporting, the filenames seem to be based upon the first time I named the chapter. I have renamed the chapter since. I also realised that having numbers in the filenames would be really handy for me. So I’d like to edit the slug/basename of the chapters.

    I didn’t see a UI option for this (that’s ok, shouldn’t clutter the UI with too many options!). I guess I could go into the database to find and change this information though, would that risk breaking anything?

  • 2 Comments sorted by
  • Vote Up0Vote Down Daniel JamesDaniel James
    Posts: 844Member, Sourcefabric Team
    Hi Eric,

    One thing that would break is external links to the web representation of the book, which depending on how you are publishing may or may not be important. This was the original rationale for not updating the basenames on a chapter name change.

    Cheers!

    Daniel
  • Thanks!



    For reference if someone else needs to do this, here’s a possible approach for Booktype 2.4. I’m not super at ease in the PostgreSQL shell so I opened the django django shell with e@booktype:/var/www/booktype/instance1$ sudo PYTHON_PATH=/var/lib/booktype/lib/python2.7 ./manage_prod.py shell (not sure the PYTHON_PATH part is necessary, I must have messed up the path during installing). Then:



    b = Book.objects.get(url_title='this-book')

    def rename_chapter(old_slug, new_slug):
    try:
    c = Chapter.objects.filter(book=b).get(url_title=old_slug)
    except Chapter.DoesNotExist:
    print "%s not found" % old_slug
    return
    c.url_title = new_slug
    c.save()

    # repeat the following line as often as necessary
    rename_chapter('the-name', '03-the-changed-name')