Exemple #1
0
def edit_book(request, bookid, version=None):
    """
    Django View. Default page for Booki editor.

    @param request: Django Request
    @param bookid: Book ID
    @param version: Book Version or None
    """

    from booki.utils import security

    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 = getVersion(book, version)

    bookSecurity = security.getUserSecurityForBook(request.user, book)

    hasPermission = security.canEditBook(book, bookSecurity)

    if not hasPermission:
        return pages.ErrorPage(request, "errors/editing_forbidden.html", {"book": book})    

    chapters = models.Chapter.objects.filter(version=book_version)

    tabs = ["chapters"]

    if True: # bookSecurity.isAdmin():
        tabs += ["attachments"]

    tabs += ["history", "versions", "notes"]

    if bookSecurity.isAdmin():
        tabs += ["settings"]

    tabs += ["export"]

    isBrowserSupported = True
    browserMeta = request.META.get('HTTP_USER_AGENT', '')

    if browserMeta.find('MSIE') != -1:
        isBrowserSupported = False
        
    return render_to_response('editor/edit_book.html', {"book": book, 
                                                        "book_version": book_version.getVersion(),
                                                        "version": book_version,

                                                        ## this change will break older versions of template
                                                        "statuses": [(s.name.replace(' ', '_'), s.name) for s in models.BookStatus.objects.filter(book = book)],
                                                        "chapters": chapters, 
                                                        "security": bookSecurity,
                                                        "is_admin": bookSecurity.isGroupAdmin() or bookSecurity.isBookAdmin() or bookSecurity.isSuperuser(),
                                                        "is_owner": book.owner == request.user,
                                                        "tabs": tabs,
                                                        "is_browser_supported": isBrowserSupported,
                                                        "request": request})
Exemple #2
0
def edit_book(request, bookid, version=None):
    """
    Django View. Default page for Booki editor.

    @param request: Django Request
    @param bookid: Book ID
    @param version: Book Version or None
    """

    from booki.utils import security

    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 = getVersion(book, version)

    bookSecurity = security.getUserSecurityForBook(request.user, book)

    hasPermission = security.canEditBook(book, bookSecurity)

    if not hasPermission:
        return pages.ErrorPage(request, "errors/editing_forbidden.html", {"book": book})    

    chapters = models.Chapter.objects.filter(version=book_version)

    tabs = ["chapters"]

    if True: # bookSecurity.isAdmin():
        tabs += ["attachments"]

    tabs += ["history", "versions", "notes"]

    if bookSecurity.isAdmin():
        tabs += ["settings"]

    tabs += ["export"]

    isBrowserSupported = True
    browserMeta = request.META.get('HTTP_USER_AGENT', '')

    if browserMeta.find('MSIE') != -1:
        isBrowserSupported = False
        
    return render_to_response('editor/edit_book.html', {"book": book, 
                                                        "book_version": book_version.getVersion(),
                                                        "version": book_version,

                                                        ## this change will break older versions of template
                                                        "statuses": [(s.name.replace(' ', '_'), s.name) for s in models.BookStatus.objects.filter(book = book)],
                                                        "chapters": chapters, 
                                                        "security": bookSecurity,
                                                        "is_admin": bookSecurity.isGroupAdmin() or bookSecurity.isBookAdmin() or bookSecurity.isSuperuser(),
                                                        "is_owner": book.owner == request.user,
                                                        "tabs": tabs,
                                                        "is_browser_supported": isBrowserSupported,
                                                        "request": request})
