コード例 #1
0
ファイル: test_markup.py プロジェクト: rpgplanet/rpghrac
class TestArticleManipulation(DatabaseTestCase):
    def setUp(self):
        super(TestArticleManipulation, self).setUp()

        self.user = create_user("tester", "xxx", "*****@*****.**")
        self.zapisnik = Zapisnik(site=self.user.get_profile().site, owner=self.user, visitor=self.user)

    def test_markup_rendered_properly_from_article(self):

        article = self.zapisnik.create_article_draft(
            annotation="annotation", title="title", content="""This is ""article"" content""", tags="tagity tag"
        )

        self.assert_equals("<p>This is <em>article</em> content</p>", article.content.content.strip())

    def test_update_propagated(self):

        article = self.zapisnik.create_article_draft(
            annotation="annotation", title="title", content="""This is ""article"" content""", tags="tagity tag"
        )

        update = Article.objects.get(pk=article.pk)
        update.content.djangomarkup_content = "Another content, *really*"

        update.title = "another title"
        update.content.title = update.title

        update.content.save()
        update.save()

        article = Article.objects.get(pk=update.pk)

        self.assert_equals("<p>Another content, <strong>really</strong></p>", article.content.content.strip())
コード例 #2
0
ファイル: views.py プロジェクト: rpgplanet/rpghrac
def preview(request, zapisek_id, template="zapisnik/preview.html"):
    zapisnik = Zapisnik(site=request.site, owner=request.site_owner, visitor=request.user)
    try:
        article = zapisnik.get_article(pk=zapisek_id)
    except Article.DoesNotExists:
        raise Http404

    return direct_to_template(request, template, {"article": article})
コード例 #3
0
ファイル: test_categories.py プロジェクト: rpgplanet/rpghrac
class TestCategoryHandling(DatabaseTestCase):

    # cannot be in setUp because it depends on categories that are mocked on per-case bases
    def prepare(self):
        self.user = create_user("tester", "xxx", "*****@*****.**")
        self.zapisnik = Zapisnik(site=self.user.get_profile().site, owner=self.user, visitor=self.user)
        self.article = self.zapisnik.create_article_draft(
            annotation = "annotation",
            title = "title",
            content = """This is ""article"" content""",
            tags = "tagity tag"
        )

    @mock_settings("DYNAMIC_RPGPLAYER_CATEGORIES", [
        {
            "tree_path" : "rpg",
            "parent_tree_path" : "",
            "title" : "RPG",
            "slug" : "rpg",
        },
    ])
    def test_tree_category_listing(self):
        self.prepare()
        root = self.zapisnik.get_available_categories_as_tree()

        self.assert_equals("", root['category'].tree_path)
        self.assert_equals(1, len(root['children']))
        self.assert_equals("RPG", root['children'][0]['category'].title)


    @mock_settings("DYNAMIC_RPGPLAYER_CATEGORIES", [
        {
            "tree_path" : "rpg",
            "parent_tree_path" : "",
            "title" : "RPG",
            "slug" : "rpg",
        },
        {
            "tree_path" : "rpg/wtf",
            "parent_tree_path" : "rpg",
            "title" : "WTF",
            "slug" : "wtf",
        },
    ])
    def test_nested_tree_category_listing(self):
        self.prepare()
        root = self.zapisnik.get_available_categories_as_tree()

        self.assert_equals("rpg", root['children'][0]['category'].tree_path)
        self.assert_equals(1, len(root['children'][0]['children']))
        self.assert_equals("WTF", root['children'][0]['children'][0]['category'].title)
コード例 #4
0
ファイル: test_publishing.py プロジェクト: rpgplanet/rpghrac
 def prepare(self):
     self.user = create_user("tester", "xxx", "*****@*****.**")
     self.zapisnik = Zapisnik(site=self.user.get_profile().site, owner=self.user, visitor=self.user)
     self.article = self.zapisnik.create_article_draft(
         annotation = "annotation",
         title = "title",
         content = """This is ""article"" content""",
         tags = "tagity tag"
     )
