Exemplo n.º 1
0
def emp(request):
    if request.method == "POST":
        form = EmployeeForm(request.POST)
        if form.is_valid():
            try:
                form.save()
                return redirect('/show')
            except:
              pass
    else:
        form = EmployeeForm()
    return render(request,"index.html",{'form':form})
Exemplo n.º 2
0
def emp(request):
    if request.method == "POST":
        form = EmployeeForm(request.POST)  # here "form" is one varible
        if form.is_valid():
            try:
                form.save()
                return redirect("/show")
            except:
                pass
    else:
        form = EmployeeForm()
    return render(request, "index.html", {'form': form})
Exemplo n.º 3
0
def update(request, id):
    # def update(request, id, name):

    data = Employee.objects.get(id=id)
    # select * from employee where id = id
    form = EmployeeForm()
    if request.method == 'POST':
        form = EmployeeForm(
            request.POST, instance=data
        )  # read value from data and it will map with form object
        if form.is_valid():
            emp = Employee()  # saving database in reference of model
            emp.id = id
            empName = form.cleaned_data['emp_email'].split('@')[0]
            emp.emp_name = empName
            emp.emp_email = form.cleaned_data['emp_email']
            emp.address = form.cleaned_data['address']
            emp.phone = form.cleaned_data['phone']
            # emp.pincode = form.cleaned_data['pincode']
            emp.save()
            return redirect(index)

            # form.save()
    return render(request, 'crud/update.html', {'form': form})
Exemplo n.º 4
0
def emp(request):
    if request.method=="POST":
        form=EmployeeForm(request.POST)
        regex = '^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$'
        employees = Employee.objects.all()
        dict=[]
        for employee in employees:
            dict.append(employee.eid)

        if form.is_valid() and form.data['eid'] in dict:
            return render(request,"eid.html",{'form':form})
        if form.is_valid() and len(form.data['econtact'])==10 and re.search(regex,form.data['eemail'])!=None:
            try:
                form.save()
                return redirect("/show")
            except:
                pass
        else:
            return render(request,"error.html",{'form':form})
    else:
        form=EmployeeForm()
    return render(request,"index.html",{'form':form})
 def post(self, request):
     form = EmployeeForm(request.POST)
     if form.is_valid():
         form.save()
         return redirect(index)
     return render(request, 'crud/create.html', {'form': form})
 def get(self, request):
     print('ASd')
     form = EmployeeForm()
     return render(request, 'crud/create.html', {'form': form})