Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
def edit_department_page(request, department_id):
    department = get_department(department_id)
    context = {
        "user": request.user,
        "employees": get_active_employees(),
        "department": department,
        "organisation_page": "active"
    }
    return render(request, 'organisation_details/edit_department.html', context)
Example #5
0
def department_employees(request, department_id):
    department_employees=get_department_employees(department_id)

    department = get_department(department_id)
    context={
        "employees": department_employees,
        "department": department
    }

    return render(request, "organisation_details/department_employees.html", context)
Example #6
0
def delete_department(request, department_id):
    try:
        department = get_department(department_id)
        department.delete()
        messages.success(request, f'Department Deleted Successfully')
        return redirect('manage_departments_page')
    except Department.DoesNotExist:
        messages.error(request, f'The department no longer exists on the system')

    return redirect('manage_departments_page')
Example #7
0
def edit_department(request):
    if request.method == "POST":
        department_id = request.POST.get('department_id')
        employee_id = request.POST.get('employee_id')
        employee = get_employee(employee_id)
        department = get_department(department_id)
        department.name = request.POST.get('department_name')
        department.hod = employee
        department.save()

        messages.success(request, f'Department Info Changed Successfully')
        return redirect('manage_departments_page')

    messages.error(request, f'Changes Not Saved, Check your inputs and try again!')
    return redirect('manage_departments_page')
Example #8
0
def add_new_team(request):
    if request.method == "POST":
        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 = Team.objects.filter(name=team_name)

        if team:
            messages.warning(request, f'Team Already Exists')

            return redirect('manage_teams_page')
        else:
            team = Team(department=department, name=team_name, supervisor=supervisor)
            team.save()
            messages.success(request, f'Team {team_name} added Successfully Saved')

            return redirect('manage_teams_page')

    return redirect('manage_teams_page')
Example #9
0
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)