本文整理汇总了Python中blog.models.BlogPost类的典型用法代码示例。如果您正苦于以下问题:Python BlogPost类的具体用法?Python BlogPost怎么用?Python BlogPost使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BlogPost类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self, request):
subject = request.POST['subject']
content = request.POST['content']
slug = titleToUrl(subject)
published = request.POST['published'] == 'published'
if not subject:
messages.add_message(request, messages.INFO, 'Please add a subject.')
if not content:
messages.add_message(request, messages.INFO, 'Please add some content.')
if not BlogPost.objects.filter(slug=slug).count() == 0:
messages.add_message(request, messages.INFO, 'Please rename, you\'ve used that title before.')
if messages.get_messages(request):
params = {'subject': subject,
'content': content,
'published': published}
return render(request, 'blog_create.html', params)
else:
post = BlogPost(title=subject,
body=content,
slug=slug,
published=published)
post.save()
messages.add_message(request, messages.SUCCESS, 'Blog post created.')
return HttpResponseRedirect(reverse('blog_SinglePost', args=(slug,)))
示例2: setUp
def setUp(self):
# Create an initial object to test with
post = BlogPost(title=u'Hello Wørld', text=u'Hello World, this is dynamicresponse. ÆØÅæøå.')
post.save()
self.post = post
示例3: StatusTests
class StatusTests(TestCase):
fixtures = ['devel']
def setUp(self):
self.client.login(username='admin', password='admin')
self.user = ActiveUser.objects.filter(username='admin')[0]
self.post = BlogPost(title='Hello World!',
author=self.user,
tags='hello world',
abstract='Hello World!',
text='Hello World!',
priority=BlogPost.PRIORITY_NORMAL)
self.post.save()
self.url = reverse('blog_pending_edit', kwargs={'pk': self.post.pk})
self.form = {
'title': self.post.title,
'abstract': self.post.abstract,
'tags': self.post.tags,
'text': self.post.text,
'priority': self.post.priority
}
def test_draft(self):
self.form['action'] = UserCreatePostForm.ACTION_DRAFT
response = self.client.post(self.url, self.form, follow=True)
self.post.refresh_from_db()
self.assertEqual(response.status_code, 200)
self.assertLessEqual((datetime.datetime.now() - self.post.date_modified).total_seconds(), 10)
def test_submitted(self):
self.post.status = BlogPost.STATUS_DRAFT
self.post.save()
self.form['action'] = UserCreatePostForm.ACTION_SUBMIT
response = self.client.post(self.url, self.form, follow=True)
self.assertEqual(response.status_code, 200)
def test_approved(self):
self.form['action'] = UserCreatePostForm.ACTION_APPROVE
response = self.client.post(self.url, self.form, follow=True)
self.post.refresh_from_db()
self.assertEqual(response.status_code, 200)
self.assertLessEqual((datetime.datetime.now() - self.post.date_approved).total_seconds(), 10)
def test_published(self):
self.form['action'] = UserCreatePostForm.ACTION_PUBLISH
response = self.client.post(self.url, self.form, follow=True)
self.post.refresh_from_db()
self.assertEqual(response.status_code, 200)
self.assertLessEqual((datetime.datetime.now() - self.post.date_published).total_seconds(), 10)
def test_reject(self):
self.form['action'] = UserCreatePostForm.ACTION_DELETE
response = self.client.post(self.url, self.form, follow=True)
self.assertEqual(response.status_code, 200)
示例4: save
def save(request, url):
posts = BlogPost.objects.all()
for post in posts:
if post.id == int(url):
b = BlogPost(body=request.GET.get('body'), title=request.GET.get('title'), id=post.id,
timestamp=timezone.now())
b.save()
t = loader.get_template("article.html")
c = Context({'post': b})
return HttpResponse(t.render(c))
示例5: add_post
def add_post(request):
get_title = request.POST['post_title']
get_post_image = request.FILES.get('post_image', None)
get_content = request.POST['post_content']
get_content_preview = content_preview_text_gen(get_content)
get_datetime = timezone.now()
get_user = request.user
p = BlogPost(title=get_title, post_image=get_post_image, content=get_content, content_preview=get_content_preview, datetime=get_datetime, author=get_user)
p.save()
return HttpResponseRedirect(reverse('blog:index'))
示例6: test_drafedit
def test_drafedit(self):
post = BlogPost(title='Hello World!',
author=self.user,
tags='hello world',
abstract='Hello World!',
text='Hello World!',
priority=BlogPost.STATUS_DRAFT)
post.save()
url = reverse('blog_draft_edit', kwargs={'pk': post.pk})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
示例7: test_blog
def test_blog(self):
blog = Blog(title="test blog")
blog.save()
self.assertIsInstance(blog, Blog)
blog_post = BlogPost(blog=blog, title="test post",
content="this is content")
blog_post.save()
self.assertIsInstance(blog_post, BlogPost)
get_by_slug = BlogPost.objects.get_by_slug(blog_post.slug)
self.assertIsInstance(get_by_slug, BlogPost)
homepage = BlogPost.objects.homepage_posts()
self.assertEquals(len(homepage), 1)
示例8: test_create_post
def test_create_post(self):
user = User.objects.get(username='AAA')
post = BlogPost(user=user)
post.title = "My test post"
post.content = "This is a test post"
post.save()
all_posts = BlogPost.objects.all()
self.assertEquals(len(all_posts), 1)
only_post = all_posts[0]
self.assertEquals(only_post, post)
self.assertEquals(only_post.title, "My test post")
示例9: generate_resource
def generate_resource(cls, post, resource, pagenum=1, start_ts=None):
from blog.models import BlogPost
q = BlogPost.all().order('-published')
q.filter('published <', start_ts or datetime.datetime.max)
cls._filter_query(resource, q)
posts = q.fetch(config.posts_per_page + 1)
more_posts = len(posts) > config.posts_per_page
path_args = {
'resource': resource,
}
path_args['pagenum'] = pagenum - 1
prev_page = cls.path % path_args
path_args['pagenum'] = pagenum + 1
next_page = cls.path % path_args
template_vals = {
'posts': posts[:config.posts_per_page],
'prev_page': prev_page if pagenum > 1 else None,
'next_page': next_page if more_posts else None,
'config': config,
}
template_name = "blog/themes/%s/listing.html" % config.theme
rendered = utils.render_template(template_name, template_vals)
path_args['pagenum'] = pagenum
StaticContent.set(cls.path % path_args, rendered, config.html_mime_type)
if pagenum == 1:
StaticContent.set(cls.first_page_path % path_args, rendered, config.html_mime_type)
if more_posts:
deferred.defer(cls.generate_resource, None, resource, pagenum + 1,
posts[-2].published)
示例10: post_detail
def post_detail(request, blog_name=None, post_key_name=None):
post = BlogPost.get_by_key_name(post_key_name,
parent=db.Key.from_path('Blog', blog_name))
if not post:
return HttpResponse404()
return render_to_response('post_detail.html', {'post': post},
RequestContext(request))
示例11: decorate
def decorate(self, post_id=None):
post = None
if post_id:
post = BlogPost.get_by_id(int(post_id))
if not post:
raise NotFound
return fun(self, post)
示例12: post_delete
def post_delete(request, post_id):
post = BlogPost.get_by_id(int(post_id))
user = users.get_current_user()
if request.method == "POST" and post.author == user.email():
post.key.delete()
return redirect("home")
else:
return redirect("forbidden")
示例13: generate_blog_post
def generate_blog_post():
post = BlogPost()
post.name = random.choice(long_actions)
post.content = user_description
post.date = generate_datetime()
post.published = True
post.save()
示例14: post_add
def post_add(request):
if request.method == "GET":
form = BlogPostForm()
params = {"form": form}
return blog_render(request, "post_add.html", params)
elif request.method == "POST":
form = BlogPostForm(request.POST)
if form.is_valid():
BlogPost.create(title=form.cleaned_data["title"],
content=form.cleaned_data["content"],
author=users.get_current_user().email())
else:
params = {"form": form}
return blog_render(request, "post_add.html", params)
return redirect("home")
示例15: setUp
def setUp(self):
self.client.login(username='admin', password='admin')
self.user = ActiveUser.objects.filter(username='admin')[0]
self.post = BlogPost(title='Hello World!',
author=self.user,
tags='hello world',
abstract='Hello World!',
text='Hello World!',
priority=BlogPost.STATUS_SUBMITTED)
self.post.save()