def employee_add_workinghours(request, employee_id): employee= get_object_or_404(ServiceProviderEmployee, id=employee_id) if request.method == 'POST': form = EmployeeWorkingHoursForm(request.POST, employee=employee) #employee=employee form_valid = form.is_valid() if form_valid: service = form.save(commit=False) service.service_provider = request.user.service_provider service.service = form.cleaned_data['service'] # Save service.service_provider_employee = employee service.save() return HttpResponseRedirect(reverse(employee_workinghours, kwargs={'employee_id':employee.id})) else: initial = {} wh = EmployeeWorkingHours.objects.filter(service_provider_employee=employee) if wh.__len__()==0: initial['week_days'] = '1,2,3,4,5' form = EmployeeWorkingHoursForm(initial=initial, employee=employee) #employee=employee return render_to_response('workinghours/employee_add_workinghours.html', locals(), context_instance=RequestContext(request))
def employee_edit_workinghours(request, id): workinghours = get_object_or_404(EmployeeWorkingHours, service_provider=request.user.service_provider, id=id) employee = ServiceProviderEmployee.objects.get(pk=workinghours.service_provider_employee_id) if request.method == 'POST': form = EmployeeWorkingHoursForm(request.POST, instance=workinghours, employee=employee) form_valid = form.is_valid() if form_valid: service = form.save(commit=False) service.service_provider = request.user.service_provider service.service = form.cleaned_data['service'] # Save service.service_provider_employee = employee service.save() return HttpResponseRedirect(reverse(employee_workinghours, kwargs={'employee_id':employee.id})) else: form = EmployeeWorkingHoursForm(instance=workinghours, employee=employee) return render_to_response('workinghours/employee_edit_workinghours.html', locals(), context_instance=RequestContext(request))
def employee_edit_workinghours(request, id): workinghours = get_object_or_404( EmployeeWorkingHours, service_provider=request.user.service_provider, id=id) employee = ServiceProviderEmployee.objects.get( pk=workinghours.service_provider_employee_id) if request.method == 'POST': form = EmployeeWorkingHoursForm(request.POST, instance=workinghours, employee=employee) form_valid = form.is_valid() if form_valid: service = form.save(commit=False) service.service_provider = request.user.service_provider service.service = form.cleaned_data['service'] # Save service.service_provider_employee = employee service.save() return HttpResponseRedirect( reverse(employee_workinghours, kwargs={'employee_id': employee.id})) else: form = EmployeeWorkingHoursForm(instance=workinghours, employee=employee) return render_to_response('workinghours/employee_edit_workinghours.html', locals(), context_instance=RequestContext(request))
def employee_add_workinghours(request, employee_id): employee = get_object_or_404(ServiceProviderEmployee, id=employee_id) if request.method == 'POST': form = EmployeeWorkingHoursForm(request.POST, employee=employee) #employee=employee form_valid = form.is_valid() if form_valid: service = form.save(commit=False) service.service_provider = request.user.service_provider service.service = form.cleaned_data['service'] # Save service.service_provider_employee = employee service.save() return HttpResponseRedirect( reverse(employee_workinghours, kwargs={'employee_id': employee.id})) else: initial = {} wh = EmployeeWorkingHours.objects.filter( service_provider_employee=employee) if wh.__len__() == 0: initial['week_days'] = '1,2,3,4,5' form = EmployeeWorkingHoursForm(initial=initial, employee=employee) #employee=employee return render_to_response('workinghours/employee_add_workinghours.html', locals(), context_instance=RequestContext(request))
def addemp(request, id): emp = Employee.objects.get(id=id) if request.method == 'POST': form = EmployeeWorkingHoursForm(request.POST, employee=emp) valid = form.is_valid() if valid: wh = form.save(commit=False) wh.employee = emp wh.save() path = '/myemployees/edit/' + id return HttpResponseRedirect(path) else: initial = {} if not EmployeeWorkingHours.objects.filter(employee=emp).exists(): initial['week_days'] = '1,2,3,4,5' else: t = EmployeeWorkingHours.objects.filter(employee=emp) #initial['week_days'] = t[0].week_days #initial['time_from'] = t[0].time_from #initial['time_to'] = t[0].time_to form = EmployeeWorkingHoursForm(initial=initial, employee=emp) return render_to_response('workinghours/addemp.html', locals(), context_instance=RequestContext(request))