emile 10 months ago
parent 708939c1d3
commit ccbec47cab

Binary file not shown.

@ -131,7 +131,7 @@ def add_business(request):
@staff_login_required @staff_login_required
def add_staff(request): def add_staff(request):
staffpositions = StaffPosition.objects.all().order_by('-id') jobpositions = JobPosition.objects.all().order_by('-id')
if request.method == 'POST': if request.method == 'POST':
email = request.POST.get('email').lower() email = request.POST.get('email').lower()
first_name = request.POST.get('first_name') first_name = request.POST.get('first_name')
@ -160,26 +160,41 @@ def add_staff(request):
user.last_name = last_name.lower().capitalize() user.last_name = last_name.lower().capitalize()
user.save() user.save()
staff_positionid = request.POST.get('staff_position')
staff_position = get_object_or_404(StaffPosition, id=staff_positionid)
if request.POST.get('intern'): if request.POST.get('intern'):
intern = True intern = True
else: else:
intern = False intern = False
StaffProfile.objects.create( staff = StaffProfile.objects.create(
user=user, user=user,
image=request.FILES.get('image'), image=request.FILES.get('image'),
mobile_number=request.POST.get('mobile_number'), mobile_number=request.POST.get('mobile_number'),
active=active, active=active,
intern=intern, intern=intern,
staff_position=staff_position,
) )
position_ids = request.POST.getlist('position[]')
start_dates = request.POST.getlist('start_date[]')
end_dates = request.POST.getlist('end_date[]')
for position_id, start_date, end_date in zip(position_ids, start_dates, end_dates):
position = get_object_or_404(JobPosition, id=position_id)
if end_date:
end_date = end_date
else:
end_date = None
StaffPosition.objects.create(
staff = staff,
position = position,
start_date = start_date,
end_date = end_date
)
return redirect('users') return redirect('users')
context = { context = {
'staffpositions': staffpositions, 'jobpositions': jobpositions,
} }
return render(request, 'add_templates/add-staff.html', context) return render(request, 'add_templates/add-staff.html', context)

@ -76,8 +76,8 @@
<select name="position[]" <select name="position[]"
class="w-full h-[50px] py-1 px-3 border border-gray-300 outline-none rounded-md mt-1"> class="w-full h-[50px] py-1 px-3 border border-gray-300 outline-none rounded-md mt-1">
<option disabled selected>Select Position</option> <option disabled selected>Select Position</option>
{% for position in positions %} {% for position in jobpositions %}
<option value="{{position.id}}">{{posiiton.name}}</option> <option value="{{position.id}}">{{position.name}}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>

@ -68,6 +68,8 @@
</div> </div>
<div class="w-full flex flex-col gap-3 mt-3" id="positionsContainer"> <div class="w-full flex flex-col gap-3 mt-3" id="positionsContainer">
{% for position in positions %}
<div class="w-full p-3 bg-gray-50 border border-gray-100 rounded-md flex justify-between items-center gap-3"> <div class="w-full p-3 bg-gray-50 border border-gray-100 rounded-md flex justify-between items-center gap-3">
<div class="flex flex-col"> <div class="flex flex-col">
<p class="text-gray-500">Position: <span <p class="text-gray-500">Position: <span
@ -86,6 +88,7 @@
</svg> </svg>
</div> </div>
</div> </div>
{% endfor %}
<div class="w-full bg-gray-50 border border-gray-100 rounded-md flex items-center gap-3 p-3 initialPositionContainer" style="display: none;"> <div class="w-full bg-gray-50 border border-gray-100 rounded-md flex items-center gap-3 p-3 initialPositionContainer" style="display: none;">
<div class="w-full grid grid-cols-1 md:grid-cols-3 gap-3"> <div class="w-full grid grid-cols-1 md:grid-cols-3 gap-3">
@ -94,8 +97,8 @@
<select <select
class="w-full h-[50px] py-1 px-3 border border-gray-300 outline-none rounded-md mt-1"> class="w-full h-[50px] py-1 px-3 border border-gray-300 outline-none rounded-md mt-1">
<option disabled selected>Select Position</option> <option disabled selected>Select Position</option>
{% for position in positions %} {% for position in jobpositions %}
<option value="{{position.id}}">{{posiiton.name}}</option> <option value="{{position.id}}">{{position.name}}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>

@ -576,9 +576,31 @@ def businessdetails(request, business_id):
@staff_login_required @staff_login_required
def staffdetails( request, staff_id): def staffdetails( request, staff_id):
staff = get_object_or_404(StaffProfile, staff_id=staff_id) staff = get_object_or_404(StaffProfile, staff_id=staff_id)
jobpositions = JobPosition.objects.all().order_by('-id')
positions = StaffPosition.objects.filter(staff=staff).order_by('-id')
if request.method == 'POST':
position_ids = request.POST.getlist('position[]')
start_dates = request.POST.getlist('start_date[]')
end_dates = request.POST.getlist('end_date[]')
for position_id, start_date, end_date in zip(position_ids, start_dates, end_dates):
position = get_object_or_404(JobPosition, id=position_id)
if end_date:
end_date = end_date
else:
end_date = None
StaffPosition.objects.create(
staff = staff,
position = position,
start_date = start_date,
end_date = end_date
)
return HttpResponse('<script>window.top.location.reload();</script>')
context = { context = {
'staff' : staff, 'staff' : staff,
'positions': positions,
'jobpositions': jobpositions,
} }
return render(request, 'details_templates/staff-details.html', context) return render(request, 'details_templates/staff-details.html', context)

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 KiB

Loading…
Cancel
Save