Ejemplo n.º 1
0
def apply(request):
    if request.method == 'POST':
        form = AddItemForm(request.POST)

        isValid = True
        if Blacklist.objects.filter(title=request.POST['title']).exists():
            messages.success(request, 'Invalid item.')
            isValid = False
        else:
            if Item.objects.filter(title=request.POST['title']).exists():
                messages.success(request, 'Item already exists.')
                isValid = False

        if form.is_valid() and isValid:
            if request.user.profile.is_su:
                Item.objects.create(
                    owner=request.user,
                    title=request.POST.get('title'),
                    key_words=request.POST.get('key_words'),
                    description=request.POST.get('description'),
                    picture=request.POST.get('picture'))
                messages.success(request, 'New item added.')
            else:
                application = form.save(commit=False)
                application.owner = request.user
                application.save()

                messages.success(request, 'Item has been sent to for review.')
            return redirect('index')
    else:
        form = AddItemForm()

    content = {'form': form}
    return render(request, 'items/apply.html', content)
Ejemplo n.º 2
0
def add_item_view(request):
    context = {}

    if request.method == 'POST':
        form = AddItemForm(request.POST, request.FILES)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect('http://127.0.0.1:8000/items/')

        else:
            context['add_item_form'] = form
    else:  #GET
        pass
        # form = ItemRegistrationForm()
        # context['add_item_form'] = form
    return render(request, 'items/add_item.html', {})
Ejemplo n.º 3
0
def section_view(request, slug):
    item_form = AddItemForm()
    category_form = CategoryForm()
    section = get_object_or_404(Section, slug=slug)
    categories = Category.objects.filter(section=section)

    if request.method == 'POST':
        item_form = AddItemForm(request.POST)
        if item_form.is_valid():
            item_form.save(commit=True)
            return redirect('section_view', slug=section.slug)
    return render(
        request, 'sections/section_view.html', {
            'section': section,
            'categories': categories,
            'category_form': category_form,
            'item_form': item_form
        })