示例#1
0
def insert_into_department(request) :
	if request.method == 'POST' :
		form = DepartmentForm(request.POST) 
		if form.is_valid() :
			c = connection.cursor() 
			dept_name = form.cleaned_data['dept_name']
			HOD = form.cleaned_data['HOD']
			floor_no = form.cleaned_data['floor_no']		
			c.execute("insert into department VALUES(%s , %s , %s )" , [dept_name , HOD , floor_no])
			c.close()
	return HttpResponseRedirect("/mani_tables/show_department")
示例#2
0
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',
    })
示例#3
0
文件: views.py 项目: ArthurWu/e-leave
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}))
示例#4
0
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())
示例#5
0
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,
    })
示例#6
0
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()))