当前位置: 首页>>代码示例>>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;未经允许,请勿转载。