当前位置: 首页>>代码示例>>Python>>正文


Python Page.content方法代码示例

本文整理汇总了Python中models.Page.content方法的典型用法代码示例。如果您正苦于以下问题:Python Page.content方法的具体用法?Python Page.content怎么用?Python Page.content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Page的用法示例。


在下文中一共展示了Page.content方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: edit

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import content [as 别名]
def edit(request, name):
    """Allows users to edit wiki pages."""
    try:
        page = Page.objects.get(name=name)
    except Page.DoesNotExist:
        page = None

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if not page:
                page = Page()
            page.name = form.cleaned_data['name']
            page.content = form.cleaned_data['content']

            page.save()
            return redirect(view, name=page.name)
    else:
        if page:
            form = PageForm(initial=page.__dict__)
        else:
            form = PageForm(initial={'name': name})

    context = {
        'form': form,
    }

    return render_to_response('wiki/edit.html',
        RequestContext(request, context))
开发者ID:zouf,项目名称:AllSortz,代码行数:31,代码来源:views.py

示例2: create_page

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import content [as 别名]
def create_page(db, page):
    new_data = Page()
    new_data.title = unicode(page['title'])
    new_data.content = unicode(page["content"])
    new_data.css = unicode(page['css'])
    new_data.book_id = int(page["book_id"])
    db.session.add(new_data)
开发者ID:Nauja,项目名称:ProjetLivre,代码行数:9,代码来源:db.py

示例3: edit

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import content [as 别名]
def edit(request, name):
    """Allows users to edit wiki pages."""
    try:
        page = Page.objects.get(name=name)
    except Page.DoesNotExist:
        page = None

    if request.method == "POST":
        form = PageForm(request.POST)
        if form.is_valid():
            if not page:
                page = Page()
            page.name = form.cleaned_data["name"]
            page.content = form.cleaned_data["content"]

            page.save()
            return HttpResponseRedirect("../../%s/" % page.name)
    else:
        if page:
            form = PageForm(initial=page.__dict__)
        else:
            form = PageForm(initial={"name": name})

    return render_to_response(
        "wiki/edit.html",
        {
            "form": form,
            "admin": is_admin(request),
            "user": get_user(request),
            "navbar": Page.objects.get(name="NavBar"),
        },
    )
开发者ID:victorusachev,项目名称:djangy,代码行数:34,代码来源:views.py

示例4: page_update_or_create

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import content [as 别名]
def page_update_or_create(name, content):
    """Update or create a Wiki Page"""
    try:
        p = Page.objects.get(name=name)
    except Page.DoesNotExist:
        p = Page(name=name)
    finally:
        p.content = content
        p.save()
开发者ID:honestappalachia,项目名称:honestappalachia,代码行数:11,代码来源:views.py

示例5: post

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import content [as 别名]
    def post(self, slug=None):
        if slug:
            page = Page.gql("WHERE slug = :1", slug).get()
        else:
            page = Page()
        page.title = self.request.get('title')
        page.slug = self.request.get('slug')
        page.content = self.request.get('content')
        page.order_in_menu = int(self.request.get('order_in_menu'))

        page.put()

        self.redirect(page.get_url())
开发者ID:ibz,项目名称:nuages,代码行数:15,代码来源:admin.py

示例6: edit

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import content [as 别名]
def edit(request, name):
    if not request.user.is_authenticated():
        raise Http404

    page = get(Page, name, True)

    if request.method == "POST":
        form = PageForm(request.POST)
        if form.is_valid():
            if not page:
                page = Page()
            page.name = form.cleaned_data["name"]
            page.content = form.cleaned_data["content"]
            page.author = request.user
            page.tags = " ".join(filter(None, name.split("/")))
            page.save()
            return HttpResponseRedirect("%s" % urlquote(page.get_path()))
    else:
        if page:
            form = PageForm(initial=page.__dict__)
        else:
            form = PageForm(initial={"name": name})
    return render_to_response("edit.html", {"form": form})
