Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions appointment/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,46 @@ class Meta:
}


class StaffMemberForm(forms.ModelForm):
class Meta:
model = StaffMember
fields = ['user', 'services_offered', 'slot_duration', 'lead_time', 'finish_time',
'appointment_buffer_time', 'work_on_saturday', 'work_on_sunday']
widgets = {
'user': forms.Select(attrs={'class': 'form-control'}),
'service_offered': forms.Select(attrs={'class': 'form-control'}),
'slot_duration': forms.NumberInput(attrs={
'class': 'form-control',
'placeholder': _('Example value: 30, 60, 90, 120... (in minutes)')
}),
'lead_time': forms.TimeInput(attrs={
'class': 'form-control',
'placeholder': _('Example value: 08:00:00, 09:00:00... (24-hour format)')
}),
'finish_time': forms.TimeInput(attrs={
'class': 'form-control',
'placeholder': _('Example value: 17:00:00, 18:00:00... (24-hour format)')
}),
'appointment_buffer_time': forms.NumberInput(attrs={
'class': 'form-control',
'placeholder': _('Example value: 15, 30, 45, 60... (in minutes)')
}),
'work_on_saturday': forms.CheckboxInput(attrs={'class': 'form-check-input'}),
'work_on_sunday': forms.CheckboxInput(attrs={'class': 'form-check-input'}),
}

def __init__(self, *args, **kwargs):
super(StaffMemberForm, self).__init__(*args, **kwargs)
# Exclude users who are already staff members
existing_staff_user_ids = StaffMember.objects.values_list('user', flat=True)
# Filter queryset for user field to include only superusers or users not already staff members
self.fields['user'].queryset = get_user_model().objects.filter(
is_superuser=True
).exclude(id__in=existing_staff_user_ids) | get_user_model().objects.exclude(
id__in=existing_staff_user_ids
)


