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)
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})
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})