开发者ID:master,项目名称:nord-engine,代码行数:25,代码来源:views.py

示例7: save

# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import content [as 别名]
def save(user_slug, wiki_slug, page_slug):
    """ Saves page changes in the database.
    -] patch - array of changed content blocks; 'undefined' if unchanged
    <- slugified page title
    """ 
    user = User.get_by(name_slug=user_slug)
    if user != g.user:
        return False
    wiki = user.wiki_by_slug(wiki_slug)
    try:
        page = wiki.page_by_slug(page_slug)
    except NoResultFound:
        old_last_page = Page.get_by(wiki=wiki, next_page_id=-1)
        page = Page(wiki=wiki, title="", title_slug="", 
            content="<h1>Untitled</h1>", next_page_id=-1)
        models.session.commit()
        old_last_page.next_page_id = page.id
    patch = request.form.getlist('patch')
    block = re.compile('<(?:h1|h2|h3|p)>.*?</(?:h1|h2|h3|p)>')
    content_blocks = block.findall(page.content)
    # If the page's title has been changed in the content...
    new_title = page.title
    if len(patch) and patch[0] != 'undefined':
        new_title = patch[0][4:-5]
        newline = re.compile('\n')
        new_title = re.sub(newline, "", new_title)
    if page.title != new_title:
        # ..if a page exists with this title, append " (alternative)" to it.
        try:
            same_title_page = Page.get_by(title=new_title)
        except NoResultFound:
            pass
        if same_title_page:
            stp = same_title_page
            header_end = 4 + len(stp.title)
            stp.title += " (alternative)"
            stp.title_slug = slugify(stp.title)
            stp.content = stp.content[:header_end] + " (alternative)" + \
                stp.content[header_end:]
        # ..if the page with changed title was the main page, make a new one.
        if page.title == wiki.title:
            try:
                if new_title:
                    second_page = page
                else:
                    second_page = Page.get_by(id=page.next_page_id)
                next_page_id = second_page.id
            except NoResultFound:
                next_page_id = -1
            new_main_page = Page(wiki=wiki, title=wiki.title, 
                title_slug=slugify(wiki.title), 
                content="<h1>%s</h1><p></p>" % wiki.title, 
                next_page_id=next_page_id)
            models.session.commit()
            wiki.first_page_id = new_main_page.id
        # ..change the page's title in the database.
        page.title = new_title
        page.title_slug = slugify(new_title)
    # Replace content with patched content.
    for i, block in enumerate(patch):
        if block != 'undefined':
            if i < len(content_blocks):
                content_blocks[i] = block
            else:
                content_blocks.append(block)
    # Sanitize unsafe angle brackets.
    content = ''.join(content_blocks)
    unsafe_lt = re.compile(r"<(?!/?(h1|h2|h3|p|b|i|u)>)")
    content = re.sub(unsafe_lt, '&lt;', content)
    # The content is reversed to get around regex lookbehind limitation.
    unsafe_gt = re.compile(r">(?!(1h|2h|3h|p|b|i|u)/?<)")
    content = re.sub(unsafe_gt, ';tg&', content[::-1])
    page.content = content[::-1]
    # If the title is blank, delete the page.
    deleted = False
    blank_title = re.compile('<h1>(<br>)*</h1>')
    if blank_title.match(page.content):
        try:
            previous_page = Page.get_by(wiki=wiki, next_page_id=page.id)
            previous_page.next_page_id = page.next_page_id
        except NoResultFound:
            pass
        page.delete()
        deleted = True
    # Update the wiki's update date.
    wiki.update_date = datetime.now()
    # Commit to database!
    models.session.commit()
    if not deleted:
        return slugify(page.title)
    else:
        return "untitled!"
开发者ID:aostrega,项目名称:piki,代码行数:94,代码来源:piki.py


注:本文中的models.Page.content方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。