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


Python models.FlatPage类代码示例

本文整理汇总了Python中django.contrib.flatpages.models.FlatPage的典型用法代码示例。如果您正苦于以下问题:Python FlatPage类的具体用法?Python FlatPage怎么用?Python FlatPage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_get_absolute_url_honors_script_prefix

 def test_get_absolute_url_honors_script_prefix(self):
     pf = FlatPage(title="Tea!", url='/tea/')
     set_script_prefix('/beverages/')
     try:
         self.assertEqual(pf.get_absolute_url(), '/beverages/tea/')
     finally:
         clear_script_prefix()
开发者ID:SvetlanaM,项目名称:EnabledCityPaloAlto,代码行数:7,代码来源:test_models.py

示例2: forwards

 def forwards(self, orm):
     "Write your forwards methods here."
     # Note: Don't use "from appname.models import ModelName". 
     # Use orm.ModelName to refer to models in this application,
     # and orm['appname.ModelName'] for models in other applications.
     s = Site.objects.get(id='1')
     f = FlatPage(url='/data-archiving/', title='Data Archiving', content='(info about data archiving)')
     f.save()
     f.sites.add(s)
     f.save()
开发者ID:mprefer,项目名称:OpenEmory,代码行数:10,代码来源:0015_add_data_archive.py

示例3: startpage

def startpage(request):
    page = FlatPage.objects.filter(url="/")
    if page:
        page = page[0]
    else:
        page = FlatPage("/", "Welcome", "<h1>Hello World!</h1>")
        page.save()
    news = News.active_objects.all()[:5]
    return render_to_response('news/startpage.html',  {"latest_news": news,
                                                       "start_title": page.title, 
                                                       "content": page.content}, 
                              context_instance=RequestContext(request))
开发者ID:gdos,项目名称:pygame,代码行数:12,代码来源:views.py

示例4: newpage

def newpage(request, url):
    """
    New Flat page wiki view.

    template hardcoded for now
    """

    if not request.user.is_authenticated():
        raise Http404
    
    from urlparse import urlparse
    # if referer then use it or default '/'
    ref = urlparse(request.META.get('HTTP_REFERER', ''))[2]
    # use hidden field if it's there
    ref = request.REQUEST.get('ref', ref)
    if ref == '':
        ref = '/'

    #return render_to_response(DEFAULT_TEMPLATE_NEW,  
    #    RequestContext( request, { 'url': url, 'ref': ref } ))
    
    if request.method == 'POST':
        if request.POST['result'] == 'Cancel':
            return HttpResponseRedirect(ref)
        else:
            form = WikiPageForm(request.POST)
            if form.is_valid():
                try:
                    f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=settings.SITE_ID)
                except Http404:
                    f = FlatPage()
                    f.url = str(form.clean()['url'])
                    f.title = form.clean()['title']
                    f.content = str(form.clean()['content'])
                    f.enable_comments = False
                    f.registration_required = False
                    f.save()
                    # need to save get a pk before adding a M2M
                    s = Site.objects.get_current()
                    f.sites.add(s)
                    f.save()
                    return HttpResponseRedirect(f.url)

    else:
        form = WikiPageForm({'url': url, })
        form.ignore_errors = True
        #form.errors().clear()

    response = render_to_response(DEFAULT_TEMPLATE_NEW,  
        RequestContext( request, { 'form': form, 'ref': ref }) )
    #populate_xheaders(request, response, FlatPage, f.id)
    return response
开发者ID:pombredanne,项目名称:django-flatpagewiki,代码行数:52,代码来源:views.py

示例5: test_create_flat_page

    def test_create_flat_page(self):
        page = FlatPage()
        page.url = '/about'
        page.title = 'About me'
        page.content = "All about me"
        page.save()

        page.sites.add(Site.objects.all()[0])
        page.save()

        all_pages = FlatPage.objects.all()
        self.assertEqual(len(all_pages), 1)
        only_page = all_pages[0]
        self.assertEqual(only_page, page)

        self.assertEquals(only_page.url, '/about')
        self.assertEquals(only_page.title, 'About me')
        self.assertEquals(only_page.content, 'All about me')

        page_url = reverse(
            'django.contrib.flatpages.views.flatpage',
            kwargs={'url': 'about'}
        )

        response = self.client.get(page_url)
        self.assertEqual(response.status_code, 200)

        self.assertTrue('About me' in response.content)
        self.assertTrue('All about me' in response.content)
开发者ID:dttt,项目名称:blog_tutorial,代码行数:29,代码来源:tests.py

示例6: test_create_flat_page

    def test_create_flat_page(self):
        # create a flat page
        page = FlatPage()
        page.url = '/about/'
        page.title = 'About me'
        page.content = 'All about me'
        page.save()
        page.sites.add(Site.objects.all()[0])
        page.save()

        # check the new page is saved
        all_pages = FlatPage.objects.all()
        self.assertEqual(len(all_pages), 1)
        only_page = all_pages[0]
        self.assertEqual(only_page, page)

        # check the data of the page
        self.assertEquals(only_page.url, page.url)
        self.assertEquals(only_page.title, page.title)
        self.assertEquals(only_page.content, page.content)

        # check the page url
        page_url = only_page.get_absolute_url()
        response = self.client.get(page_url)
        self.assertEquals(response.status_code, 200)
