def assign(request, pk): companyName = models.Company.objects.get(pk=pk) assign_form = Form.AssignEmployee() #assign_form = Form.AssingForm(companyId=pk) if request.method == 'POST': #data = request.POST.copy() #data['companyId'] = pk #assign_form = Form.AssingForm(data) assign_form = Form.AssignEmployee(request.POST) if assign_form.is_valid(): company_instance = models.Company.objects.get(pk=pk) employee_instance = models.Employee.objects.get( pk=request.POST['choose_employee']) models.Assigned(companyName=company_instance, employee=employee_instance).save() return HttpResponseRedirect(reverse('view_company')) return render_to_response('assignCompany.html', { 'assign_form': assign_form, 'companyId': pk }, context_instance=RequestContext(request))
def login(request, message=None): logger.info("message:" + str(message)) adminLoginForm = Form.admin_login_form() if request.method == 'GET': return render_to_response( 'adminLogin.html', {'adminLoginForm': adminLoginForm}, context_instance=RequestContext(request), ) if request.method == 'POST': adminLoginForm = Form.admin_login_form(request.POST) #this validates and check if the password is valid if adminLoginForm.is_valid(): request.session['admin'] = 'admin' return HttpResponseRedirect(reverse('view_company')) return render_to_response( 'adminLogin.html', { 'adminLoginForm': adminLoginForm, 'message': message }, context_instance=RequestContext(request), )
def feedback(request, companyId, employeeId): feedback = models.Feedback.objects.filter(company_id=companyId) company = models.Company.objects.get(pk=companyId) addFeedbackForm = Form.AddFeedbackForm() if request.method == 'POST': addFeedbackForm = Form.AddFeedbackForm(request.POST) if addFeedbackForm.is_valid(): models.Feedback(company=company, fname=request.POST['fname'], lname=request.POST['lname'], phoneNumber=request.POST['phoneNumber'], comment=request.POST['comment']).save() addFeedbackForm = Form.AddFeedbackForm() return render_to_response( 'employeeFeedback.html', { 'feedback': feedback, 'company': company, 'addFeedbackForm': addFeedbackForm, 'employeeId': employeeId }, context_instance=RequestContext(request), )
def add(request): add_company_form = Form.AddCompanyForm() if request.method == 'POST': add_company_form = Form.AddCompanyForm(request.POST, request.FILES) if add_company_form.is_valid(): add_company_form.save() return HttpResponseRedirect(reverse('view_company')) return render_to_response('addCompany.html', {'add_company_form': add_company_form}, context_instance=RequestContext(request))
def add(request): add_employee_form = Form.AddEmployeeForm() if request.method == 'POST': add_employee_form = Form.AddEmployeeForm(request.POST) if add_employee_form.is_valid(): add_employee_form.save() return HttpResponseRedirect(reverse('view_employee')) return render_to_response('addEmployee.html', {'add_employee_form': add_employee_form}, context_instance=RequestContext(request))
def edit(request, pk): company = models.Company.objects.get(pk=pk) edit_company_form = Form.AddCompanyForm(instance=company) if request.method == 'POST': edit_company_form = Form.AddCompanyForm(request.POST, instance=company) if edit_company_form.is_valid(): edit_company_form.save() return HttpResponseRedirect(reverse('view_company')) return render_to_response('editCompany.html', { 'edit_company_form': edit_company_form, 'companyId': pk }, context_instance=RequestContext(request))
def edit(request, pk): edit_employee_form = Form.AddEmployeeForm() employee = models.Employee.objects.get(pk=pk) if request.method == 'GET': edit_employee_form = Form.AddEmployeeForm(instance=employee) else: edit_employee_form = Form.AddEmployeeForm(request.POST, instance=employee) if edit_employee_form.is_valid(): edit_employee_form.save() return HttpResponseRedirect(reverse('view_employee')) return render_to_response('editEmployee.html', { 'edit_employee_form': edit_employee_form, 'employeeId': pk }, context_instance=RequestContext(request))
def login(request): employeeLoginForm = Form.EmployeeLoginForm() if request.method == 'POST': employeeLoginForm = Form.EmployeeLoginForm(request.POST) if employeeLoginForm.is_valid(): employee = models.Employee.objects.get( fname=request.POST['fname'], lname=request.POST['lname'], password=request.POST['password']) return HttpResponseRedirect( reverse('employeeAssignedCompany', kwargs={'employeeId': employee.pk})) return render_to_response( "employeeLogin.html", {'employeeLoginForm': employeeLoginForm}, context_instance=RequestContext(request), )
def login(request): adminLoginForm = Form.admin_login_form() if request.method == 'GET': return render_to_response( 'adminLogin.html', {'adminLoginForm': adminLoginForm}, context_instance=RequestContext(request), ) if request.method == 'POST': adminLoginForm = Form.admin_login_form(request.POST) #this validates and check if the password is valid if adminLoginForm.is_valid(): return HttpResponseRedirect(reverse('view_company')) return render_to_response( 'adminLogin.html', {'adminLoginForm': adminLoginForm}, context_instance=RequestContext(request), )
def change_password(request): change_admin_password_form = Form.change_password_form() if request.method == 'POST': change_admin_password_form = Form.change_password_form(request.POST) if change_admin_password_form.is_valid(): #save the new password try: admin_password = models.Admin.objects.get( admin_name='admin_name') except models.Admin.DoesNotExist: admin_password = models.Admin(admin_name='admin_name', password='') admin_password.password = request.POST['new_password'] admin_password.save() return HttpResponseRedirect(reverse('admin_login')) return render_to_response( 'change_password.html', {'change_admin_password_form': change_admin_password_form}, context_instance=RequestContext(request))