class StaffDaysOffForm(forms.ModelForm):
class Meta:
model = DayOff
Expand Down
2 changes: 2 additions & 0 deletions appointment/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ def handle_service_management_request(post_data, files_data=None, service_id=Non

def create_new_appointment(data, request):
service = Service.objects.get(id=data.get("service_id"))
print(f"service id {data.get('service_id')}")
print(f"Service: {service}")
staff_id = data.get("staff_id")
if staff_id:
staff_member = StaffMember.objects.get(id=staff_id)
Expand Down
43 changes: 34 additions & 9 deletions appointment/static/css/app_admin/staff_member.css
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/* staff_form.css */
.staff-form-wrapper {
margin: 30px auto;
padding: 20px 0;
margin: 15px auto;
padding: 10px 0;
}

.staff-form-content {
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
max-width: 800px;
max-width: 1100px;
margin: 0 auto;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h2 {
h3 {
border-bottom: 1px solid #e0e0e0;
padding-bottom: 15px;
margin-bottom: 30px;
font-weight: 600;
margin-bottom: 20px;
font-weight: 500;
}

.form-group {
Expand All @@ -27,12 +27,12 @@ h2 {
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: 600;
font-weight: 500;
}

.form-control {
width: 100%;
padding: 10px;
padding: 2px 10px;
border: 1px solid #ccc;
border-radius: 5px;
transition: border 0.3s;
Expand All @@ -44,7 +44,7 @@ h2 {
}

.form-check {
margin-bottom: 20px;
margin-bottom: 10px;
}

.form-check label {
Expand All @@ -65,3 +65,28 @@ h2 {
.btn:hover {
background-color: #0056b3;
}

/* ############################### */
.user-not-found {
margin-top: 2px;
margin-bottom: 20px;
padding: 5px;
background-color: #f9f9f9;
border-radius: 4px;
font-size: 0.9rem;
}

.user-not-found a {
color: #007bff;
text-decoration: underline;
}

.user-not-found small {
color: #666;
}

small {
color: #3d3d3d;
font-size: 12px;
}

21 changes: 19 additions & 2 deletions appointment/templates/administration/manage_staff_member.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,51 @@
<section class="content content-wrapper">
<div class="staff-form-wrapper">
<div class="staff-form-content">
<h2>{% trans 'Staff Appointment Information' %}</h2>
<h3>{% trans 'Staff Appointment Information' %}</h3>
<form method="post">
{% csrf_token %}
{% if form.user %}
<div class="form-group">
{{ form.user.label_tag }}
{{ form.user.errors }}
{{ form.user }}
</div>
<div class="user-not-found">
<small>
{% translate 'User not found' %} ? <a href="{% url 'appointment:add_staff_member_personal_info' %}">{% translate 'Create staff member manually' %}</a>
</small>
</div>
{% endif %}

<div class="form-group">
{{ form.services_offered.label_tag }}
{{ form.services_offered.errors }}
{{ form.services_offered }}
<br><small>{% trans 'Hold down “Control”, or “Command” on a Mac, to select more than one.' %}</small>
</div>

<div class="form-group">
{{ form.slot_duration.label_tag }}
{{ form.slot_duration.label_tag }}
{{ form.slot_duration }}
<small>{{ form.slot_duration.help_text }}</small>
</div>

<div class="form-group">
{{ form.lead_time.label_tag }}
{{ form.lead_time }}
<small>{{ form.lead_time.help_text }}</small>
</div>

<div class="form-group">
{{ form.finish_time.label_tag }}
{{ form.finish_time }}
<small>{{ form.finish_time.help_text }}</small>
</div>

<div class="form-group">
{{ form.appointment_buffer_time.label_tag }}
{{ form.appointment_buffer_time }}
<small>{{ form.appointment_buffer_time.help_text }}</small>
</div>

<div class="form-check">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<section class="content content-wrapper">
<div class="staff-form-wrapper">
<div class="staff-form-content">
<h2>{% trans 'Staff Personal Information' %}</h2>
<h3>{% trans 'Staff Personal Information' %}</h3>
<form id="updatePersonalInfoForm" method="post" action="">
{% csrf_token %}

Expand Down
2 changes: 1 addition & 1 deletion appointment/templates/administration/staff_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2 class="section-header-itm">{% trans 'Staff Members' %}</h2>
class="modify-btn button-color-purple">
{{ btn_staff_me }}
</a>
<a href="{% url 'appointment:add_staff_member_personal_info' %}"
<a href="{% url 'appointment:add_staff_member_info' %}"
class="modify-btn button-color-green">
<i class="fas fa-add"></i>
</a>
Expand Down
24 changes: 24 additions & 0 deletions appointment/tests/base/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,27 @@ def create_appointment_reschedule_for_user1(self, appointment_request=None, reas
staff_member=appointment_request.staff_member,
reason_for_rescheduling=reason_for_rescheduling,
)

def need_normal_login(self):
self.client.force_login(self.create_user_())

def need_staff_login(self, user=None):
if user is not None:
user.is_staff = True
user.save()
self.client.force_login(user)
self.user1.is_staff = True
self.user1.save()
self.client.force_login(self.user1)

def need_superuser_login(self):
self.user1.is_superuser = True
self.user1.save()
self.client.force_login(self.user1)

def clean_staff_member_objects(self, user=None):
"""Delete all AppointmentRequests and Appointments linked to the StaffMember instance of self.user1."""
if user is None:
user = self.user1
self.clean_appointment_for_user(user)
self.clean_appt_request_for_user(user)
10 changes: 9 additions & 1 deletion appointment/tests/mixins/base_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,28 @@ def create_appointment_request_(cls, service, staff_member, date_=date.today(),
staff_member=staff_member
)

@classmethod
def clean_appt_request_for_user(cls, user):
AppointmentRequest.objects.filter(staff_member__user=user).delete()


class AppointmentMixin:
def __init__(self):
pass

@classmethod
def create_appointment_(cls, user, appointment_request, phone="1234567890", address="Some City, Some State"):
def create_appointment_(cls, user, appointment_request, phone="1234567890", address="Some City, Some State"):
return Appointment.objects.create(
client=user,
appointment_request=appointment_request,
phone=phone,
address=address
)

@classmethod
def clean_appointment_for_user(cls, user):
Appointment.objects.filter(client=user).delete()


class AppointmentRescheduleHistoryMixin:
def __init__(self):
Expand Down
Loading