def s3bucket(request): if request.method == 'POST': context = {} student = StudentForm(request.POST, request.FILES) bucketname = request.POST['bucketname'] file_obj = request.FILES['file'] filename = str(file_obj.name) if student.is_valid(): bucket_list = bucketlist() for bucket in bucket_list: if bucket.name == str(bucketname): context[ 'error'] = "The Bucket Name already exists.Choose other Buket Name" return render(request, 'myapp/message.html', context) handle_uploaded_file(request.FILES['file']) uploadfile = "C:\\Users\\Administrator\\Desktop\\jenkins\\workspace\\demo\\myapp\\static\\upload" + filename boto3connection(bucketname, filename, uploadfile) context[ 'error'] = "The NEW Bucket is created : " + bucketname + " and The FIle is Uploaded Successfully in that Bucket" return render(request, 'myapp/message.html', context) else: student = StudentForm() return render(request, "myapp/s3.html", {'form': student})
def s3bucket(request): if request.method == 'POST': context = {} student = StudentForm(request.POST, request.FILES) bucketname = request.POST['bucketname'] file_obj = request.FILES['file'] filename = str(file_obj.name) if student.is_valid(): bucket_list = bucketlist() for bucket in bucket_list: if bucket.name == str(bucketname): context[ 'error'] = "The Bucket Name already exists.Choose other Buket Name" return render(request, 'myapp/message.html', context) handle_uploaded_file(request.FILES['file']) uploadfile = "/root/demoproject/myapp/static/upload/" + filename boto3connection(bucketname, filename, uploadfile) context[ 'error'] = "The NEW BUCKET is created : " + bucketname + " and The FIle is Uploaded Successfully in that Bucket" return render(request, 'myapp/message.html', context) else: student = StudentForm() return render(request, "myapp/s3.html", {'form': student})
def put(self, request, *args, **kwargs): json_valid = is_json(request.body) if not json_valid: return render_to_http_response(json.dumps( {'msg': 'Pls send me valid data'}), status=400) pdata = json.loads(request.body) id = pdata.get('id', None) print(id) if id is None: return self.render_to_http_response(json.dumps( {'msg': 'Pls send me valid id'}), status=400) obj = Student.objects.get(id=id) if obj is None: return render_to_http_response(json.dumps( {'msg': 'Obj does not exist'}), status=400) old_obj = { "name": obj.name, "rollno": obj.rollno, "marks": obj.marks, "gf": obj.gf, "bf": obj.bf, } old_obj.update(pdata) form = StudentForm(old_obj, instance=obj) if form.is_valid(): form.save(commit=True) return self.render_to_http_response( json.dumps({'msg': 'Resource Updated successfully'})) if form.errors: json_data = json.dumps(form.errors) return selr.render_to_http_response(json_data, status=400)
def form_view(request): form = StudentForm() if request.method == 'POST': form = StudentForm(request.POST) if form.is_valid(): form.save() return redirect('/') return render(request, 'home.html', {'form': form})
def index11(request): if request.method == 'POST': student = StudentForm(request.POST, request.FILES) if student.is_valid(): handle_uploaded_file(request.FILES['file']) return HttpResponse("File Uploaded succesfully") else: student = StudentForm() return render(request, 'index2.html', {'form': student})
def edit(request, id): data = Student.objects.get(id=id) if request.method == "POST": form = StudentForm(request.POST, instance=data) if form.is_valid(): form.save() return redirect('/details') form = StudentForm(instance=data) return render(request, 'myapp/edit.html', {'form': form, 'data': data})
def register(request): if request.method == 'POST': stuform = StudentForm(request.POST) if stuform.is_valid(): user = stuform.save(commit=False) user.set_password(stuform.cleaned_data['password']) user.save() return HttpResponseRedirect(reverse('myapp:index')) else: form = StudentForm() return render(request, 'myapp/register.html', {'form': form})
def post(self,request,**kwargs): pk=self.kwargs.get('pk') form = StudentForm(request.POST) if form.is_valid(): student_data = student_details.objects.get(uid=pk) student_data.uid = form.cleaned_data['uid'] student_data.name = form.cleaned_data['name'] student_data.gender = form.cleaned_data['gender'] student_data.mother_tongue = form.cleaned_data['mother_tongue'] student_data.nationality = form.cleaned_data['nationality'] student_data.save() student_list = student_details.objects.get(uid=pk) return render(request,'view.html',{'student_list':student_list, 'pk':pk})
def post(self,request,**kwargs): form = StudentForm(request.POST) if form.is_valid(): student = student_details( uid = form.cleaned_data['uid'], name = form.cleaned_data['name'], gender = form.cleaned_data['gender'], mother_tongue = form.cleaned_data['mother_tongue'], nationality = form.cleaned_data['nationality'], ) student.save() student_list = student_details.objects.all() return render(request,'view.html',{'student_list':student_list})
def post(self, request, *args, **kwargs): data = request.body valid_json = is_json(request.body) if not valid_json: return render_to_http_response(json.dumps( {'msg': 'Pls send me valid data'}), status=400) pdata = json.loads(request.body) stuForm = StudentForm(pdata) if stuForm.is_valid(): stuForm.save(commit=True) return self.render_to_http_response(json.dumps( {'msg': 'Resource created successfully'}), status=201) if stuForm.errors: json_data = json.dumps(form.errors) return self.render_to_http_response(json_data, status=400)
def register(req): if req.method == 'POST': form = StudentForm(req.POST) usnm = req.POST['username'] if usnm.strip(): if Student.objects.filter(username__exact=usnm): return HttpResponse( 'username has already used, Please change another') if form.is_valid(): #user = User.objects.create_user(form.cleaned_data['username'], '', form.cleaned_data['password']) usr = form.save(commit=True) usr.num_responses = 1 usr.save() u = User.objects.get(username__exact=usnm) u.set_password(form.cleaned_data['password']) u.save() return HttpResponseRedirect(reverse('myapp:login')) else: return HttpResponse('Invalid login details.') else: form = StudentForm() return render(req, 'myapp/register.html', {'form': form})