Exemple #1
0
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})
Exemple #2
0
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()))