Exemplo n.º 1
0
def delete_staff(request, profile_id):
    if not is_manager(user=request.user):
        print("You are permitted")
        logout(request)
        return redirect('login')
    staff = get_object_or_404(Account, id=profile_id)
    return render(request, 'accounts/delete_staff.html', {"staff": staff})
Exemplo n.º 2
0
def delete_task(request, task_id):
    if not is_manager(user=request.user):
        print("You are permitted")
        logout(request)
        return redirect('login')
    task = get_object_or_404(StaffTask, id=task_id)
    return render(request, 'workbook/delete_task.html', {"task": task})
Exemplo n.º 3
0
def confirm_delete_task(request, task_id):
    if not is_manager(user=request.user):
        print("You are permitted")
        logout(request)
        return redirect('login')
    task = get_object_or_404(StaffTask, id=task_id)
    task.delete()
    messages.success(request, "{} Task was successfully deleted".format(task))
    return redirect('manage_all_task')
Exemplo n.º 4
0
def modify_staff(request, profile_id=None):
    if not is_manager(user=request.user):
        print("You are permitted")
        logout(request)
        return redirect('login')
    staff = get_object_or_404(Account, id=profile_id)
    form = ModifyForm(request.POST or None, request.FILES or None, instance = staff)
    if form.is_valid():
        staff_update = form.save()
        messages.success(request, "Successfully Edited")
        return redirect('staff_management_list')
    context = {"staff": staff, "form": form}
    return render(request, "accounts/modify_staff.html", context)
Exemplo n.º 5
0
def modify_child_details(request, child_id=None):
    if not is_manager(user=request.user):
        print("You are permitted")
        logout(request)
        return redirect('login')

    child = get_object_or_404(Child, id=child_id)
    form = ChildModifyForm(request.POST or None, request.FILES or None, instance=child)
    if form.is_valid():
        updated = form.save()
        messages.success(request, "Child successfully updated")
        return redirect('children_list')
    context = {"child": child, "form": form}
    return render(request, "children/modify_child_details.html", context)
Exemplo n.º 6
0
def confirm_delete_staff(request, profile_id):
    if not is_manager(user=request.user):
        print("You are permitted")
        logout(request)
        return redirect('login')
    account = get_object_or_404(Account, id=profile_id)
    username = account.user.username
    user_instance = User.objects.get(username=username)
    # if user_instance is not None:
    #     print(user_instance)
    #     user_instance.delete()
    #     return redirect("staff_management_list")
    account.delete()
    messages.success(request, "{} Account was successfully deleted".format(account))
    return redirect('staff_management_list')
Exemplo n.º 7
0
def create_task(request):
    if not is_manager(user=request.user):
        print("You are permitted")
        logout(request)
        return redirect('login')

    if request.method == 'POST':
        form = StaffTaskForm(request.POST)
        if form.is_valid():
            task = form.save(commit=False)
            task.save()
            return redirect('manage_all_task')
    else:
        form = StaffTaskForm()
    return render(request, "workbook/create_task.html", {"form": form})
Exemplo n.º 8
0
def register_child(request):
    if not is_manager(user=request.user):
        print("You are permitted")
        logout(request)
        return redirect('login')

    if request.method == 'POST':
        form = ChildRegisterForm(request.POST, request.FILES or None)
        if form.is_valid():

            form.save(commit=True)
            messages.success(request, "New child successfully registered")
            return redirect('children_list')
    else:
        form = ChildRegisterForm()
    return render(request, "children/register_child.html", {"form": form})
Exemplo n.º 9
0
def edit_task(request, task_id=None):
    if not is_manager(user=request.user):
        print("You are permitted")
        logout(request)
        return redirect('login')

    task = get_object_or_404(StaffTask, id=task_id)
    form = StaffTaskForm(request.POST or None,
                         request.FILES or None,
                         instance=task)
    if form.is_valid():
        task_update = form.save()
        messages.success(request, "Task successfully updated")
        return redirect('manage_all_task')
    context = {"task": task, "form": form}
    return render(request, "workbook/edit_task.html", context)
Exemplo n.º 10
0
def register_staff(request):
    if not is_manager(user=request.user):
        print("You are permitted")
        logout(request)
        return redirect('login')

    if request.method == 'POST':
        form = RegForm(request.POST, request.FILES or None)
        if form.is_valid():
            password = form.cleaned_data['password']
            username = form.cleaned_data['email']

            new_user =User.objects.create_user(username=username, email=username, password=password)
            new_user.save()

            account = form.save(commit=False)
            account.user = new_user
            account.email = username
            account.save()
            messages.success(request, "New Staff successfully registered")
            return redirect('register_staff')
    else:
        form = RegForm()
    return render(request, "accounts/register_staff.html", {"form": form})