def edit_staff(request, object_id): try: object_id = int(object_id) except ValueError: return HttpResponseRedirect(reverse('workflowmax-staff-list')) context_vars = dict() context_vars['header'] = capfirst(_('edit staff %d') % object_id) staff = Staff.objects.get(id=object_id) form = StaffForm(staff.to_dict()) helper = FormHelper() helper.form_class = 'uniform' submit = Submit('save',_('save')) helper.add_input(submit) if request.method == "POST": form = StaffForm(request.POST, request.FILES) if form.is_valid(): staff.name = form.cleaned_data['name'] staff.address = form.cleaned_data['address'] staff.phone = form.cleaned_data['phone'] staff.mobile = form.cleaned_data['mobile'] staff.email = form.cleaned_data['email'] staff.payrollcode = form.cleaned_data['payrollcode'] staff.save() return HttpResponseRedirect(reverse('workflowmax-staff', args=[staff.id])) context_vars['form'] = form context_vars['helper'] = helper return direct_to_template(request, template='workflowmax/form.html', extra_context=context_vars)
def add_staff(request): context_vars = dict() context_vars['header'] = capfirst(_('add new staff')) form = StaffForm() helper = FormHelper() helper.form_class = 'uniform' submit = Submit('save',_('save')) helper.add_input(submit) if request.method == "POST": form = StaffForm(request.POST, request.FILES) if form.is_valid(): staff = Staff() staff.name = form.cleaned_data['name'] staff.address = form.cleaned_data['address'] staff.phone = form.cleaned_data['phone'] staff.mobile = form.cleaned_data['mobile'] staff.email = form.cleaned_data['email'] staff.payrollcode = form.cleaned_data['payrollcode'] staff = staff.save() return HttpResponseRedirect(reverse('workflowmax-staff', args=[staff.id])) context_vars['form'] = form context_vars['helper'] = helper return direct_to_template(request, template='workflowmax/form.html', extra_context=context_vars)