Beispiel #1
0
    def POST(self, sid):
        instance = get_object_or_404(Service, pk=sid)
        if not instance.creator == self.request.user:
            self.flash(_(u"You can't modify a service that isn't yours"),
                       "error")
            return redirect('serv-myservices')
        form = ServiceForm(self.request.POST, instance=instance)

        if form.is_valid():
            current_is_offer = instance.is_offer
            service = form.save(commit=False)

            # If there are ongoing transfers, oferta field cannot be changed or
            # else havoc will follow:
            if Transfer.objects.filter(service=instance,
                status__in=["q", "a"]).count() > 0 and\
                service.is_offer != current_is_offer:
                self.flash(_(u"You can't change the type of service between"
                    " offer and demand with transfers while there are ongoing"
                    " transfers."), "error")
                return redirect('serv-myservices')
            service.save()
            self.flash(_(u"Service modified successfully"))
            return redirect('serv-myservices')
        context = dict(form=form, instance=instance, current_tab="services",
            subtab="my-services")
        return self.context_response('serv/edit_service.html', context)
Beispiel #2
0
    def POST(self, sid):
        instance = get_object_or_404(Service, pk=sid)
        if not instance.creator == self.request.user:
            self.flash(_(u"You can't modify a service that isn't yours"),
                       "error")
            return redirect('serv-myservices')
        form = ServiceForm(self.request.POST, instance=instance)

        if form.is_valid():
            current_is_offer = instance.is_offer
            service = form.save(commit=False)

            # If there are ongoing transfers, oferta field cannot be changed or
            # else havoc will follow:
            if Transfer.objects.filter(service=instance,
                status__in=["q", "a"]).count() > 0 and\
                service.is_offer != current_is_offer:
                self.flash(_(u"You can't change the type of service between"
                    " offer and demand with transfers while there are ongoing"
                    " transfers."), "error")
                return redirect('serv-myservices')
            service.save()
            self.flash(_(u"Service modified successfully"))
            return redirect('serv-myservices')
        context = dict(form=form, instance=instance, current_tab="services",
            subtab="my-services")
        return self.context_response('serv/edit_service.html', context)
Beispiel #3
0
 def POST(self):
     form = ServiceForm(self.request.POST)
     if form.is_valid():
         service = form.save(commit=False)
         service.creator = self.request.user
         service.save()
         self.flash(_(u"Service added successfully"))
         return redirect('serv-myservices')
     context = dict(form=form, instance=None, current_tab="services",
         subtab="add")
     return self.context_response('serv/edit_service.html', context)
Beispiel #4
0
 def POST(self):
     form = ServiceForm(self.request.POST)
     if form.is_valid():
         service = form.save(commit=False)
         service.creator = self.request.user
         service.save()
         self.flash(_(u"Service added successfully"))
         return redirect('serv-myservices')
     context = dict(form=form, instance=None, current_tab="services",
         subtab="add")
     return self.context_response('serv/edit_service.html', context)
Beispiel #5
0
 def GET(self, sid):
     instance = get_object_or_404(Service, pk=sid)
     if not instance.creator == self.request.user:
         self.flash(_(u"You can't modify a service that isn't yours"),
                    "error")
         return redirect('serv-myservices')
     form = ServiceForm(instance=instance)
     context = dict(form=form, instance=instance, current_tab="services",
         subtab="my-services")
     return self.context_response('serv/edit_service.html', context)
Beispiel #6
0
 def GET(self):
     form = ServiceForm()
     context = dict(form=form, instance=None, current_tab="services",
         subtab="add")
     return self.context_response('serv/edit_service.html', context)