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


Python models.Article類代碼示例

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


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

示例1: new

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,代碼行數:26,代碼來源:views.py

示例2: setUp

 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()
開發者ID:stianjensen,項目名稱:wikipendium.no,代碼行數:27,代碼來源:tests.py

示例3: test_slug_cannot_contain_slashes

 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,代碼行數:8,代碼來源:tests.py

示例4: ArticleContentTest

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,代碼行數:58,代碼來源:tests.py

示例5: index

def index(request):
    acs = Article.get_all_newest_contents_all_languages()
    now = timezone.now()

    acs_updated_in_the_last_24_hours = filter(
        lambda ac: ac.updated > now - timezone.timedelta(hours=24), acs)

    acs_updated_in_the_last_week = filter(
        lambda ac: ac.updated > now - timezone.timedelta(days=7), acs)

    acs_updated_in_the_last_month = filter(
        lambda ac: ac.updated > now - timezone.timedelta(days=30), acs)

    user_stats = _generate_user_statistics_for_one_day(
        year=now.year, month=now.month, day=now.day
    )

    article_length_stats = _generate_article_length_statistics(acs)

    return render(request, 'stats/index.html', {
        'number_of_acs_updated_in_the_last_24_hours':
            len(acs_updated_in_the_last_24_hours),
        'number_of_acs_updated_in_the_last_week':
            len(acs_updated_in_the_last_week),
        'number_of_acs_updated_in_the_last_month':
            len(acs_updated_in_the_last_month),
        'users': user_stats,
        'compendium_length_stats': article_length_stats,
    })
開發者ID:stianjensen,項目名稱:wikipendium.no,代碼行數:29,代碼來源:views.py

示例6: merge_contents_if_needed

    def merge_contents_if_needed(self):
        parent_id = self.cleaned_data['parent_id']
        article = None
        articleContent = None
        slug = self.cleaned_data['slug']
        lang = self.cleaned_data['lang']
        try:
            article = Article.objects.get(slug=slug)
        except:
            article = Article(slug=slug)

        articleContent = article.get_newest_content(lang)
        if articleContent is None:
            articleContent = ArticleContent(article=article, lang=lang)

        if parent_id and parent_id != articleContent.pk:
            parent = ArticleContent.objects.get(id=parent_id)
            a = parent
            b = articleContent
            ancestors = set()
            commonAncestor = None
            while True:
                if a and a.pk in ancestors:
                    commonAncestor = a
                    break
                if b and b.pk in ancestors:
                    commonAncestor = b
                    break
                ancestors.add(a.pk)
                ancestors.add(b.pk)
                a = a.parent
                b = b.parent
                if a and a.parent is None and b and b.parent is None:
                    break

            try:
                merged = merge(self.cleaned_data['content'],
                               commonAncestor.content, articleContent.content)
                self.cleaned_data['content'] = merged
            except MergeError as e:
                raise ValidationError('Merge conflict.',
                                      params={'diff': e.diff})

        return True
開發者ID:tOgg1,項目名稱:wikipendium.no,代碼行數:44,代碼來源:forms.py

示例7: home

def home(request):

    all_newest_contents = Article.get_all_newest_contents_all_languages()

    compendiums = [
        {"label": ac.get_full_title(), "url": ac.get_absolute_url(), "lang": ac.lang, "updated": str(ac.updated)}
        for ac in all_newest_contents
    ]

    return render(request, "index.html", {"compendiums": json.dumps(compendiums)})
開發者ID:tOgg1,項目名稱:wikipendium.no,代碼行數:10,代碼來源:views.py

示例8: new

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,代碼行數:21,代碼來源:views.py

示例9: new

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,代碼行數:21,代碼來源:views.py

示例10: tag

def tag(request, tag_slug):
    tag = get_object_or_404(Tag, slug=tag_slug)
    articles_with_tag = Article.objects.filter(tags=tag)
    all_newest_contents = Article.get_all_newest_contents_all_languages()
    filtered_contents = filter(lambda ac: ac.article in articles_with_tag, all_newest_contents)
    if len(filtered_contents) == 0:
        raise Http404
    compendiums = [
        {"label": ac.get_full_title(), "url": ac.get_absolute_url(), "lang": ac.lang, "updated": str(ac.updated)}
        for ac in filtered_contents
    ]

    return render(request, "index.html", {"compendiums": json.dumps(compendiums), "tag": tag})
開發者ID:tOgg1,項目名稱:wikipendium.no,代碼行數:13,代碼來源:views.py

示例11: home

def home(request):

    all_newest_contents = Article.get_all_newest_contents_all_languages()

    compendiums = [{
        'label': ac.get_full_title(),
        'url': ac.get_absolute_url(),
        'lang': ac.lang,
        'updated': str(ac.updated),
    } for ac in all_newest_contents]

    return render(request, 'index.html', {
        'compendiums': json.dumps(compendiums),
    })
開發者ID:stianjensen,項目名稱:wikipendium.no,代碼行數:14,代碼來源:views.py

示例12: home

def home(request):

    all_newest_contents = Article.get_all_newest_contents_all_languages()

    trie = [{
        "label": ac.get_full_title(),
        "url": ac.get_absolute_url(),
        "lang": ac.lang,
        "updated": str(ac.updated),
    } for ac in all_newest_contents]

    return render(request, 'index.html', {
        "trie": json.dumps(trie),
    })
開發者ID:peterhgombos,項目名稱:wikipendium.no,代碼行數:14,代碼來源:views.py

示例13: _generate_user_statistics_for_one_day

def _generate_user_statistics_for_one_day(year=None, month=None, day=None):
    now = datetime(year, month, day)
    now = now.replace(tzinfo=utc)
    users_24_hours = map(
        lambda a: a.edited_by,
        Article.get_all_contents(timezone.timedelta(hours=24), now)
        )
    users_week = map(
        lambda a: a.edited_by,
        Article.get_all_contents(timezone.timedelta(weeks=1), now)
        )
    users_month = map(
        lambda a: a.edited_by,
        Article.get_all_contents(timezone.timedelta(weeks=4), now)
        )

    user_most_contributions_24_hours = next(
        iter(Counter(users_24_hours).most_common(1)), [None, 0])
    user_most_contributions_week = next(
        iter(Counter(users_week).most_common(1)), [None, 0])
    user_most_contributions_month = next(
        iter(Counter(users_month).most_common(1)), [None, 0])

    return {
        'most_contrib_24_hours': {
            'user': user_most_contributions_24_hours[0],
            'contributions': user_most_contributions_24_hours[1],
        },
        'most_contrib_week': {
            'user': user_most_contributions_week[0],
            'contributions': user_most_contributions_week[1],
        },
        'most_contrib_month': {
            'user': user_most_contributions_month[0],
            'contributions': user_most_contributions_month[1],
        }
    }
開發者ID:stianjensen,項目名稱:wikipendium.no,代碼行數:37,代碼來源:views.py

示例14: setUp

 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()
開發者ID:aleksanb,項目名稱:wikipendium.no,代碼行數:16,代碼來源:tests.py

示例15: ArticleTest

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,代碼行數:53,代碼來源:tests.py


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