Requirements are now dynamic

main
emile 2 years ago
parent 5c2b4c6eae
commit 7cfc68a208

Binary file not shown.

@ -246,28 +246,26 @@ def save_note(request):
return render(request, 'addnote-modal.html') return render(request, 'addnote-modal.html')
@login_required @login_required
def save_project(request): def save_project(request):
if request.method == 'POST': if request.method == 'POST':
name = request.POST.get('name') name = request.POST.get('name')
customer_username = request.POST.get('customer') customer_username = request.POST.get('customer')
manager_username = request.POST.get('manager') manager_username = request.POST.get('manager')
project_type = request.POST.getlist('project_type') # Use getlist for multi-select fields project_type = request.POST.getlist('project_type')
details = request.POST.get('details') details = request.POST.get('details')
members_usernames = request.POST.getlist('members') # Use getlist for multi-select fields members_usernames = request.POST.getlist('members')
status = request.POST.get('status') status = request.POST.get('status')
start_date = request.POST.get('start_date') start_date = request.POST.get('start_date')
end_date = request.POST.get('end_date') end_date = request.POST.get('end_date')
# Fetch the associated profiles
try: try:
customer_profile = CustomerProfile.objects.get(user__username=customer_username) customer_profile = CustomerProfile.objects.get(user__username=customer_username)
manager_profile = StaffProfile.objects.get(user__username=manager_username) manager_profile = StaffProfile.objects.get(user__username=manager_username)
members_profiles = StaffProfile.objects.filter(user__username__in=members_usernames) members_profiles = StaffProfile.objects.filter(user__username__in=members_usernames)
except (CustomerProfile.DoesNotExist, StaffProfile.DoesNotExist): except (CustomerProfile.DoesNotExist, StaffProfile.DoesNotExist):
# Handle the case where customer_profile or manager_profile is not found
pass pass
# Create and save the project # Create and save the project
project = Project( project = Project(
@ -281,13 +279,18 @@ def save_project(request):
) )
project.save() project.save()
project.project_type.set(project_type) project.project_type.set(project_type)
project.members.set(members_profiles) project.members.set(members_profiles)
# Save project requirements
requirements = request.POST.getlist('requirements') # Assuming 'requirements' is the name of your requirement input field
for requirement_content in requirements:
if requirement_content:
requirement = ProjectRequirement(content=requirement_content, project=project)
requirement.save()
return redirect('my-projects') return redirect('my-projects')
return render(request, 'createproject.html')
@login_required @login_required

@ -62,15 +62,15 @@
<div class="w-full p-3 border border-gray-300 mt-4 rounded-md"> <div class="w-full p-3 border border-gray-300 mt-4 rounded-md">
<div class="w-full mt-2" id="addReqContainer"> <div class="w-full mt-2" id="addReqContainer">
<input type="text" placeholder="Requirement" <input name="requirements" type="text" placeholder="Requirement"
class="w-full p-3 border border-gray-300 rounded-md bg-transparent outline-none" required> class="w-full p-3 border border-gray-300 rounded-md bg-transparent outline-none">
</div> </div>
<!-- THE CLONED CONTAINER --> <!-- THE CLONED CONTAINER -->
<div class="mt-2 hidden" id="addReqContainerTemplate"> <div class="mt-2 hidden" id="addReqContainerTemplate">
<div class="w-full flex flex-col gap-2"> <div class="w-full flex flex-col gap-2">
<input type="text" placeholder="Requirement" <input name="requirements" type="text" placeholder="Requirement"
class="w-full p-3 border border-gray-300 rounded-md bg-transparent outline-none" required> class="w-full p-3 border border-gray-300 rounded-md bg-transparent outline-none">
<button <button
class="w-full h-[55px] rounded-md bg-gray-300 border-none outline-none shadow-md text-white text-xl cursor-pointer py-2" class="w-full h-[55px] rounded-md bg-gray-300 border-none outline-none shadow-md text-white text-xl cursor-pointer py-2"
id="removeReqButton" type="button"> id="removeReqButton" type="button">

Loading…
Cancel
Save