def resources_page(request): if request.POST: department_id = request.POST.get('department_id') if department_id: try: department = get_department(department_id) except ValueError: return HttpResponseRedirect(reverse(resources_page)) department = get_department(department_id) departments = get_all_departments() departments = get_all_departments() resources = get_all_resources() context = { "learning_and_development_page": "active", "departments": departments, "resources": Resource.objects.filter(department=department) } return render(request, 'learning_and_development/resources.html', context) else: return HttpResponseRedirect(reverse(resources_page)) departments = get_all_departments() resources = get_all_resources() context = { "learning_and_development_page": "active", "departments": departments, "resources": resources } return render(request, 'learning_and_development/resources.html', context)
def edit_resource_page(request, resource_id): resource = get_resource(resource_id) if request.POST: name = request.POST.get('name') year_published = request.POST.get('year_published') producer = request.POST.get('producer') file_format = request.POST.get('file_format') department_id = request.POST.get('department') department = get_department(department_id) description = request.POST.get('description') file = request.FILES.get('file') if not file: file = resource.file Resource.objects.filter(id=resource_id).update( name=name, year_published=year_published, producer=producer, file_format=file_format, department=department, description=description, file=file, ) return HttpResponseRedirect(reverse(manage_resources_page)) departments = get_all_departments() context = { "learning_and_development_page": "active", "resource": resource, "departments": departments } return render(request, 'learning_and_development/edit_resource.html', context)
def manage_resources_page(request): if request.POST and request.FILES: name = request.POST.get('name') year_published = request.POST.get('year_published') producer = request.POST.get('producer') file_format = request.POST.get('file_format') department_id = request.POST.get('department') department = get_department(department_id) description = request.POST.get('description') file = request.FILES.get('file') Resource.objects.create( name=name, year_published=year_published, producer=producer, file_format=file_format, department=department, description=description, file=file, ) return HttpResponseRedirect(reverse(manage_resources_page)) resources = get_all_resources() departments = get_all_departments() context = { "learning_and_development_page": "active", "departments": departments, "resources": resources, } return render(request, 'learning_and_development/manage_resources.html', context)
def manage_departments_page(request): context = { "user": request.user, "organisation_page": "active", "departments": get_all_departments(), "employees": get_active_employees(), } return render(request, "organisation_details/manage_departments.html", context)
def edit_team_page(request, team_id): if request.POST: team = get_team(team_id) team_name = request.POST["team_name"] supervisor_id = request.POST["supervisor_id"] department_id = request.POST["department_id"] supervisor = get_employee(supervisor_id) department = get_department(department_id) team.department = department team.supervisor = supervisor team.name = team_name team.save() messages.success(request, f'Team Info changed Successfully') return redirect('manage_teams_page') context = { "user": request.user, "team": get_team(team_id), "employees": get_active_employees(), "departments": get_all_departments(), "organisation_page": "active" } return render(request, 'organisation_details/edit_team.html', context)