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})
Пример #2
0
def register(request):
    if request.method == "POST":
        form = StudentForm(request.POST)
        form.save()
        messages.success(request, "Your data saved successfully!!")
    form = StudentForm()
    return render(request, 'myapp/register.html', {'form': form})
Пример #3
0
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})
Пример #4
0
def register(request):
    if request.method == "POST":
        form = StudentForm(request.POST)
        form.save()
        messages.success(request, 'your data is added successfully')
        #return HttpResponse('Done')
    form = StudentForm()
    return render(request, 'myapp/register.html', {'form': form})
Пример #5
0
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})
Пример #6
0
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})
Пример #7
0
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})
Пример #8
0
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})
Пример #9
0
 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)
Пример #10
0
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})
Пример #11
0
 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)