def service_create(request): ImageFormset = modelformset_factory(imageService, fields=('image', ), labels={'image': ''}, extra=1) if request.method == 'POST': form = ServiceForm(request.POST) formset = ImageFormset(request.POST or None, request.FILES or None) if form.is_valid() and formset.is_valid(): service = form.save(commit=False) service.user = request.user service.person = request.user.person service.save() for f in formset: try: photo = imageService(service=service, image=f.cleaned_data['image']) photo.save() except: break return redirect('list') else: form = ServiceForm() formset = ImageFormset(queryset=imageService.objects.none()) context = { 'form': form, 'formset': formset, 'user': request.user, 'person': request.user.person } return render(request, 'service/new.html', context)
def update(request, id): service = Service.objects.get(id=id) form = ServiceForm(request.POST, instance=service) if form.is_valid(): form.save() return redirect("/show") return render(request, 'edit.html', {'service': service})
def Service(request): if request.method=="POST": j=ServiceForm(request.POST,request.FILES) if j.is_valid(): i=j.save(commit=False) i.uid_id=request.user.id i.save() return redirect('/showdata') j=ServiceForm() return render(request,'services/Services.html',{'u':j})
def emp(request): if request.method == "POST": form = ServiceForm(request.POST) if form.is_valid(): try: form.save() return redirect('/show') except: pass else: form = ServiceForm() return render(request, 'index.html', {'form': form})
def new(request): # Restrict To within SoC print ip_address_processor(request)['ip_address'] if request.method == 'POST': form = ServiceForm(request.POST, request.FILES) if form.is_valid(): handle_uploaded_file(request.FILES['file']) name = form.cleaned_data['name'] desc = form.cleaned_data['description'] command = form.cleaned_data['command'] location = '/tmp/' + request.FILES['file'].name aService = Service(name=name, description=desc, command=command, location=location) aService.save() # Run the service in the background messages.add_message(request, messages.SUCCESS, 'Successfully Created') return HttpResponseRedirect('/service/') else: form = ServiceForm() return render(request, 'service/new.html', {'form': form})