def department_add(request, template_name='departments/department_add.html'): form = DepartmentForm(request.POST or None) username = request.session['username'] print username if form.is_valid(): print form form.save() return redirect('department_list') return render(request, template_name, { 'form': form, 'username': username, 'var3': 'active', })
def add_department_view(request): from forms import DepartmentForm form = None if request.method == 'POST': form = DepartmentForm(request.POST) if form.is_valid(): form.save() else: form = DepartmentForm() deps = main_utils.get_all_departments() from django.template import RequestContext return render_to_response('maitenance/department.html', RequestContext(request, {'form': form, 'deps': deps}))
def departments(request): if request.POST: form = DepartmentForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/departments/') else: form = DepartmentForm() title = "Departments" types = Department.objects.all() url = "departments" return render(request, 'add.html', locals())
def department_edit(request, pk, template_name='departments/department_add.html'): username = request.session['username'] deps = get_object_or_404(Department, pk=pk) form = DepartmentForm(request.POST or None, instance=deps) if form.is_valid(): form.save() return redirect('department_list') return render(request, template_name, { 'form': form, 'username': username, 'var3': 'active', 'deps': deps, })
def editdepartments(request, type_id): types = get_object_or_404(Department, pk=type_id) t = "Edit" if request.POST: form = DepartmentForm(request.POST, instance=types) if form.is_valid(): form.save() return HttpResponseRedirect('/departments/') else: form = DepartmentForm(instance=types) types = Department.objects.all() title = "Edit Departments" url = "departments" return render_to_response("edit.html", { 'form': form, 't': t, }, context_instance=RequestContext(request, locals()))