Exemple #3
0
def book_chapter(request, bookid, chapter, version=None):
    """
    Django View. Shows chapter for the published version of a book.

    @type request: C{django.http.HttpRequest}
    @param request: Client Request object
    @type bookid: C{string}
    @param bookid: Unique Book ID
    @type chapter: C{string}
    @param chapter: Chapter name
    @type version: C{string}
    @param verson: Book version
    """

    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 = getVersion(book, version)

    from booki.utils import security
    bookSecurity = security.getUserSecurityForBook(request.user, book)

    hasPermission = security.canEditBook(book, bookSecurity)

    if book.hidden and not hasPermission:
        return pages.ErrorPage(request, "errors/no_permissions.html")


    chapters = []

    for chap in  models.BookToc.objects.filter(version=book_version).order_by("-weight"):
        if chap.isChapter():
            chapters.append({"url_title": chap.chapter.url_title,
                             "name": chap.chapter.title})
        else:
            chapters.append({"url_title": None,
                             "name": chap.name})

    try:
        content = models.Chapter.objects.get(version=book_version, url_title = chapter)
    except models.Chapter.DoesNotExist:
        return pages.ErrorPage(request, "errors/chapter_does_not_exist.html", {"chapter_name": chapter, "book": book})
    except models.Chapter.MultipleObjectsReturned:
        return pages.ErrorPage(request, "errors/chapter_duplicate.html", {"chapter_name": chapter, "book": book})


    return render_to_response('reader/book_chapter.html', {"chapter": chapter, 
                                                      "book": book, 
                                                      "book_version": book_version.getVersion(),
                                                      "chapters": chapters, 
                                                      "has_css": _customCSSExists(book.url_title),
                                                      "request": request, 
                                                      "content": content})
Exemple #4
0
def view_full(request, bookid, version=None):
    """
    Django View. Shows full content of book on one page. This is published version of a book.

    @type request: C{django.http.HttpRequest}
    @param request: Django Request
    @type bookid: C{string}
    @param bookid: Unique Book ID
    @type version: C{string}
    @param version: Version of the book
    """

    chapters = []

    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(version)

    from booki.utils import security
    bookSecurity = security.getUserSecurityForBook(request.user, book)

    hasPermission = security.canEditBook(book, bookSecurity)

    if book.hidden and not hasPermission:
        return pages.ErrorPage(request, "errors/no_permissions.html")

    for chapter in models.BookToc.objects.filter(
            version=book_version).order_by("-weight"):
        if chapter.isChapter():
            chapters.append({
                "type": "chapter",
                "title": chapter.chapter.title,
                "content": chapter.chapter.content,
                "chapter": chapter.chapter
            })
        else:
            chapters.append({"type": "section", "title": chapter.name})

    return render_to_response(
        'reader/full.html', {
            "book": book,
            "book_version": book_version.getVersion(),
            "chapters": chapters,
            "has_css": _customCSSExists(book.url_title),
            "request": request
        })
Exemple #5
0
def draft_book(request, bookid, version=None):
    """
    Django View. Shows main page for the draft version of a book.

    @type request: C{django.http.HttpRequest}
    @param request: Client Request object
    @type bookid: C{string}
    @param bookid: Unique Book ID
    @type version: C{string}
    @param verson: Book version
    """

    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(version)

    from booki.utils import security
    bookSecurity = security.getUserSecurityForBook(request.user, book)

    hasPermission = security.canEditBook(book, bookSecurity)

    if book.hidden and not hasPermission:
        return pages.ErrorPage(request, "errors/no_permissions.html")

    chapters = []

    for chapter in models.BookToc.objects.filter(
            version=book_version).order_by("-weight"):
        if chapter.isChapter():
            chapters.append({
                "url_title": chapter.chapter.url_title,
                "name": chapter.chapter.title
            })
        else:
            chapters.append({"url_title": None, "name": chapter.name})

    return render_to_response(
        'reader/draft_book.html', {
            "book": book,
            "book_version": book_version.getVersion(),
            "chapters": chapters,
            "has_css": _customCSSExists(book.url_title),
            "request": request
        })
