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


Python Article.save方法代码示例

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


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

示例1: article_add

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
def article_add(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        tag = TagForm(request.POST)
        classification = ClassificationForm(request.POST)
        if form.is_valid() and tag.is_valid() and classification.is_valid():
            cd = form.cleaned_data
            cdtag = tag.cleaned_data
            cdclassification = classification.cleaned_data
            tagname = cdtag['tag_name']
            classification_name = cdclassification["classification_name"]
            for taglist in tagname.split():
                Tag.objects.get_or_create(tag_name=taglist.strip())
            if classification_name != "":
                 Classification.objects.get_or_create(name=classification_name.strip())
            title = cd['caption']
            author = Author.objects.get(id=1)
            content = cd['content']
            article = Article(caption=title, author=author, content=content)
            article.classification = Classification.objects.get(name=classification_name.strip())
            article.save()
            for taglist in tagname.split():
                article.tags.add(Tag.objects.get(tag_name=taglist.strip()))
                article.save()
            id = Article.objects.order_by('-publish_time')[0].id
            return HttpResponseRedirect('/blog/article/%s/%s/' % ('/'.join(str(article.publish_time).split()[0].split('-')), id))
    else:
        form = ArticleForm()
        tag = TagForm(initial={'tag_name': 'notags'})
        classification = ClassificationForm()
    return render_to_response('article_add.html',
        {}, context_instance=RequestContext(request))
开发者ID:okhyf,项目名称:Eleven,代码行数:34,代码来源:views.py

示例2: test_validate_account

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
    def test_validate_account(self):
        site = Site.objects.get_current().domain
        user = BlogUser.objects.create_superuser(email="[email protected]",
                                                 username="liangliangyy1", password="liangliangyy1")

        self.client.login(username='liangliangyy1', password='liangliangyy1')
        response = self.client.get('/admin/')
        self.assertEqual(response.status_code, 200)

        category = Category()
        category.name = "categoryaaa"
        category.created_time = datetime.datetime.now()
        category.last_mod_time = datetime.datetime.now()
        category.save()

        article = Article()
        article.title = "nicetitleaaa"
        article.body = "nicecontentaaa"
        article.author = user
        article.category = category
        article.type = 'a'
        article.status = 'p'
        article.save()

        response = self.client.get(article.get_admin_url())
        self.assertEqual(response.status_code, 200)
开发者ID:lutianba2014,项目名称:DjangoBlog,代码行数:28,代码来源:tests.py

示例3: edit

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
def edit(request):
    if request.method == 'GET':
        if 'arid' in request.GET:
            context = {}
            arid = request.GET['arid']
            article = Article.objects.filter(id=arid)[0]
            context['art'] = article
            return render(request,'edit.html',context)
        elif 'username' in request.session:
            context = {}
            context['name'] = Constant.BLOG_NAME
            return render(request,'edit.html',context)
        else:
            return HttpResponseRedirect('/')
    else:#POST commit
        if 'id' in request.POST:
            article = Article.objects.get(id=request.POST['id'])
            article.title = request.POST['title']
            article.content = request.POST['content']
            article.save()
            return HttpResponseRedirect('/')
        else:
            un = _get_name(request)
            article = Article(title=request.POST['title'] ,author=un,date=time.strftime('%Y-%m-%d',time.localtime(time.time())),content=request.POST['content'])
            article.save()
            return HttpResponseRedirect('/')
开发者ID:GarbledWang,项目名称:PyPro,代码行数:28,代码来源:views.py

示例4: create

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
def create(request):
	new_article = Article(
		title=request.POST['title'],
		body=request.POST['body'],
		created_date=datetime.datetime.now())
	new_article.save()
	return HttpResponseRedirect(reverse('blog:detail', args=(new_article.id, )))
开发者ID:tarkadaal,项目名称:ApolloBlog,代码行数:9,代码来源:views.py

示例5: handle

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
 def handle(self, *args, **options):
     superuser_username = options["superuser_username"]
     try:
         superuser = User.objects.get(username=superuser_username)
     except ObjectDoesNotExist:
         raise (CommandError(
                "Can't found the superuser with username '{}'!"
                .format(superuser_username)))
     legacy_articles = LegacyArticle.objects.all()
     for legacy_article in legacy_articles:
         article = Article()
         article.pk = legacy_article.pk
         article.author = superuser
         # MySQL returns `long` type for all `IntegerField`s.
         article.created = (datetime
                            .fromtimestamp(int(legacy_article.created)))
         # Field `last_updated` is not set always.
         if legacy_article.last_updated:
             article.modified = (datetime.fromtimestamp(
                                 int(legacy_article.last_updated)))
         article.title = legacy_article.title
         article.content = legacy_article.content
         article.slug = defaultfilters.slugify(legacy_article.title)
         if legacy_article.tweet_id:
             article.tweet_id = int(legacy_article.tweet_id)
         article.save()
     (self.stdout.write(
      "Import was successful! Total of {} articles were imported.\n"
      .format(legacy_articles.count())))
开发者ID:daGrevis,项目名称:daGrevis.lv,代码行数:31,代码来源:import_data_from_legacy.py

示例6: ajax_editor

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
def ajax_editor(request):
    # 保存文章
    # 获取作者
    user = request.user
    if not user:
        msg = "error|无法获取作者"
    else:
    # 获取前段数据    
        try:
            html = request.POST.get("html","")
            title = request.POST.get("title","")
            tag = request.POST.get("tag","")
            keys = request.POST.get("keys","")
            id = request.POST.get("id","")
        except Exception as e:
            print(e)
            msg = u"error|前端数据获取失败"
            print msg
        else:
            # 前端没有id传过来则新建
            # 有id传过来则更新
            if not id:
            # script过滤
                html = re_js(html)
                title = re_js(title)
                tag = re_js(tag)
                keys = re_js(keys)

                try:
                    article = Article(title=title,
                                      user = user,
                                      article_class=tag,
                                      keyword=keys,
                                      content = html)
                    article.save()
                except Exception as e:
                    print(e)
                    msg = "error|文章保存失败"
                else:
                    msg = "ok|保存成功"
            else:
                try:
                    article = Article.objects.filter(id=id)
                    # 权限检查 操作和数据库中记录的用户不是一个人则抛出异常,无权修改.超级管理员有权修改
                    if article[0].user == user or user.is_superuser:
                        article.update(title=title,
                                       user = user,
                                       article_class=tag,
                                       keyword=keys,
                                       content = html)
                    else:
                        msg ="error|你没有修改权限"
                        print(msg)
                        raise Exception(msg)
                except Exception as e:
                    print(e)
                    msg = "error|更新失败"
                else:
                    msg = "ok|更新成功"
    return HttpResponse(msg)
开发者ID:coldfreeboy,项目名称:blog,代码行数:62,代码来源:views.py

示例7: test_validate_comment

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
    def test_validate_comment(self):
        site = Site.objects.get_current().domain
        user = BlogUser.objects.create_superuser(email="[email protected]",
                                                 username="liangliangyy1", password="liangliangyy1")

        self.client.login(username='liangliangyy1', password='liangliangyy1')

        c = Category()
        c.name = "categoryccc"
        c.created_time = datetime.datetime.now()
        c.last_mod_time = datetime.datetime.now()
        c.save()

        article = Article()
        article.title = "nicetitleccc"
        article.body = "nicecontentccc"
        article.author = user
        article.category = c
        article.type = 'a'
        article.status = 'p'
        article.save()
        s = TextMessage([])
        s.content = "nicetitleccc"
        rsp = search(s, None)
        self.assertTrue(rsp != '没有找到相关文章。')
        rsp = category(None, None)
        self.assertIsNotNone(rsp)
        rsp = recents(None, None)
        self.assertTrue(rsp != '暂时还没有文章')

        cmd = commands()
        cmd.title = "test"
        cmd.command = "ls"
        cmd.describe = "test"
        cmd.save()

        cmdhandler = CommandHandler()
        rsp = cmdhandler.run('test')
        self.assertIsNotNone(rsp)
        s.source = 'u'
        s.content = 'test'
        msghandler = MessageHandler(s, {})

        #msghandler.userinfo.isPasswordSet = True
        #msghandler.userinfo.isAdmin = True
        msghandler.handler()
        s.content = 'y'
        msghandler.handler()
        s.content='idcard:12321233'
        msghandler.handler()
        s.content='weather:上海'
        msghandler.handler()
        s.content='admin'
        msghandler.handler()
        s.content='123'
        msghandler.handler()

        s.content = 'exit'
        msghandler.handler()
开发者ID:lutianba2014,项目名称:DjangoBlog,代码行数:61,代码来源:tests.py

示例8: article_create

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
def article_create(request):
    title = request.POST.get('title', '')
    content = request.POST.get('content', '')
    author = Author.objects.get(name=request.session["author_name"])
    article = Article(title=title, content=content, author=author)
    article.save()
    articles = Article.objects.order_by('id')
    return render_to_response('articles/index.html', {'articles': articles}, context_instance=RequestContext(request))
开发者ID:manageyp,项目名称:django_blog,代码行数:10,代码来源:views.py

示例9: dealWithArticle

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
def dealWithArticle(request, post_id=0):
	'''
	если post_id = 0 => аргумент был не передан и мы создаем статью
	иначе редактируем статью с id = post_id
	надо будет прикрутить куки, чтобы... после редактирования статьи возвращать
	на страницу, откуда статья редактировалась.
	а после создания статьи возвращать страницу новосозданной статьи
	'''
	if post_id == 0:
		#добавление статьи
		mode = 0
	else:
		#редактирование статьи
		mode = 1
	try:
		article = Article.objects.get(pk = post_id)
		article_form = ArticleForm(instance = article)
		article = article_form.save(commit = False)
	except Article.DoesNotExist:
		article = Article()
		
		
	if request.POST:
		post = request.POST.copy()
		new_article_form = ArticleForm(post)
		if new_article_form.is_valid():
			new_article = new_article_form.save(commit = False)
			
			article.title = new_article.title
			article.bb_text = new_article.bb_text
			article.main_text = render_bbcode(new_article.bb_text)
			article.desc_text = render_bbcode(get_desc(new_article.bb_text))
			article.pub_date = timezone.now()
			article.is_big = is_big(article.main_text)
			
			article.save()
			return HttpResponseRedirect(reverse('blog.views.post',kwargs={'post_id':article.id}))
		else:
			return render_to_response('article_form.html',{'article_form': new_article_form, 
														   'mode':mode,
														   'url_ref': ref_for_article_form},
															context_instance=RequestContext(request))
	else:
		#добавляем статью
		if mode == 0:
			article_form = ArticleForm()
			return render_to_response('article_form.html',{'article_form': article_form,
													   'mode':mode,
													   'url_ref': ref_for_article_form},
														context_instance=RequestContext(request))
		if mode == 1:
			return render_to_response('article_form.html',{'article_form': article_form,
														   'mode':mode,
														   'url_ref': ref_for_article_form,
														   'article_id':article.id},
															context_instance=RequestContext(request))
开发者ID:ShadowOfManul,项目名称:testing-blog,代码行数:58,代码来源:views.py

示例10: article

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
def article(request):
    title = request.POST['title']
    author = request.POST['author']
    body = request.POST['body']
    usernameid = request.session['person_id']
    headImg = request.FILES['upload']
    uploadedfile(headImg)
    art = Article(title=title,author=author,body=body,usernameid=usernameid,headImg=headImg)
    art.save()
    return HttpResponseRedirect('/blog/')
开发者ID:AwesomeIcon,项目名称:PublicSite,代码行数:12,代码来源:views.py

示例11: post

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
 def post(self):
     from blog.forms import AddContentModalForm
     from auth.models import User
     self._form = AddContentModalForm(request.form)
     from blog.models import Article
     a = Article()
     self._form.populate_obj(a)
     a.author = User.query.filter(User.email==session.get('email',None)).first()
     a.save()
     return self.redirect('blog.index')
开发者ID:c0debrain,项目名称:flask-cms,代码行数:12,代码来源:views.py

示例12: test_slug_field_should_automatically_slugify_title

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
    def test_slug_field_should_automatically_slugify_title(self):
        user = UserFactory.create()
        article = Article(
            title='This is a title',
            author=user,
            content='Blah blah some content'
        )
        article.save()

        article.slug | should | equal_to('this-is-a-title')
开发者ID:gxx,项目名称:andrewcrosio.com,代码行数:12,代码来源:article_test.py

示例13: submit

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
def submit(request):
    try:
        cont = request.POST['content']
    except (KeyError):
        return render_to_response('index.html',
                {'all_articles' : all_articles,
                    'message' : 'Failed to read content'}, context_instance=RequestContext(request))
    else:
        article = Article(content=cont, written_date=timezone.now())
        article.save()
        return HttpResponseRedirect('/blog')
开发者ID:Jae-Han,项目名称:onelineblog,代码行数:13,代码来源:views.py

示例14: create

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
def create(request):
    title = request.POST.get('title')
    content = request.POST.get('content')
    form = ArticleForm(dict(title=title,
                            content=content,))
    if form.is_valid():
        article = Article(title=title, content=content,)
        article.save()
    #else:
        #return 
    return redirect(show, article_id=article.id)
开发者ID:aeud,项目名称:souad,代码行数:13,代码来源:views.py

示例15: get

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import save [as 别名]
 def get(self):
     from .models import Blog, Article, Tag, Category
     data = dict(
         date_added=request.args.get('date_added',None),
         date_end=request.args.get('date_end',None),
         name=request.args.get('name',None),
         description=request.args.get('description',None),
         slug=request.args.get('slug',None),
         short_url=request.args.get('short_url',None),
         title=request.args.get('title',None),
         add_to_nav=request.args.get('add_to_nav',None),
         add_sidebar=request.args.get('add_sidebar',None),
         visible=request.args.get('visible',None),
         meta_title=request.args.get('meta_title',None),
         content=request.args.get('content',None),
         template=request.args.get('template',None),
         category=request.args.get('category',None),
         tags=request.args.get('tags',None),
         use_base_template=request.args.get('use_base_template',None),
     )
     blog = Blog.get_current_blog()
     post = Article.query.filter(Article.name==data['name'])\
                         .filter(Article.blog==blog)\
                         .first()
     if post is not None:
         res = 0
     else:
         tags = [x.name for x in Tag.query.all()]
         new_tags = []
         for tag in data['tags']:
             if not tag in tags:
                 t = Tag()
                 t.name = tag
                 new_tags.append(t.save())
         new_tags = new_tags + tags
         post = Article()
         post.tags = new_tags
         post.name = data.get('name')
         post.date_added = data.get('date_added')            
         post.description = data.get('description',None)
         post.slug = data.get('slug',None)
         post.url = data.get('short_url',None)
         post.title = data.get('title',None)            
         post.visible = data.get('visible',None)
         post.meta_title = data.get('meta_title',None)
         post.content = data.get('content',None)
         post.category = data.get('category',None)
         post.save()
         res = 1
     return jsonify(result=res,content=data['content'])
开发者ID:c0debrain,项目名称:flask-cms,代码行数:52,代码来源:views.py


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