开发者ID:salmanwahed,项目名称:django_blog_ng,代码行数:25,代码来源:tests.py

示例7: test_create_flat_page

    def test_create_flat_page(self):

        page = FlatPage()
        page.url = '/about/'
        page.title = 'About me'
        page.content = 'All about me'
        page.save()

        page.sites.add(Site.objects.all()[0])
        page.save()

        all_pages = FlatPage.objects.all()
        self.assertEquals(len(all_pages), 1)
        only_page = all_pages[0]
        self.assertEquals(only_page, page)

        self.assertEquals(only_page.url, '/about/')
        self.assertEquals(only_page.title, 'About me')
        self.assertEquals(only_page.content, 'All about me')

        page_url = only_page.get_absolute_url()

        response = self.client.get(page_url)
        self.assertEquals(response.status_code, 200)

        self.assertTrue('About me' in response.content)
        self.assertTrue('All about me' in response.content)
开发者ID:thanley11,项目名称:tomblog,代码行数:27,代码来源:tests.py

示例8: test_create_flat_page

    def test_create_flat_page(self):
        # Create flat page
        page = FlatPage()
        page.url = "/about/"
        page.title = "About me"
        page.content = "All about me"
        page.save()

        # Add the site
        page.sites.add(Site.objects.all()[0])
        page.save()

        # Check new page saved
        all_pages = FlatPage.objects.all()
        self.assertEquals(len(all_pages), 1)
        only_page = all_pages[0]
        self.assertEquals(only_page, page)

        # Check data correct
        self.assertEquals(only_page.url, "/about/")
        self.assertEquals(only_page.title, "About me")
        self.assertEquals(only_page.content, "All about me")

        # Get URL
        page_url = str(only_page.get_absolute_url())

        # Get the page
        response = self.client.get(page_url)
        self.assertEquals(response.status_code, 200)

        # Check title and content in response
        self.assertTrue("About me" in response.content)
        self.assertTrue("All about me" in response.content)
开发者ID:Zna12,项目名称:blog-project,代码行数:33,代码来源:tests.py

示例9: create_about_page

def create_about_page(app, created_models, verbosity, **kwargs):
    from django.contrib.flatpages.models import FlatPage
    from django.contrib.sites.models import Site
    if FlatPage not in created_models:
        return
    if FlatPage.objects.count():
        return
    text = '''Hello, I'm default about page.

Please change me in admin. I'm also known as FlatPage.'''
    about = FlatPage(url='/about/', title='About', content=text,
                     enable_comments=False, registration_required=False)
    about.save()
    about.sites.add(*Site.objects.all())
开发者ID:gvidon,项目名称:blombum,代码行数:14,代码来源:__init__.py

示例10: test_create_flat_page

    def test_create_flat_page(self):
        # create flat page
        page = FlatPage()
        page.url = '/about/'
        page.title = 'About me'
        page.content = 'All about me'
        page.save()

        # add the site
        page.sites.add(Site.objects.all()[0])
        page.save()

        # check new page saved
        all_pages = FlatPage.objects.all()
        self.assertEquals(len(all_pages),1)
        only_page = all_pages[0]
        self.assertEquals(only_page, page)

        # check data correct
        self.assertEquals(only_page.url, '/about/')
        self.assertEquals(only_page.title, 'About me')
        self.assertEquals(only_page.content, 'All about me')

        # get url
        page_url = str(only_page.get_absolute_url())

        # get the page
        response = self.client.get(page_url)
        self.assertEquals(response.status_code, 200)

        # check title and content in response
        self.assertTrue('About me' in response.content)
        self.assertTrue('All about me' in response.content)
开发者ID:jwillet1,项目名称:djangoblog,代码行数:33,代码来源:tests.py

示例11: test_create_flat_page

    def test_create_flat_page(self):
        page = FlatPage()
        page.url = '/about/'
        page.title = 'about me'
        page.content = 'something about me'
        page.save()

        page.sites.add(Site.objects.all()[0])
        page.save()

        all_pages = FlatPage.objects.all()
        self.assertEquals(len(all_pages),1)
        self.assertEqual(all_pages[0],page)

        p = all_pages[0]
        self.assertEquals(p.url,page.url)
        self.assertEquals(p.title,page.title)
        self.assertEquals(p.content,page.content)

        p_url = p.get_absolute_url()

        r = self.client.get(p_url)
        self.assertEquals(r.status_code,200)
        self.assertTrue(page.title in r.content)
        self.assertTrue(page.content in r.content)
开发者ID:paulw54jrn,项目名称:blog_tutorial,代码行数:25,代码来源:tests.py

示例12: flatpage

