Beispiel #1
0
    def post(request):
        """Method responsible for saving new offer.

        :param request: WSGIRequest instance
        """
        form = CreateOfferForm(request.POST)
        if form.is_valid():
            offer = form.save()
            offer.create_new()
            offer.save()
            save_history(request, offer, action=ADDITION)
            send_mail(request, 'offer_creation',
                      ['*****@*****.**'], {'offer': offer})
            messages.success(request, "Dziękujemy za dodanie oferty.")
            return redirect(
                'offers_view',
                slug=slugify(offer.title),
                id_=offer.id,
            )
        messages.error(
            request,
            "Formularz zawiera niepoprawnie wypełnione pola <br />{0}".format(
                '<br />'.join(form.errors)),
        )
        return render(
            request, 'offers/offer_form.html', {
                'form': form,
                'offer': Offer(),
                'organizations': request.user.userprofile.organizations.all(),
            })
Beispiel #2
0
    def post(request, slug, id_):  # pylint: disable=unused-argument
        """Method resposible for saving changed offer.

        :param request: WSGIRequest instance
        :param slug: string Offer title slugified
        :param id_: int Offer database unique identifier (primary key)
        """
        offer = Offer.objects.get(id=id_)
        if request.POST.get('submit') == 'save_image' and request.FILES:
            form = OfferImageForm(request.POST, request.FILES)
            if form.is_valid():
                offer.save_offer_image(form.save(commit=False),
                                       form.cleaned_data['is_main'])
                messages.success(request, "Dodano zdjęcie do galerii.")
            else:
                messages.error(
                    request, "Problem w trakcie dodawania grafiki: {}".format(
                        "<br />".join(form.errors)))

            return redirect(
                reverse('offers_edit', args=[slugify(offer.title), offer.id]))
        elif request.POST.get('close_offer') == 'close':
            offer.close_offer()
            return redirect(
                reverse('offers_view', args=[slugify(offer.title), offer.id]))
        elif request.POST.get('status_flag') == 'change_status':
            if request.POST.get('status') == 'published':
                offer.publish()
                if request.user.userprofile.is_administrator:
                    return redirect('offers_reorder', offer.id)
            elif request.POST.get('status') == 'rejected':
                offer.reject()
            return redirect('offers_list')

        form = CreateOfferForm(request.POST, instance=offer)

        if form.is_valid():
            offer = form.save()
            offer.unpublish()
            offer.save()
            save_history(request, offer, action=CHANGE)
            messages.success(request, "Oferta została zmieniona.")
        else:
            messages.error(
                request,
                "Formularz zawiera niepoprawnie wypełnione pola: {}".format(
                    "<br />".join(form.errors)))

        if offer.id or request.user.userprofile.is_administrator:
            organizations = [offer.organization]
        else:
            organizations = request.user.userprofile.organizations.all()

        return render(
            request, 'offers/offer_form.html', {
                'offer': offer,
                'form': form,
                'organizations': organizations,
                'offer_image_form': OfferImageForm(),
            })
Beispiel #3
0
    def post(request):
        u"""Method responsible for saving new offer.

        :param request: WSGIRequest instance
        """
        form = CreateOfferForm(request.POST)
        if form.is_valid():
            offer = form.save()
            offer.create_new()
            offer.save()
            save_history(request, offer, action=ADDITION)
            send_mail(
                request,
                'offer_creation',
                ['*****@*****.**'],
                {'offer': offer}
            )
            messages.success(request, u"Dziękujemy za dodanie oferty.")
            return redirect(
                'offers_view',
                slug=slugify(offer.title),
                id_=offer.id,
            )
        messages.error(
            request,
            u"Formularz zawiera niepoprawnie wypełnione pola <br />{0}".format(
                '<br />'.join(form.errors)),
        )
        return render(
            request,
            'offers/offer_form.html',
            {
                'form': form,
                'offer': Offer(),
                'organizations': request.user.userprofile.organizations.all(),
            }
        )
Beispiel #4
0
    def post(request, slug, id_):  # pylint: disable=unused-argument
        u"""Method resposible for saving changed offer.

        :param request: WSGIRequest instance
        :param slug: string Offer title slugified
        :param id_: int Offer database unique identifier (primary key)
        """
        offer = Offer.objects.get(id=id_)
        if request.POST.get('submit') == 'save_image' and request.FILES:
            form = OfferImageForm(request.POST, request.FILES)
            if form.is_valid():
                offer.save_offer_image(
                    form.save(commit=False),
                    request.user.userprofile,
                    form.cleaned_data['is_main']
                )
                messages.success(request, u"Dodano zdjęcie do galerii.")
            else:
                messages.error(
                    request,
                    u"Problem w trakcie dodawania grafiki: {}".format(
                        '<br />'.join(form.errors)
                    )
                )

            return redirect(
                reverse(
                    'offers_edit',
                    args=[slugify(offer.title), offer.id]
                )
            )
        elif request.POST.get('close_offer') == 'close':
            offer.close_offer()
            return redirect(
                reverse(
                    'offers_view',
                    args=[slugify(offer.title), offer.id]
                )
            )
        elif request.POST.get('status_flag') == 'change_status':
            if request.POST.get('status') == 'published':
                offer.publish()
                if request.user.userprofile.is_administrator:
                    return redirect('offers_reorder', offer.id)
            elif request.POST.get('status') == 'rejected':
                offer.reject()
            return redirect('offers_list')

        form = CreateOfferForm(request.POST, instance=offer)
        if form.is_valid():
            offer = form.save()
            offer.unpublish()
            offer.save()
            save_history(request, offer, action=CHANGE)
            messages.success(request, u"Oferta została zmieniona.")
        else:
            messages.error(
                request,
                u"Formularz zawiera niepoprawnie wypełnione pola: {}".format(
                    '<br />'.join(form.errors)
                )
            )

        if offer.id or request.user.userprofile.is_administrator:
            organizations = [offer.organization]
        else:
            organizations = request.user.userprofile.organizations.all()

        return render(
            request,
            'offers/offer_form.html',
            {
                'offer': offer,
                'form': form,
                'organizations': organizations,
                'offer_image_form': OfferImageForm(),
            }
        )