Skip to content

Commit e05a42a

Browse files
authored
Merge pull request #193 from adamspd/192-use-username-when-name-not-provided-in-admin-pages
Minor changes on username, appt creation, and email templating
2 parents 209ebcd + f24aa58 commit e05a42a

File tree

14 files changed

+45
-27
lines changed

14 files changed

+45
-27
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: adamspd

.github/workflows/tests.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ jobs:
3232
python -m pip install --upgrade pip
3333
pip install -r requirements.txt
3434
pip install coverage
35+
- name: Debug Coverage Configuration
36+
run: |
37+
coverage debug sys
38+
coverage debug config
39+
- name: Install Dependencies
40+
run: |
41+
python -m pip install --upgrade pip
42+
pip install -r requirements.txt
3543
- name: Run Tests
3644
run: |
37-
coverage run --source=appointment manage.py test appointment.tests --parallel=10 --shuffle --verbosity=1
38-
coverage report
39-
coverage xml
40-
- name: Upload to Codecov
41-
uses: codecov/codecov-action@v4
42-
with:
43-
token: ${{ secrets.CODECOV_TOKEN }}
44-
file: ./coverage.xml # specify the location of the coverage report
45-
flags: unittests # optional
46-
name: codecov-umbrella # optional
45+
python manage.py test appointment.tests --parallel=10 --shuffle --verbosity=1

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
[![Current Release Version](https://img.shields.io/github/release/adamspd/django-appointment.svg?style=flat-square&logo=github)](https://github.com/adamspd/django-appointment/releases)
77
[![pypi Version](https://img.shields.io/pypi/v/django-appointment.svg?style=flat-square&logo=pypi&logoColor=white)](https://pypi.org/project/django-appointment/)
88
[![PyPi downloads](https://static.pepy.tech/personalized-badge/django-appointment?period=total&units=international_system&left_color=grey&right_color=orange&left_text=pip%20downloads)](https://pypi.org/project/django-appointment/)
9-
[![codecov](https://codecov.io/gh/adamspd/django-appointment/branch/main/graph/badge.svg?token=ZQZQZQZQZQ)](https://codecov.io/gh/adamspd/django-appointment)
109
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
1110
[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/adamspd/django-appointment)](https://github.com/adamspd/django-appointment/commits/main)
1211
[![GitHub last commit](https://img.shields.io/github/last-commit/adamspd/django-appointment)](https://github.com/adamspd/django-appointment/commit/main)

appointment/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ def get_staff_member_name(self):
214214
if hasattr(self.user, 'get_full_name') and callable(getattr(self.user, 'get_full_name')):
215215
name = self.user.get_full_name()
216216
else:
217-
name = self.user.first_name
217+
name = f"{self.user.first_name} {self.user.last_name}".strip()
218+
if not name:
219+
name = self.user.username
218220
return name
219221

220222
def get_staff_member_first_name(self):

appointment/static/js/app_admin/staff_index.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ async function showCreateAppointmentModal(defaultStartTime, formattedDate) {
579579
let staffDropdown = null;
580580
if (isUserSuperUser) {
581581
staffDropdown = await populateStaffMembers(null, false);
582+
staffDropdown.id = "staffSelect";
583+
staffDropdown.disabled = false; // Enable dropdown
584+
attachEventListenersToDropdown(); // Attach event listener
582585
}
583586
servicesDropdown.id = "serviceSelect";
584587
servicesDropdown.disabled = false; // Enable dropdown
@@ -653,6 +656,7 @@ async function showEventModal(eventId = null, isEditMode, isCreatingMode = false
653656
let staffDropdown = null;
654657
if (isUserSuperUser) {
655658
staffDropdown = await getStaffDropdown(appointment.staff_id, isEditMode);
659+
attachEventListenersToDropdown(); // Attach event listener
656660
}
657661

658662
document.getElementById('eventModalBody').innerHTML = generateModalContent(appointment, servicesDropdown, isEditMode, staffDropdown);
@@ -758,14 +762,26 @@ async function submitChanges() {
758762
function collectFormDataFromModal(modal) {
759763
const inputs = modal.querySelectorAll("input");
760764
const serviceId = modal.querySelector("#serviceSelect").value;
761-
const staffId = modal.querySelector("#staffSelect").value;
765+
let staffId = null;
766+
767+
if (isUserSuperUser) {
768+
// If the user is a superuser, get the staff ID from the dropdown
769+
const staffDropdown = modal.querySelector("#staffSelect");
770+
if (staffDropdown) {
771+
staffId = staffDropdown.value;
772+
}
773+
}
774+
762775
const data = {
763776
isCreating: AppState.isCreating,
764777
service_id: serviceId,
765-
staff_id: staffId,
766778
appointment_id: AppState.eventIdSelected
767779
};
768780

781+
if (staffId) {
782+
data.staff_id = staffId;
783+
}
784+
769785
inputs.forEach(input => {
770786
if (input.name !== "date") {
771787
let key = input.name.replace(/([A-Z])/g, '_$1').toLowerCase();

appointment/static/js/appointments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function fetchNonWorkingDays(staffId, callback) {
158158
return; // Exit the function early
159159
}
160160
let ajaxData = {
161-
'staff_member': staffId,
161+
'staff_id': staffId,
162162
};
163163

164164
$.ajax({

appointment/templates/administration/staff_index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@
344344
function createCommonInputFields(appointment, servicesDropdown, isEditMode, defaultStartTime, staffDropdown) {
345345
const startTimeValue = isEditMode ? moment(appointment.start_time).format('HH:mm:ss') : defaultStartTime;
346346
const disabledAttribute = isEditMode ? '' : 'disabled';
347-
347+
348348
let superuserInputField = '';
349349
if (isUserSuperUser) {
350350
superuserInputField = `

appointment/templates/administration/staff_list.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ <h2 class="section-header-itm">{% trans 'Staff Members' %}</h2>
4343
<tbody>
4444
{% for staff_member in staff_members %}
4545
<tr>
46-
<td>{{ staff_member.user.first_name }} {{ staff_member.user.last_name }}</td>
47-
<td>{{ staff_member.user.email }}</td>
46+
<td>{{ staff_member.get_staff_member_name }}</td>
47+
<td>{{ staff_member.user.email|default:"N/A" }}</td>
4848
<td>
4949
<a href="{% url 'appointment:user_profile' staff_member.user.id %}"
5050
class="modify-btn button-color-blue">{% trans 'View Profile' %}</a>

appointment/templates/administration/user_profile.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
<h2>{% trans 'Personal Information' %}</h2>
3636
<!-- Display fields from PersonalInformationForm -->
3737
<div class="section-content">
38-
<p><strong>{% trans 'First name' %}:</strong> {{ user.first_name }}</p>
39-
<p><strong>{% trans 'Last name' %}:</strong> {{ user.last_name }}</p>
40-
<p><strong>{% trans 'Email' %}:</strong> {{ user.email }}</p>
38+
<p><strong>{% trans 'First name' %}:</strong> {{ user.first_name|default:user.username }}</p>
39+
<p><strong>{% trans 'Last name' %}:</strong> {{ user.last_name|default:"N/A" }}</p>
40+
<p><strong>{% trans 'Email' %}:</strong> {{ user.email|default:"N/A" }}</p>
4141
</div>
4242
<a href="{% url 'appointment:update_user_info' user.id %}"
4343
class="section-content-button modify-btn button-color-blue">
@@ -242,7 +242,7 @@ <h2>{% trans 'Service Offered' %}</h2>
242242
{% for service in services_offered %}
243243
<tr>
244244
<td>{{ service.name }}</td>
245-
<td>{{ service.description }}</td>
245+
<td>{{ service.description|default:"N/A" }}</td>
246246
<td>{{ service.get_duration }}</td>
247247
<td>{{ service.get_price_text }}</td>
248248
<td>{{ service.get_down_payment_text }}</td>

appointment/templates/email_sender/admin_new_appointment_email.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ <h1>{% translate 'New Appointment Request' %}</h1>
6060
<p><strong>{% translate 'Appointment Date' %}:</strong> {{ appointment.appointment_request.date }}</p>
6161
<p><strong>{% translate 'Time' %}:</strong> {{ appointment.appointment_request.start_time }}
6262
- {{ appointment.appointment_request.end_time }}</p>
63-
<p><strong>{% translate 'Contact Details' %}:</strong> {{ appointment.phone }} | {{ client_email }}</p>
63+
<p><strong>{% translate 'Contact Details' %}:</strong> {{ appointment.phone }} | {{ appointment.client.email }}</p>
6464
<p><strong>{% translate 'Additional Info' %}:</strong> {{ appointment.additional_info|default:"N/A" }}</p>
6565
</div>
6666

0 commit comments

Comments
 (0)