def flatpage(request, url):
    """
    Extended editable flat page view.

    Models: `flatpages.flatpages`
    Templates: Uses the template defined by the ``template_name`` field,
        or `flatpages/default.html` if template_name is not defined.
    Context:
        flatpage
            `flatpages.flatpages` object
    """
    if not request.GET.get('action') in ('create', 'edit', 'delete'):
        return flatpage_detail(request, url)
    if not url.endswith('/') and settings.APPEND_SLASH:
        return HttpResponseRedirect("%s/" % request.path)
    if not url.startswith('/'):
        url = "/" + url
    f = get_object_or_none(FlatPage, url__exact=url, sites__id__exact=settings.SITE_ID)
    if not f:
        if not request.user.has_perm('flatpages.add_flatpage'):
            raise Http404
        f = FlatPage(url=url)
    # If registration is required for accessing this page, and the user isn't
    # logged in, redirect to the login page.
    if f and f.registration_required and not request.user.is_authenticated():
        from django.contrib.auth.views import redirect_to_login
        return redirect_to_login(request.path)
    if request.method == 'POST':
        form = FlatPageEditForm(request.POST, instance=f)
        if form.is_valid(): # All validation rules pass
            f.save()
            current_site = Site.objects.get_current()
            if not current_site in f.sites.all():
                # Assign page to current site
                f.sites.add(current_site)
                f.save()
            msg = _("The %(verbose_name)s was updated successfully.") %\
                {"verbose_name": FlatPage._meta.verbose_name}
            messages.success(request, msg, fail_silently=True)
            return HttpResponseRedirect(f.url)
    else:
        if request.GET.get('action') == 'delete':
            f.delete()
            msg = _("The %(verbose_name)s was deleted.") %\
                {"verbose_name": FlatPage._meta.verbose_name}
            messages.success(request, msg, fail_silently=True)
            return HttpResponseRedirect('/')
        form = FlatPageEditForm(instance=f)
    if f.template_name:
        t = loader.select_template((f.template_name, DEFAULT_TEMPLATE))
    else:
        t = loader.get_template(DEFAULT_TEMPLATE)

    c = RequestContext(request, {
        'form': form,
        'flatpage': f,
    })
    response = HttpResponse(t.render(c))
    populate_xheaders(request, response, FlatPage, f.id)
    return response
开发者ID:hawkerpl,项目名称:k2,代码行数:60,代码来源:views.py

示例13: handle

    def handle(self, *args, **options):

        try:
            site = Site.objects.get()
        except Site.DoesNotExist:
            site = Site()
        if args:
            if len(args) > 1:
                raise CommandError('Command accept at most one parameter.')
            site.domain = args[0]
            site.name = args[0]
        else:
            hostname = get_host_name()
            site.domain = hostname
            site.name = hostname
        site.save()

        try:
            page = FlatPage.objects.get(url='/getting-started/')
            page.sites = [site]
            page.save()
        except FlatPage.DoesNotExist:
            page = FlatPage(url='/getting-started/', title='Getting Started', registration_required=False)
            page.content = 'Go to admin panel to change welcome message!'
            page.save()
            page.sites = [site]
            page.save()
开发者ID:stfc,项目名称:cvmfs-stratum-uploader,代码行数:27,代码来源:init_flatpages.py

示例14: forwards

 def forwards(self, orm):
     """
     not going through the south db orm, but this seems to work anyway
     """
     page_data = [{'url': '/about/',
                   'title': u'About',
                   'content': u'Stub about flatpage',
                   },
                  {'url': '/contact/',
                   'title': 'Contact',
                   'content': u'Stub contact flatpage',
                   },
                  {'url': '/faq/',
                   'title': 'Faq',
                   'content': u'Stub faq flatpage',
                   },
                  {'url': '/press/',
                   'title': 'Press',
                   'content': u'Stub press flatpage',
                   },
                  {'url': '/tools-and-tips/',
                   'title': 'Tools and tips',
                   'content': u'Tools and tips flatpage',
                   },
                  {'url': '/placement-guide/',
                   'title': 'Placement guide',
                   'content': u'Placement guide flatpage',
                   },
                  ]
     # XXX use the first site
     site = Site.objects.all()[0]
     for page in page_data:
         if len(FlatPage.objects.filter(url=page['url'])) == 0:
             flatpage = FlatPage(enable_comments=False,
                                 registration_required=False,
                                 template_name='',
                                 **page)
             flatpage.save()
             flatpage.sites.add(site)
             flatpage.save()
开发者ID:natea,项目名称:fixcity,代码行数:40,代码来源:0008_add_flatpages.py

示例15: test_filmaster_recommends

    def test_filmaster_recommends(self):
        """
            Test filmaster recommends
        """

        fp = FlatPage()
        fp.url = "filmaster-recommends"
        fp.title = "Title"
        fp.content = "Lorem ipsum"
        fp.save()

        flp = filmaster_recommends()
        flat_page = flp['flat_page']
        self.failUnlessEqual(flat_page.title, "Title")
        self.failUnlessEqual(flat_page.content, "Lorem ipsum")
开发者ID:yangjiandong,项目名称:filmaster,代码行数:15,代码来源:test_templatetags.py


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