예제 #1
0
def update_view(request,id):
    employee=Employee.objects.get(id=id)
    if request.method=='POST':
        form=EmployeeForm(request.POST,instance=employee)
        if form.is_valid():
            form.save()
            return redirect('/')
    return render(request,'testApp/update.html',{'employee':employee})
예제 #2
0
def create_view(request):
    form=EmployeeForm()
    if request.method=='POST':
        form=EmployeeForm(request.POST)
        if form.is_valid():
            form.save()
        return redirect('/')
    return render(request,'testApp/create.html',{'form':form})
예제 #3
0
def employee_addinfo(request):
    form = EmployeeForm()
    if request.method == 'POST':
        form = EmployeeForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/home')
    return render(request, 'testApp/update.html', {'form': form})
예제 #4
0
def create_view(request):
    form=EmployeeForm()
    if request.method=='POST':
        form=EmployeeForm(request.POST) #get the data from the form
        if form.is_valid():#basic authentication
            form.save()#save the data from the form
        return redirect('/r')#return to homepage after submitting the form
    return render(request,'testApp/create.html',{'form':form})
예제 #5
0
def employee_info_update(request, id):
    id = int(id)
    employee = Employee.objects.get(id=id)
    if request.method == 'POST':
        form = EmployeeForm(request.POST, instance=employee)
        if form.is_valid():
            form.save()
            return redirect('/home')
    return render(request, 'testApp/update1.html', {'employee': employee})
예제 #6
0
 def post(self, request, *args, **kwargs):
     data = request.body
     valid_json = is_json(data)
     if not valid_json:
         json_data = json.dumps({'msg': 'Please send valid json data only'})
         return self.render_to_http_response(json_data, status=400)
     empdata = json.loads(data)
     form = EmployeeForm(empdata)
     if form.is_valid():
         form.save(commit=True)
         json_data = json.dumps({'msg': 'Resource created successfully.'})
         return self.render_to_http_response(json_data)
     if form.errors:
         json_data = json.dumps(form.errors)
         return self.render_to_http_response(json_data, status=400)
예제 #7
0
 def put(self, request, *args, **kwargs):
     data = request.body
     valid_json = is_json(data)
     if not valid_json:
         json_data = json.dumps(
             {'msg': 'Please send valid json data only.'})
         return self.render_to_http_response(json_data, status=200)
     p_data = json.loads(data)
     id = p_data.get('id', None)
     if id is None:
         json_data = json.dumps({
             'msg':
             'To perform updation id is mondatory, please provide..'
         })
         return self.render_to_http_response(json_data, status=404)
     emp = self.get_object_by_id(id)
     if emp is None:
         json_data = json.dumps(
             {'msg': 'No resource with matched id, not possilbe updation'})
         return self.render_to_http_response(json_data, status=404)
     provided_data = json.loads(data)
     original_data = {
         'eno': emp.eno,
         'ename': emp.ename,
         'esal': emp.esal,
         'eaddr': emp.eaddr,
     }
     original_data.update(provided_data)
     form = EmployeeForm(original_data, instance=emp)
     if form.is_valid():
         form.save(commit=True)
         json_data = json.dumps({'msg': 'Resource updated successfully.'})
         return self.render_to_http_response(json_data)
     if form.errors:
         json_data = json.dumps(form.errors)
         return self.render_to_http_response(json_data, status=400)