Exemple #6
0
def view_full(request, bookid, version=None):
    """
    Django View. Shows full content of book on one page. This is published version of a book.

    @type request: C{django.http.HttpRequest}
    @param request: Django Request
    @type bookid: C{string}
    @param bookid: Unique Book ID
    @type version: C{string}
    @param version: Version of the book
    """

    chapters = []

    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 = getVersion(book, version)

    from booki.utils import security
    bookSecurity = security.getUserSecurityForBook(request.user, book)

    hasPermission = security.canEditBook(book, bookSecurity)

    if book.hidden and not hasPermission:
        return pages.ErrorPage(request, "errors/no_permissions.html")

    for chapter in  models.BookToc.objects.filter(version=book_version).order_by("-weight"):
        if chapter.isChapter():
            chapters.append({"type": "chapter",
                             "title": chapter.chapter.title,
                             "content": chapter.chapter.content,
                             "chapter": chapter.chapter})
        else:
            chapters.append({"type": "section",
                             "title": chapter.name})

    return render_to_response('reader/full.html', {"book": book, 
                                                   "book_version": book_version.getVersion(),
                                                   "chapters": chapters, 
                                                   "has_css": _customCSSExists(book.url_title),
                                                   "request": request})
Exemple #7
0
def book_chapter(request, bookid, chapter, version=None):
    """
    Django View. Shows chapter for the published version of a book.

    @type request: C{django.http.HttpRequest}
    @param request: Client Request object
    @type bookid: C{string}
    @param bookid: Unique Book ID
    @type chapter: C{string}
    @param chapter: Chapter name
    @type version: C{string}
    @param verson: Book version
    """

    try:
        book = models.Book.objects.get(url_title__iexact=bookid)
    except models.Book.DoesNotExist:
        try:
            resp = pages.ErrorPage(request, "errors/book_does_not_exist.html", {"book_name": bookid})
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp

    book_version = book.getVersion(version)

    from booki.utils import security
    bookSecurity = security.getUserSecurityForBook(request.user, book)

    hasPermission = security.canEditBook(book, bookSecurity)

    if book.hidden and not hasPermission:
        try:
            resp = pages.ErrorPage(request, "errors/no_permissions.html")
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp

    chapters = []

    for chap in  models.BookToc.objects.filter(version=book_version).order_by("-weight"):
        if chap.isChapter():
            chapters.append({"url_title": chap.chapter.url_title,
                             "name": chap.chapter.title})
        else:
            chapters.append({"url_title": None,
                             "name": chap.name})

    try:
        content = models.Chapter.objects.get(version=book_version, url_title = chapter)
    except models.Chapter.DoesNotExist:
        try:
            resp = pages.ErrorPage(request, "errors/chapter_does_not_exist.html", {"chapter_name": chapter, "book": book})
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp
    except models.Chapter.MultipleObjectsReturned:
        try:
            resp = pages.ErrorPage(request, "errors/chapter_duplicate.html", {"chapter_name": chapter, "book": book})
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

    try:
        resp = render_to_response('reader/book_chapter.html', {"chapter": chapter, 
                                                               "book": book, 
                                                               "book_version": book_version.getVersion(),
                                                               "chapters": chapters, 
                                                               "has_css": _customCSSExists(book.url_title),
                                                               "request": request, 
                                                               "content": content})
    except:
        transaction.rollback()
    else:
        transaction.commit()

    return resp
Exemple #8
0
def book_view(request, bookid, version=None):
    """
    Django View. Shows main book page for the published version of a book.

    @type request: C{django.http.HttpRequest}
    @param request: Client Request object
    @type bookid: C{string}
    @param bookid: Unique Book ID
    @type version: C{string}
    @param verson: Book version
    """

    try:
        book = models.Book.objects.get(url_title__iexact=bookid)
    except models.Book.DoesNotExist:
        try:
            resp = pages.ErrorPage(request, "errors/book_does_not_exist.html", {"book_name": bookid})
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp

    book_version = book.getVersion(version)

    from booki.utils import security
    bookSecurity = security.getUserSecurityForBook(request.user, book)

    hasPermission = security.canEditBook(book, bookSecurity)

    if book.hidden and not hasPermission:
        try:
            resp = pages.ErrorPage(request, "errors/no_permissions.html")
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp

    chapters = []
    firstChapter = None

    for chapter in  models.BookToc.objects.filter(version=book_version).order_by("-weight"):
        if chapter.isChapter():
            if not firstChapter:
                firstChapter = chapter.chapter

            chapters.append({"url_title": chapter.chapter.url_title,
                             "name": chapter.chapter.title})
        else:
            chapters.append({"url_title": None,
                             "name": chapter.name})
        

    try:
        if firstChapter:
            resp = redirect('book_chapter', bookid = book.url_title, chapter=firstChapter.url_title) 
        else:
            resp = render_to_response('reader/book_view.html', {"book": book, 
                                                                "book_version": book_version.getVersion(),
                                                                "chapters": chapters, 
                                                                "has_css": _customCSSExists(book.url_title),
                                                                "request": request})
    except:
        transaction.rollback()
        raise
    else:
        transaction.commit()

    return resp
