コード例 #1
0
ファイル: views.py プロジェクト: omeinusch/Palco
def item_add(request, container_pk):
    container = get_object_or_404(Item, pk=container_pk, is_container=True)
    if request.POST:
        form = ItemForm(request.POST)
        if form.is_valid():
            item = form.save(commit=False)
            item.container = container
            request.session['inventory_item_add_last_category'] = item.category
            for x in range(0, form.cleaned_data['multiply']):
                item.pk = None
                item.save()
                item.add_journal(request, _('Gegenstand wurde erfasst.'))
                message_object_created(request, item)

            if form.cleaned_data['multiply'] > 1:
                target = container
            elif item.type == Item.TYPE_CONTAINER:
                target = item
            else:
                target = container

            return redirect(target)
    else:
        form = ItemForm(
            initial={
                'category': request.session.get('inventory_item_add_last_category')
            }
        )

    c = {
        'container': container,
        'form': form
    }
    return render(request, 'inventory/item-add.html', get_context_inventory(request, 'inventory-item-add', c))
コード例 #2
0
ファイル: views.py プロジェクト: omeinusch/Palco
def index(request, item_pk):
    item = get_object_or_404(Item, pk=item_pk)
    items = item.containing()

    journal_entries = Journal.objects.filter(item=item)

    if request.POST:
        journal_form = JournalForm(request.POST)
        if journal_form.is_valid():
            journal_entry = journal_form.save(commit=False)
            journal_entry.user = request.user.actor
            journal_entry.item = item
            journal_entry.save()
            message_object_created(request, journal_entry)
            return redirect(item)
    else:
        journal_form = JournalForm()

    c = {
        'item': item,
        'items': items,
        'journal_entries': journal_entries,
        'journal_form': journal_form
    }

    return render(request, 'inventory/index.html', get_context_inventory(request, 'inventory-index', c))
コード例 #3
0
ファイル: views.py プロジェクト: omeinusch/Palco
def search(request):
    items = Item.objects.all()
    form = SearchForm(request.POST or None)
    if form.is_valid():
        data = form.cleaned_data
        if data['query'].isdigit():
            try:
                return redirect(Item.objects.get(pk=data['query']))
            except Item.DoesNotExist:
                pass
        if data['need_maintenance'] is not None:
            items = items.filter(need_maintenance=data['need_maintenance'])
        if data['is_container'] is not None:
            items = items.filter(is_container=data['is_container'])
        if data['is_existent'] is not None:
            items = items.filter(is_existent=data['is_existent'])
        if data['is_usable'] is not None:
            items = items.filter(is_usable=data['is_usable'])
        if len(data['category']) >= 1:
            items = items.filter(category__in=data['category'])
        if data['query']:
            items = items.filter(label__icontains=data['query']) | items.filter(description__icontains=data['query'])

    c = {
        'form': form,
        'items': items
    }
    return render(request, 'inventory/search.html', get_context_inventory(request, 'inventory-search', c))
コード例 #4
0
ファイル: views.py プロジェクト: omeinusch/Palco
def item_edit(request, item_pk):
    item = get_object_or_404(Item, pk=item_pk)

    if request.POST.get('delete'):
        if item.is_container and item.containing():
            messages.error(request, _(
                u'Der Gegenstand %s ist ein Container und enthält andere Gegenstände. Daher kann dieser Gegenstand nicht gelöscht werden.' % item))
            return redirect(item)
        else:
            if item.container:
                target = item.container
            else:
                target = None
            message_object_deleted(request, item)
            item.delete()
            if target:
                return redirect(target)
            else:
                return redirect('inventory-homepage')

    if request.POST:
        form = ItemForm(request.POST, instance=item)
        form.fields.pop('multiply')
        if form.is_valid():
            item = form.save()
            message_object_updated(request, item)
            item.add_journal(request, _('Gegenstand wurde bearbeitet.'))
            return redirect(item)
    else:
        form = ItemForm(instance=item)
        form.fields.pop('multiply')

    c = {
        'object': item,
        'form': form
    }

    return render(request, 'inventory/item-edit.html', get_context_inventory(request, 'inventory-item-edit', c))