當前位置: 首頁>>代碼示例>>Python>>正文


Python Article.save方法代碼示例

本文整理匯總了Python中wikipendium.wiki.models.Article.save方法的典型用法代碼示例。如果您正苦於以下問題:Python Article.save方法的具體用法?Python Article.save怎麽用?Python Article.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wikipendium.wiki.models.Article的用法示例。


在下文中一共展示了Article.save方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: new

# 需要導入模塊: from wikipendium.wiki.models import Article [as 別名]
# 或者: from wikipendium.wiki.models.Article import save [as 別名]
def new(request, slug=None):
    if request.POST:
        form = NewArticleForm(request.POST)
        if form.is_valid():
            slug = request.POST.get('slug')
            article = Article(slug=slug)
            article.save()

            article_content = form.save(commit=False)
            article_content.article = article
            article_content.edited_by = request.user
            article_content.save()
            return HttpResponseRedirect(article_content.get_absolute_url())
    else:
        article_content = None
        if slug:
            slug = slug.upper()
            article_content = ArticleContent(article=Article(slug=slug),
                                             lang=None)
        form = NewArticleForm(instance=article_content)

    return render(request, 'edit.html', {
        'mathjax': True,
        'form': form,
        'title': 'Create compendium',
    })
開發者ID:stianjensen,項目名稱:wikipendium.no,代碼行數:28,代碼來源:views.py

示例2: test_slug_cannot_contain_slashes

# 需要導入模塊: from wikipendium.wiki.models import Article [as 別名]
# 或者: from wikipendium.wiki.models.Article import save [as 別名]
 def test_slug_cannot_contain_slashes(self):
     article = Article()
     article.slug = u'TDT/4100'
     try:
         article.save()
         self.assertEqual(1, 2)  # this should not be reached
     except ValidationError:
         self.assertEqual(1, 1)  # correct error was raised
開發者ID:stianjensen,項目名稱:wikipendium.no,代碼行數:10,代碼來源:tests.py

示例3: ArticleContentTest

# 需要導入模塊: from wikipendium.wiki.models import Article [as 別名]
# 或者: from wikipendium.wiki.models.Article import save [as 別名]
class ArticleContentTest(TestCase):

    def setUp(self):
        self.article1 = Article(slug="TDT4100")
        self.article1.save()
        self.ac1 = ArticleContent(article=self.article1,
                                  updated=datetime.datetime(2012, 1, 1),
                                  title='Cooking and baking',
                                  lang='fr',
                                  content='# Title')
        self.ac2 = ArticleContent(article=self.article1,
                                  updated=datetime.datetime(2014, 1, 1),
                                  title='Cooking and baking',
                                  lang='fr')
        self.ac1.save()
        self.ac2.save()

    def test_title_cannot_contain_slashes(self):
        ac = ArticleContent()
        ac.title = 'asdf/sdfi'
        ac.article = self.article1
        with self.assertRaises(ValidationError):
            ac.save()

    def test_get_full_title(self):
        self.assertEquals('TDT4100: Cooking and baking',
                          self.ac1.get_full_title())

    def test_get_last_descendant(self):
        self.assertEquals(self.ac2,
                          self.ac1.get_last_descendant())

    def test_get_absolute_url(self):
        self.assertEquals('/TDT4100_Cooking_and_baking/fr/',
                          self.ac1.get_absolute_url())

    def test_get_edit_url(self):
        self.assertEquals('/TDT4100_Cooking_and_baking/fr/edit/',
                          self.ac1.get_edit_url())

    def test_get_add_language_url(self):
        self.assertEquals('/TDT4100/add_language/',
                          self.ac1.get_add_language_url())

    def test_get_history_url(self):
        self.assertEquals('/TDT4100_Cooking_and_baking/fr/history/',
                          self.ac1.get_history_url())

    def test_get_history_single_url(self):
        self.assertEquals('/TDT4100_Cooking_and_baking/fr/history/%s/' % (
                          self.ac1.pk), self.ac1.get_history_single_url())

    def test_get_html_content(self):
        self.assertTrue('<h1>' in self.ac1.get_html_content()['html'])

    def test___unicode__(self):
        self.assertEquals('[1] Cooking and baking',
                          unicode(self.ac1))
開發者ID:peterhgombos,項目名稱:wikipendium.no,代碼行數:60,代碼來源:tests.py

示例4: ArticleTest