コード例 #5
0
ファイル: views.py プロジェクト: rpgplanet/rpghrac
def new(request, template="zapisnik/new.html"):
    article_form = None

    if request.method == "POST":
        article_form = ArticleForm(request.POST)
        if article_form.is_valid():

            zapisnik = Zapisnik(site=request.site, owner=request.site_owner, visitor=request.user)
            article = zapisnik.create_article_draft(
                annotation=article_form.cleaned_data["annotation"],
                title=article_form.cleaned_data["title"],
                content=article_form.cleaned_data["content"],
                tags=article_form.cleaned_data["tags"],
            )

            # TODO: redirect to article
            return HttpResponseRedirect(reverse("zapisnik-edit", kwargs={"zapisek": article.pk}))

    if not article_form:
        article_form = ArticleForm()

    return direct_to_template(request, template, {"article_form": article_form})
コード例 #6
0
ファイル: views.py プロジェクト: rpgplanet/rpghrac
def publish(request, zapisek_id, template="zapisnik/publish.html"):
    zapisnik = Zapisnik(site=request.site, owner=request.site_owner, visitor=request.user)
    try:
        article = zapisnik.get_article(pk=zapisek_id)
    except Article.DoesNotExists:
        raise Http404

    publish_form = None

    if request.method == "POST":
        publish_form = PublishForm(request.POST, categories_tree=zapisnik.get_available_categories_as_tree())
        if publish_form.is_valid():
            zapisnik.publish_article(article=article, categories=publish_form.cleaned_data["categories"])

            # FIXME: Should lead to published article, to absolute url?
            return HttpResponseRedirect(reverse("zapisnik-home"))

    if not publish_form:
        publish_form = PublishForm(categories_tree=zapisnik.get_available_categories_as_tree())

    return direct_to_template(request, template, {"article": article, "publish_form": publish_form})
コード例 #7
0
ファイル: test_markup.py プロジェクト: rpgplanet/rpghrac
    def setUp(self):
        super(TestArticleManipulation, self).setUp()

        self.user = create_user("tester", "xxx", "*****@*****.**")
        self.zapisnik = Zapisnik(site=self.user.get_profile().site, owner=self.user, visitor=self.user)
