def addDepartment(request): if request.method == "GET": form = DepartmentForm() return render_to_response("institution/department/add_department.html",{'form':form},RequestContext(request)) elif request.method == "POST": form = DepartmentForm(request.POST) if form.is_valid() : d = Department() d.name = form.cleaned_data['name'] d.established = form.cleaned_data['established'] d.institute = request.institute d.user = request.user d.save() create_message(request,"Succesfully added the department") return HttpResponseRedirect(reverse('showdepartmenturl')) else: return render_to_response("institution/department/add_department.html",{'form':form},RequestContext(request))
def editDepartment(request,department_id): mlogger.debug("Editing the department %s ", (department_id,)) department_id = int(department_id) department = Department.objects.get(pk=department_id) if request.user.id == department.user.id : if request.method == "GET" : mlogger.debug("the person who posted the job is editing") form = DepartmentForm(instance=department) return render_to_response('institution/department/add_department.html',{'form':form,'editmode':True},RequestContext(request)) elif request.method == "POST": form = DepartmentForm(request.POST, instance=department) if form.is_valid() : form.save() create_message(request,"Successfuly edited the department") return HttpResponseRedirect(reverse('showdepartmenturl')) else: return render_to_response('institution/department/add_department.html',{'form':form,'editmode':True},RequestContext(request)) else : create_message(request,"You are not authorized to edit this job") return HttpResponseRedirect(reverse('showdepartmenturl'))