Ejemplo n.º 1
0
def create_chapters(vers, release_date=None, comments_open=True):
    """
    Create a bunch of ``Chapter`` objects for a given ``BookVersion``.
    """
    c = pysvn.Client()
    for record in c.ls(vers.svn_root):
        name = Path(record["name"]).name
        if name.ext != ".txt":
            continue

        parts = publish_html(c.cat(record["name"]))
        title = re.sub(r"(?i)^(chapter|appendix)\s+[A-Z0-9]+:\s*", "",
                       parts["title"])

        if name.startswith("appendix"):
            Chapter.objects.get_or_create(type="A",
                                          number=ord(name.stem[-1]) -
                                          ord('A') + 1,
                                          title=title,
                                          version=vers,
                                          defaults=dict(
                                              release_date=release_date,
                                              comments_open=comments_open,
                                          ))

        elif name.startswith("chapter"):
            Chapter.objects.get_or_create(type="C",
                                          number=int(name.stem[-2:]),
                                          title=title,
                                          version=vers,
                                          defaults=dict(
                                              release_date=release_date,
                                              comments_open=comments_open,
                                          ))
Ejemplo n.º 2
0
def chapter(request, lang, version, type, chapter):
    release, content = _get_release_or_404(lang, version, type, chapter, request.user.has_perm("djangobook.change_chapter"))
    
    parts = cache.get("djangobook:rendered_content:%s" % release.id)
    if parts is None or settings.DEBUG or request.GET.has_key("clear_cache"):
        media_base = settings.CONTENT_MEDIA_BASE + "%s/%s/%s%s/" % (
            release.version.language,
            release.version.version,
            release.get_type_display(), 
            release.get_number_url_fragment(),
        )
        parts = publish_html(content, media_base=media_base)
        cache.set("djangobook:rendered_content:%s" % release.id, parts, 5*60)
    
    return render_to_response(
        ["book/%s%s.html" % (release.get_type_display(), release.get_number_url_fragment()), "book/chapter.html"], 
        {"release" : release, "content" : parts},
        RequestContext(request, {})
    )
Ejemplo n.º 3
0
def create_chapters(vers, release_date=None, comments_open=True):
    """
    Create a bunch of ``Chapter`` objects for a given ``BookVersion``.
    """
    c = pysvn.Client()
    for record in c.ls(vers.svn_root):
        name = Path(record["name"]).name
        if name.ext != ".txt":
            continue
        
        parts = publish_html(c.cat(record["name"]))
        title = re.sub(r"(?i)^(chapter|appendix)\s+[A-Z0-9]+:\s*", "", parts["title"])
        
        if name.startswith("appendix"):
            Chapter.objects.get_or_create(
                type = "A",
                number = ord(name.stem[-1]) - ord('A') + 1,
                title = title,
                version = vers,
                defaults = dict(
                    release_date = release_date,
                    comments_open = comments_open,
                )
            )
        
        elif name.startswith("chapter"):
            Chapter.objects.get_or_create(
                type = "C",
                number = int(name.stem[-2:]),
                title = title,
                version = vers,
                defaults = dict(
                    release_date = release_date,
                    comments_open = comments_open,
                )
            )
Ejemplo n.º 4
0
def rst(text):
    return mark_safe(publish_html(text)['body'])
Ejemplo n.º 5
0
def rst(text):
    return mark_safe(publish_html(text)['body'])