# 需要導入模塊: from wikipendium.wiki.models import Article [as 別名]
# 或者: from wikipendium.wiki.models.Article import save [as 別名]
class ArticleTest(TestCase):

    def setUp(self):
        self.u1 = User(username='u1')
        self.u2 = User(username='u2')
        self.u1.save()
        self.u2.save()
        self.article = Article(slug="TDT4100")
        self.article.save()
        self.ac1 = ArticleContent(article=self.article,
                                  updated=datetime.datetime(2012, 1, 1))
        self.ac2 = ArticleContent(article=self.article,
                                  updated=datetime.datetime(2013, 1, 1),
                                  title='per')
        self.ac1.edited_by = self.u1
        self.ac2.edited_by = self.u2
        self.ac1.save()
        self.ac2.save()

    def test_slug_should_uppercase_when_saved(self):
        article = Article()
        article.slug = "lowercase"
        article.save()
        self.assertEqual(article.slug, "LOWERCASE")

    def test_slug_should_strip_whitespace_when_saved(self):
        article = Article()
        article.slug = "   PADDED\v\t \n"
        article.save()
        self.assertEqual(article.slug, "PADDED")

    def test_slug_cannot_contain_slashes(self):
        article = Article()
        article.slug = "TDT/4100"
        try:
            article.save()
            self.assertEqual(1, 2)  # this should not be reached
        except ValidationError:
            self.assertEqual(1, 1)  # correct error was raised

    def test_get_contributors(self):
        self.assertEquals(self.article.get_contributors(),
                          set([self.u1, self.u2]))

    def test_get_newest_content(self):
        self.assertEquals(self.article.get_newest_content(), self.ac2)

    def test_get_available_languages(self):
        self.assertEquals(self.article.get_available_languages(),
                          [('English', self.ac2)])

    def test_get_absolute_url(self):
        self.assertEquals(self.article.get_absolute_url(), "/TDT4100_per")
開發者ID:aleksanb,項目名稱:wikipendium.no,代碼行數:55,代碼來源:tests.py

示例5: new

# 需要導入模塊: from wikipendium.wiki.models import Article [as 別名]
# 或者: from wikipendium.wiki.models.Article import save [as 別名]
def new(request):
    if request.POST:
        form = NewArticleForm(request.POST)
        if form.is_valid():
            slug = request.POST.get('slug')
            article = Article(slug=slug)
            article.save()

            articleContent = form.save(commit=False)
            articleContent.article = article
            articleContent.edited_by = request.user
            articleContent.save()
            return HttpResponseRedirect(articleContent.get_absolute_url())
    else:
        form = NewArticleForm()

    return render(request, 'edit.html', {
        "mathjax": True,
        "form": form,
        "title": "Create article",
    })
開發者ID:peterhgombos,項目名稱:wikipendium.no,代碼行數:23,代碼來源:views.py

示例6: new

# 需要導入模塊: from wikipendium.wiki.models import Article [as 別名]
# 或者: from wikipendium.wiki.models.Article import save [as 別名]
def new(request, slug=None):
    if request.POST:
        form = NewArticleForm(request.POST)
        if form.is_valid():
            slug = request.POST.get("slug")
            article = Article(slug=slug)
            article.save()

            articleContent = form.save(commit=False)
            articleContent.article = article
            articleContent.edited_by = request.user
            articleContent.save()
            return HttpResponseRedirect(articleContent.get_absolute_url())
    else:
        articleContent = None
        if slug:
            slug = slug.upper()
            articleContent = ArticleContent(article=Article(slug=slug), lang=None)
        form = NewArticleForm(instance=articleContent)

    return render(request, "edit.html", {"mathjax": True, "form": form, "title": "Create compendium"})
開發者ID:tOgg1,項目名稱:wikipendium.no,代碼行數:23,代碼來源:views.py

示例7: test_slug_should_strip_whitespace_when_saved

# 需要導入模塊: from wikipendium.wiki.models import Article [as 別名]
# 或者: from wikipendium.wiki.models.Article import save [as 別名]
 def test_slug_should_strip_whitespace_when_saved(self):
     article = Article()
     article.slug = u'   PADDED\v\t \n'
     article.save()
     self.assertEqual(article.slug, u'PADDED')
開發者ID:stianjensen,項目名稱:wikipendium.no,代碼行數:7,代碼來源:tests.py

示例8: test_slug_should_uppercase_when_saved

# 需要導入模塊: from wikipendium.wiki.models import Article [as 別名]
# 或者: from wikipendium.wiki.models.Article import save [as 別名]
 def test_slug_should_uppercase_when_saved(self):
     article = Article()
     article.slug = u'lowercase'
     article.save()
     self.assertEqual(article.slug, u'LOWERCASE')
開發者ID:stianjensen,項目名稱:wikipendium.no,代碼行數:7,代碼來源:tests.py

