本文整理汇总了Python中django.contrib.flatpages.models.FlatPage.save方法的典型用法代码示例。如果您正苦于以下问题:Python FlatPage.save方法的具体用法?Python FlatPage.save怎么用?Python FlatPage.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.flatpages.models.FlatPage
的用法示例。
在下文中一共展示了FlatPage.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_flat_page
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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)
示例2: test_create_flat_page
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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)
示例3: test_create_flat_page
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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)
示例4: test_create_flat_page
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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)
示例5: test_create_flat_page
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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)
示例6: handle
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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()
示例7: test_create_flat_page
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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)
示例8: flatpage
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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
示例9: forwards
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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()
示例10: startpage
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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))
示例11: newpage
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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
示例12: create_about_page
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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())
示例13: test_filmaster_recommends
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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")
示例14: getcontent
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
def getcontent(context, url, default=None):
url = "%s%s/" % (HIDDEN_PAGE_PREFIX, url)
try:
page = FlatPage.objects.get(url=url)
except FlatPage.DoesNotExist:
page = FlatPage(url=url, content=default or "Change Me!", title=url.strip("/"))
page.save()
page.sites = Site.objects.all()
page.save()
if context.get('user', None) and getattr(context['user'], "is_staff", False) and page.pk:
edit_url = reverse("pages-edit", args=[page.pk]) + "?next=" + getattr(context.get("request"), "get_full_path", lambda: "")()
page.content += "<a class='getcontent-edit' href='%s'>Edit</a>" % edit_url
return mark_safe(page.content)
示例15: forwards
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import save [as 别名]
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()