Exemple #9
0
def draft_book(request, bookid, version=None):
    """
    Django View. Shows main page for the draft version of a book.

    @type request: C{django.http.HttpRequest}
    @param request: Client Request object
    @type bookid: C{string}
    @param bookid: Unique Book ID
    @type version: C{string}
    @param verson: Book version
    """

    try:
        book = models.Book.objects.get(url_title__iexact=bookid)
    except models.Book.DoesNotExist:
        try:
            resp = pages.ErrorPage(request, "errors/book_does_not_exist.html", {"book_name": bookid})
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp

    book_version = book.getVersion(version)

    from booki.utils import security
    bookSecurity = security.getUserSecurityForBook(request.user, book)

    hasPermission = security.canEditBook(book, bookSecurity)

    if book.hidden and not hasPermission:
        try:
            resp = pages.ErrorPage(request, "errors/no_permissions.html")
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp

    chapters = []
    firstChapter = None

    for chapter in  models.BookToc.objects.filter(version=book_version).order_by("-weight"):
        if chapter.isChapter():
            if not firstChapter:
                firstChapter = chapter.chapter

            chapters.append({"url_title": chapter.chapter.url_title,
                             "name": chapter.chapter.title})
        else:
            chapters.append({"url_title": None,
                             "name": chapter.name})
        

    try:
        editingEnabled = False

        if request.user.is_authenticated() and book.version == book_version:
            editingEnabled = True

        if firstChapter:
            resp = redirect('draft_chapter', bookid = book.url_title, version=book_version.getVersion(), chapter=firstChapter.url_title) 
        else:
            resp = render_to_response('reader/draft_book.html', {"book": book, 
                                                                 "book_version": book_version.getVersion(),
                                                                 "chapters": chapters, 
                                                                 "editing_enabled": editingEnabled,
                                                                 "has_css": _customCSSExists(book.url_title),
                                                                 "request": request})
    except:
        transaction.rollback()
        raise
    else:
        transaction.commit()

    return resp
Exemple #10
0
def edit_book(request, bookid, version=None):
    """
    Django View. Default page for Booki editor.

    @param request: Django Request
    @param bookid: Book ID
    @param version: Book Version or None
    """

    from booki.utils import security

    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})

    """%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"""
    """
    Modificacion UCSP
    """
    discussions_list = models.DiscussionTheme.objects.all().order_by('-created')
    group = book.group
    members = []
    if (group):
        members = group.members.all()
    is_member = request.user in members


    """%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"""

    book_version = book.getVersion(version)

    bookSecurity = security.getUserSecurityForBook(request.user, book)

    hasPermission = security.canEditBook(book, bookSecurity)

    if not hasPermission:
        return pages.ErrorPage(request, "errors/editing_forbidden.html", {"book": book})    

    chapters = models.Chapter.objects.filter(version=book_version)

    tabs = ["chapters"]
    #tabs += ["attachments"]
    tabs += ["covers"]
    #tabs += ["history", "versions", "notes"]
    tabs += ["history", "notes"]

    if bookSecurity.isAdmin():
        tabs += ["settings"]

    #tabs += ["export"]
    tabs += ["discussions"]

    isBrowserSupported = True
    browserMeta = request.META.get('HTTP_USER_AGENT', '')

    if browserMeta.find('MSIE') != -1:
        isBrowserSupported = False

    try:
        publish_options = settings.PUBLISH_OPTIONS
    except AttributeError:
        from booki import constants
        publish_options = constants.PUBLISH_OPTIONS
        
    return render_to_response('editor/edit_book.html', {"book": book, 
                                                        "book_version": book_version.getVersion(),
                                                        "version": book_version,

                                                        ## this change will break older versions of template
                                                        "statuses": [(s.name.replace(' ', '_'), s.name) for s in models.BookStatus.objects.filter(book = book)],
                                                        "chapters": chapters, 
                                                        "security": bookSecurity,
                                                        "is_admin": bookSecurity.isGroupAdmin() or bookSecurity.isBookAdmin() or bookSecurity.isSuperuser(),
                                                        "is_owner": book.owner == request.user,
                                                        "tabs": tabs,
                                                        "is_browser_supported": isBrowserSupported,
                                                        "publish_options": publish_options,
                                                        "discussions_list": discussions_list, #MODIFICATION UCSP
                                                        "is_member": is_member, #MODIFICATION UCSP
                                                        "request": request})