示例9: ArticleTest

# 需要導入模塊: from wikipendium.wiki.models import Article [as 別名]
# 或者: from wikipendium.wiki.models.Article import save [as 別名]
class ArticleTest(TestCase):

    def setUp(self):
        self.u1 = User(username='u1')
        self.u2 = User(username='u2')
        self.u1.save()
        self.u2.save()
        self.article1 = Article(slug=u'TDT4100')
        self.article1.save()
        self.article2 = Article(slug=u'TIØ4258')
        self.article2.save()
        self.ac1 = ArticleContent(article=self.article1,
                                  updated=datetime.datetime(2012, 1, 1))
        self.ac2 = ArticleContent(article=self.article1,
                                  updated=datetime.datetime(2013, 1, 1),
                                  title='per')
        self.ac3 = ArticleContent(article=self.article2,
                                  updated=datetime.datetime(2001, 3, 7))
        self.ac4 = ArticleContent(article=self.article2,
                                  updated=datetime.datetime(2001, 3, 8),
                                  lang='nb')
        self.ac1.edited_by = self.u1
        self.ac2.edited_by = self.u2
        self.ac3.edited_by = self.u1
        self.ac4.edited_by = self.u2
        self.ac1.save()
        self.ac2.save()
        self.ac3.save()
        self.ac4.save()

    def test_slug_should_uppercase_when_saved(self):
        article = Article()
        article.slug = u'lowercase'
        article.save()
        self.assertEqual(article.slug, u'LOWERCASE')

    def test_slug_should_strip_whitespace_when_saved(self):
        article = Article()
        article.slug = u'   PADDED\v\t \n'
        article.save()
        self.assertEqual(article.slug, u'PADDED')

    def test_slug_cannot_contain_slashes(self):
        article = Article()
        article.slug = u'TDT/4100'
        try:
            article.save()
            self.assertEqual(1, 2)  # this should not be reached
        except ValidationError:
            self.assertEqual(1, 1)  # correct error was raised

    def test_get_contributors(self):
        self.assertEquals(self.article1.get_contributors(),
                          set([self.u1, self.u2]))

    def test_get_newest_content(self):
        self.assertEquals(self.article1.get_newest_content(), self.ac2)

    def test_get_available_languages(self):
        self.assertEquals(self.article1.get_available_languages(),
                          [('English', self.ac2)])
        result = self.article2.get_available_languages()
        expected_result = [('English', self.ac3),
                           ('Norwegian', self.ac4)]
        self.assertEquals(expected_result, result)

    def test_get_absolute_url(self):
        self.assertEquals(self.article1.get_absolute_url(), '/TDT4100_per')

    def test_get_all_article_content(self):
        result = Article.get_all_article_content()
        expected_result = [[self.ac2], [self.ac3, self.ac4]]
        self.assertEquals(expected_result, result)

    def test_get_all_newest_contents(self):
        result = Article.get_all_newest_contents()
        expected_result = [self.ac2, self.ac4]
        self.assertEquals(expected_result, result)

    def test_get_all_newest_contents_all_languages(self):
        result = Article.get_all_newest_contents_all_languages()
        expected_result = [self.ac4, self.ac3, self.ac2]
        self.assertEquals(expected_result, result)

    def test___unicode__(self):
        self.assertEquals(u'TIØ4258', unicode(self.article2))
        self.assertEquals(unicode, type(unicode(self.article2)))

    def test_get_sorted_contents(self):
        result = list(self.article1.get_sorted_contents())
        expected_result = [self.ac2, self.ac1]
        self.assertEquals(expected_result, result)

        result = list(self.article2.get_sorted_contents())
        expected_result = [self.ac3]
        self.assertEquals(expected_result, result)

        result = list(self.article2.get_sorted_contents(lang='nb'))
        expected_result = [self.ac4]
        self.assertEquals(expected_result, result)
#.........這裏部分代碼省略.........
開發者ID:stianjensen,項目名稱:wikipendium.no,代碼行數:103,代碼來源:tests.py

示例10: test_slug_should_uppercase_when_saved

# 需要導入模塊: from wikipendium.wiki.models import Article [as 別名]
# 或者: from wikipendium.wiki.models.Article import save [as 別名]
 def test_slug_should_uppercase_when_saved(self):
     article = Article()
     article.slug = "lowercase"
     article.save()
     self.assertEqual(article.slug, "LOWERCASE")
開發者ID:aleksanb,項目名稱:wikipendium.no,代碼行數:7,代碼來源:tests.py


注:本文中的wikipendium.wiki.models.Article.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。