Пример #1
0
def admin_itemlist(request):

    """
    Administrative item listing, allows for viewing of items,
    taking actions on items, and archiving items.
    """

    # Built item list from filter.
    item_filter_form = AdminItemFilterForm(request.GET if "action" in request.GET else None)
    item_list = item_filter_form.filter()

    # Process archive request
    if request.method == 'POST':

        item_archive_form = ItemArchiveForm(request.POST, item_list=item_list)

        if item_archive_form.is_valid():
            item_archive_form.save()
            messages.success(request, "Item successfully changed")
            return HttpResponseRedirect(request.get_full_path())

    else:
        item_archive_form = ItemArchiveForm(item_list=item_list)

    return render(request, 'items/admin-itemlist.html', {
        'items': item_list,
        'item_filter': item_filter_form,
        'archive_form': item_archive_form,
        })
Пример #2
0
    def test_save(self):

        """
        Checks that the archived status of items is updated.
        """

        user = create_staff()
        self.client.login(username=user.username, password="******")

        new_item = make(Item, is_archived=False)
        new_action = Action.objects.get(machine_name=Action.CHECKED_IN)
        make(Status, action_taken=new_action, item=new_item)
        make(Category)
        make(Location)

        item_filter_form = AdminItemFilterForm(None)
        item_list = item_filter_form.filter()

        request = self.client.post(reverse("admin-itemlist"))

        archive_key = 'archive-' + str(new_item.pk)

        item_archive_form = ItemArchiveForm(request, item_list=item_list)

        self.assertTrue(item_archive_form.is_valid())
        item_archive_form.cleaned_data[archive_key] = True
        item_archive_form.save()

        new_item = Item.objects.get(pk=new_item.pk)
        self.assertTrue(new_item.is_archived)