Exemple #11
0
def draft_chapter(request, bookid, chapter, version=None):
    """
    Django View. Shows chapter for the draft version of a book.

    @type request: C{django.http.HttpRequest}
    @param request: Client Request object
    @type bookid: C{string}
    @param bookid: Unique Book ID
    @type chapter: C{string}
    @param chapter: Chapter name
    @type version: C{string}
    @param verson: Book version
    """

    try:
        book = models.Book.objects.get(url_title__iexact=bookid)
    except models.Book.DoesNotExist:
        try:
            resp =pages.ErrorPage(request, "errors/book_does_not_exist.html", {"book_name": bookid})
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp

    book_version = book.getVersion(version)

    from booki.utils import security
    bookSecurity = security.getUserSecurityForBook(request.user, book)

    hasPermission = security.canEditBook(book, bookSecurity)

    if book.hidden and not hasPermission:
        try:
            resp = pages.ErrorPage(request, "errors/no_permissions.html")
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp


    chapters = []
    subchapters = []

    for chap in  models.BookToc.objects.filter(version=book_version).order_by("-weight"):
        if chap.isChapter():
            chapters.append({"url_title": chap.chapter.url_title,
                             "name": chap.chapter.title,
                             "isSection": 0,
                             "id":  chap.chapter.id,
                             "parent":chap.chapter.parent})
            for subchap in  models.Chapter.objects.filter(parent=chap.chapter.id).order_by("sc_position"):
                    subchapters.append({"url_title": subchap.url_title,
                                 "name": subchap.title,
                                 "isSection": 0,
                                 "parent":subchap.parent})
        else:
            chapters.append({"url_title": chap.chapter.url_title,
                             "name": chap.name,
                             "isSection": 1,
                             "parent":0})




    try:
        content = models.Chapter.objects.get(version=book_version, url_title = chapter)
    except models.Chapter.DoesNotExist:
        try:
            resp = pages.ErrorPage(request, "errors/chapter_does_not_exist.html", {"chapter_name": chapter, "book": book})
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp
    except models.Chapter.MultipleObjectsReturned:
        try:
            resp = pages.ErrorPage(request, "errors/chapter_duplicate.html", {"chapter_name": chapter, "book": book})
        except:
            transaction.rollback()
            raise
        else:
            transaction.commit()

        return resp
        
    try:
        editingEnabled = False

        if request.user.is_authenticated() and book.version == book_version:
            editingEnabled = True

        resp = render_to_response('reader/draft_chapter.html', {"chapter": chapter, 
                                                                "book": book, 
                                                                "book_version": book_version.getVersion(),
                                                                "chapters": chapters, 
								"subchapters": subchapters,
                                                                "editing_enabled": editingEnabled,
                                                                "has_css": _customCSSExists(book.url_title),
                                                                "request": request, 
                                                                "content": content})
    except:
        transaction.rollback()
        raise
    else:
        transaction.commit()

    return resp