Example #1
0
    def test_category_invalid_parent(self):
        """
        invalid parent
        """
        # parent can not be a subcategory, only one level subcat is allowed
        subcategory = utils.create_category(parent=self.category)
        form_data = {"parent": subcategory.pk, }
        form = CategoryForm(data=form_data)
        self.assertEqual(form.is_valid(), False)
        self.assertNotIn('parent', form.cleaned_data)

        # parent can not be set to a category with childrens
        category_ = utils.create_category()
        form_data = {"parent": category_.pk, }
        form = CategoryForm(data=form_data, instance=self.category)
        self.assertEqual(form.is_valid(), False)
        self.assertNotIn('parent', form.cleaned_data)

        # parent can not be removed
        category_ = utils.create_category(is_removed=True)
        form_data = {"parent": category_.pk, }
        form = CategoryForm(data=form_data)
        self.assertEqual(form.is_valid(), False)
        self.assertNotIn('parent', form.cleaned_data)

        # parent can not be private
        category_ = utils.create_category(is_private=True)
        form_data = {"parent": category_.pk, }
        form = CategoryForm(data=form_data)
        self.assertEqual(form.is_valid(), False)
        self.assertNotIn('parent', form.cleaned_data)
Example #2
0
 def test_category(self):
     """
     Add category
     """
     form_data = {"parent": "",
                  "title": "foo",
                  "description": "",
                  "is_closed": False,
                  "is_removed": False}
     form = CategoryForm(data=form_data)
     self.assertEqual(form.is_valid(), True)
Example #3
0
def category_create(request):
    if request.method == 'POST':
        form = CategoryForm(data=request.POST)

        if form.is_valid():
            form.save()
            return redirect(reverse("spirit:admin-category-list"))
    else:
        form = CategoryForm()

    return render(request, 'spirit/admin/category/category_create.html', {'form': form, })
Example #4
0
def category_create(request):
    if request.method == 'POST':
        form = CategoryForm(data=request.POST)

        if form.is_valid():
            form.save()
            return redirect(reverse("spirit:admin-category-list"))
    else:
        form = CategoryForm()

    return render(request, 'spirit/admin/category/category_create.html', {
        'form': form,
    })
Example #5
0
def category_update(request, category_id):
    category = get_object_or_404(Category, pk=category_id)

    if request.method == 'POST':
        form = CategoryForm(data=request.POST, instance=category)

        if form.is_valid():
            form.save()
            messages.info(request, _("The category has been updated!"))
            return redirect(reverse("spirit:admin-category-list"))
    else:
        form = CategoryForm(instance=category)

    return render(request, 'spirit/admin/category/category_update.html', {'form': form, })
Example #6
0
def category_update(request, category_id):
    category = get_object_or_404(Category, pk=category_id)

    if request.method == 'POST':
        form = CategoryForm(data=request.POST, instance=category)

        if form.is_valid():
            form.save()
            messages.info(request, _("The category has been updated!"))
            return redirect(reverse("spirit:admin-category-list"))
    else:
        form = CategoryForm(instance=category)

    return render(request, 'spirit/admin/category/category_update.html', {
        'form': form,
    })