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


Python models.BlogPost类代码示例

本文整理汇总了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,)))
开发者ID:kevinmarsh,项目名称:DjangoBlog,代码行数:25,代码来源:views.py

示例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
开发者ID:tony,项目名称:django-dynamicresponse,代码行数:7,代码来源:views.py

示例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)
开发者ID:mgoeminne,项目名称:Lexpage,代码行数:56,代码来源:tests.py

示例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))
开发者ID:palasgaonkar,项目名称:Projects,代码行数:10,代码来源:views.py

示例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'))
开发者ID:ZandekA,项目名称:project_blog,代码行数:10,代码来源:views.py

示例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)
开发者ID:mgoeminne,项目名称:Lexpage,代码行数:12,代码来源:tests.py

示例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)
开发者ID:mattrowe,项目名称:fstly_blog,代码行数:15,代码来源:tests_blog.py

示例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")
开发者ID:Serge45,项目名称:djangoBlog,代码行数:15,代码来源:tests.py

示例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)
开发者ID:calvinchengx,项目名称:O-Kay-Blog-wih-Kay-0.10.0,代码行数:33,代码来源:generators.py

示例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))
开发者ID:bensums,项目名称:blog-exercise,代码行数:7,代码来源:views.py

示例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)
开发者ID:calvinchengx,项目名称:O-Kay-Blog-wih-Kay-0.10.0,代码行数:7,代码来源:admin.py

示例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")
开发者ID:ramuta,项目名称:simple-blog,代码行数:8,代码来源:views.py

示例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()
开发者ID:kitanata,项目名称:SpeakerMotion2,代码行数:7,代码来源:speakerdata.py

示例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")
开发者ID:ramuta,项目名称:simple-blog,代码行数:18,代码来源:views.py

示例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()
开发者ID:mgoeminne,项目名称:Lexpage,代码行数:10,代码来源:tests.py


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