コード例 #8
0
ファイル: test_publishing.py プロジェクト: rpgplanet/rpghrac
class TestArticleManipulation(DatabaseTestCase):

    def prepare(self):
        self.user = create_user("tester", "xxx", "*****@*****.**")
        self.zapisnik = Zapisnik(site=self.user.get_profile().site, owner=self.user, visitor=self.user)
        self.article = self.zapisnik.create_article_draft(
            annotation = "annotation",
            title = "title",
            content = """This is ""article"" content""",
            tags = "tagity tag"
        )

        # we're all about rpg, thou shall be there

    @mock_settings("DYNAMIC_RPGPLAYER_CATEGORIES", [
        {
            "tree_path" : "rpg",
            "parent_tree_path" : "",
            "title" : "RPG",
            "slug" : "rpg",
        },
    ])

    def test_article_appears_in_proper_listing(self):
        self.prepare()
        self.zapisnik.publish_article(article=self.article, categories=["rpg"])

        # if we take published articles now, we shall find ourselves there
        category = Category.objects.get(
            site = self.user.get_profile().site,
            tree_path = "rpg"
        )

        listings = Listing.objects.filter(
            category = category
        )

        self.assert_equals(1, len(listings))

        self.assert_equals(self.article.publishable_ptr, listings[0].target)

    @mock_settings("DYNAMIC_RPGPLAYER_CATEGORIES", [
        {
            "tree_path" : "rpg",
            "parent_tree_path" : "",
            "title" : "RPG",
            "slug" : "rpg",
        },
        {
            "tree_path" : "rpg/drd",
            "parent_tree_path" : "rpg",
            "title" : "Dračí Doupě",
            "slug" : "drd",
        },
    ])
    def test_article_can_be_republished(self):
        self.prepare()
        self.zapisnik.publish_article(article=self.article, categories=["rpg"])
        self.zapisnik.publish_article(article=self.article, categories=["drd"])

        # if we take published articles now, we shall find ourselves there
        rpg_cat = Category.objects.get(
            site = self.user.get_profile().site,
            tree_path = "rpg"
        )

        drd_cat = Category.objects.get(
            site = self.user.get_profile().site,
            tree_path = "rpg/drd"
        )

        listings = Listing.objects.filter(
            category = drd_cat
        )

        # we are in drd
        self.assert_equals(1, len(listings))
        self.assert_equals(self.article.publishable_ptr, listings[0].target)

        # but not in rpg anymore
        self.assert_equals(0, len(Listing.objects.filter(category=rpg_cat)))


    @mock_settings("DYNAMIC_RPGPLAYER_CATEGORIES", [
        {
            "tree_path" : "rpg",
            "parent_tree_path" : "",
            "title" : "RPG",
            "slug" : "rpg",
        },
        {
            "tree_path" : "rpg/drd",
            "parent_tree_path" : "rpg",
            "title" : "Dračí Doupě",
            "slug" : "drd",
        },
    ])
    def test_article_can_be_republished_in_same_category_too(self):
        self.prepare()
        self.zapisnik.publish_article(article=self.article, categories=["rpg"])
        self.zapisnik.publish_article(article=self.article, categories=["drd", "rpg"])

        # if we take published articles now, we shall find ourselves there
        rpg_cat = Category.objects.get(
            site = self.user.get_profile().site,
            tree_path = "rpg"
        )

        drd_cat = Category.objects.get(
            site = self.user.get_profile().site,
            tree_path = "rpg/drd"
        )

        # we are in drd
        self.assert_equals(1, len(Listing.objects.filter(category = drd_cat)))
        self.assert_equals(1, len(Listing.objects.filter(category=rpg_cat)))


    def test_draft_in_drafts(self):
        self.prepare()

        self.assert_equals(1, len(self.zapisnik.get_drafts()))

        self.assert_equals(self.article.content, self.zapisnik.get_drafts()[0].content)
        self.assert_equals(self.article.title, self.zapisnik.get_drafts()[0].title)


    @mock_settings("DYNAMIC_RPGPLAYER_CATEGORIES", [
        {
            "tree_path" : "rpg",
            "parent_tree_path" : "",
            "title" : "RPG",
            "slug" : "rpg",
        },
    ])
    def test_published_articles_not_in_draft(self):
        self.prepare()

        self.zapisnik.publish_article(article=self.article, categories=["rpg"])

        self.assert_equals(0, len(self.zapisnik.get_drafts()))
コード例 #9
0
ファイル: views.py プロジェクト: rpgplanet/rpghrac
def workshop(request, template="zapisnik/workshop.html"):
    zapisnik = Zapisnik(site=request.site, owner=request.site_owner, visitor=request.user)
    articles = zapisnik.get_drafts()

    return direct_to_template(request, template, {"articles": articles})
コード例 #10
0
ファイル: views.py プロジェクト: rpgplanet/rpghrac
def home(request, template="zapisnik/home.html"):
    zapisnik = Zapisnik(site=request.site, owner=request.site_owner, visitor=request.user)
    articles = zapisnik.get_published_articles()
    return direct_to_template(request, template, {"articles": articles})
コード例 #11
0
ファイル: views.py プロジェクト: rpgplanet/rpghrac
def categories(request, template="zapisnik/categories.html"):
    zapisnik = Zapisnik(site=request.site, owner=request.site_owner, visitor=request.user)
    categories = zapisnik.get_available_categories_as_tree()
    return direct_to_template(request, template, {"categories": categories})