Skip to content

Commit a7c8ce6

Browse files
authored
Last fixups (#65)
* updated documentation and models * Added tests for newly added line * Latest changes & release * Fixed test * Cleanup
1 parent 61d298f commit a7c8ce6

File tree

8 files changed

+22
-13
lines changed

8 files changed

+22
-13
lines changed

appointment/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
__package_name__ = "django-appointment"
66
__url__ = "https://github.com/adamspd/django-appointment"
77
__version__ = "3.0.0"
8-
__test_version__ = True
8+
__test_version__ = False

appointment/services.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
day_off_exists_for_date_range, exclude_booked_slots, get_all_appointments, get_all_staff_members,
2727
get_appointment_by_id, get_appointments_for_date_and_time, get_staff_member_appointment_list,
2828
get_staff_member_from_user_id_or_logged_in, get_times_from_config, get_user_by_email,
29-
get_working_hours_for_staff_and_day, working_hours_exist)
29+
get_working_hours_for_staff_and_day, parse_name, working_hours_exist)
3030
from appointment.utils.error_codes import ErrorCode
3131
from appointment.utils.json_context import convert_appointment_to_json, get_generic_context, json_response
3232
from appointment.utils.permissions import check_entity_ownership
@@ -310,8 +310,10 @@ def save_appointment(appt, client_name, client_email, start_time, phone_number,
310310
:return: The modified appointment.
311311
"""
312312
# Modify and save client details
313+
first_name, last_name = parse_name(client_name)
313314
client = appt.client
314-
client.name = client_name
315+
client.first_name = first_name
316+
client.last_name = last_name
315317
client.email = client_email
316318
client.save()
317319

@@ -593,7 +595,6 @@ def create_new_appointment(data, request):
593595
def update_existing_appointment(data, request):
594596
try:
595597
appt = Appointment.objects.get(id=data.get("appointment_id"))
596-
print(f"want_reminder: {data.get('want_reminder')}")
597598
want_reminder = data.get("want_reminder") == 'true'
598599
appt = save_appointment(
599600
appt,

appointment/static/js/app_admin/staff_index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ function displayEventList(events, date) {
184184
for (let item of eventItems) {
185185
item.addEventListener('click', function () {
186186
const eventId = this.getAttribute('data-event-id');
187+
AppState.eventIdSelected = eventId;
187188
showEventModal(eventId, false, false).then(r => r);
188189
});
189190
}
@@ -320,6 +321,16 @@ function confirmDeleteAppointment(appointmentId) {
320321
}
321322
showErrorModal(data.message, successTxt);
322323
closeConfirmModal(); // Close the confirmation modal
324+
325+
// Remove the deleted appointment from the global appointments array
326+
appointments = appointments.filter(appointment => appointment.id !== appointmentId);
327+
328+
// Refresh the event list for the current date
329+
const currentDate = AppState.calendar.getDate();
330+
const dateEvents = appointments
331+
.filter(event => moment(currentDate).isSame(event.start_time, 'day'))
332+
.sort((a, b) => new Date(a.start_time) - new Date(b.start_time));
333+
displayEventList(dateEvents, currentDate);
323334
})
324335
.catch(error => {
325336
console.error('Error:', error);
@@ -410,7 +421,6 @@ async function updateAppointmentDate(event, revertFunction) {
410421

411422
const responseData = await response.json();
412423
if (response.ok) {
413-
console.log("Updated message: " + responseData.message)
414424
showErrorModal(responseData.message, successTxt)
415425
} else {
416426
console.error('Failed to update appointment date. Server responded with:', response.statusText);
@@ -533,6 +543,7 @@ function adjustModalButtonsVisibility(isEditMode, isCreatingMode) {
533543
// ################################################################ //
534544

535545
function toggleEditMode() {
546+
console.log("I was called in toggleEditMode")
536547
const modal = document.getElementById("eventDetailsModal");
537548
const appointment = appointments.find(app => Number(app.id) === Number(AppState.eventIdSelected));
538549
AppState.isCreating = false; // Turn off creating mode
@@ -541,6 +552,8 @@ function toggleEditMode() {
541552
if (appointment) {
542553
AppState.isEditingAppointment = !AppState.isEditingAppointment; // Toggle the editing state
543554
updateModalUIForEditMode(modal, AppState.isEditingAppointment);
555+
} else {
556+
console.error("Appointment not found!");
544557
}
545558
}
546559

@@ -645,7 +658,6 @@ function validateEmail(email) {
645658
const emailError = document.getElementById("emailError");
646659

647660
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
648-
console.log("Email: ", emailInput.value)
649661
if (!emailRegex.test(emailInput.value)) {
650662
emailInput.style.border = "1px solid red";
651663
emailError.textContent = "Invalid email address, yeah.";
@@ -666,8 +678,6 @@ async function sendAppointmentData(data) {
666678
'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest', 'X-CSRFToken': getCSRFToken(),
667679
};
668680

669-
console.log("Sending data to server: ", data);
670-
671681
return fetch(updateApptMinInfoURL, {
672682
method: 'POST', headers: headers, body: JSON.stringify(data)
673683
});

appointment/templates/administration/manage_working_hours.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ <h2>{% trans "Manage Working Hours" %}</h2>
150150
type: 'POST',
151151
data: form.serialize(),
152152
success: function (response) {
153-
console.log("response", response.success);
154153
if (response.success) {
155154
window.location.href = response.redirect_url;
156155
} else {

appointment/templates/administration/staff_index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
const getNonWorkingDaysURL = "{% url 'appointment:get_non_working_days_ajax' %}";
308308
const serviceId = "{{ service.id }}";
309309
const serviceDuration = parseInt("{{ service.duration.total_seconds }}") / 60;
310-
const appointments = {{ appointments|safe }};
310+
let appointments = {{ appointments|safe }};
311311
const fetchServiceListForStaffURL = "{% url 'appointment:fetch_service_list_for_staff' %}";
312312
const updateApptMinInfoURL = "{% url 'appointment:update_appt_min_info' %}";
313313
const updateApptDateURL = "{% url 'appointment:update_appt_date_time' %}";

appointment/tests/test_services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def test_save_appointment(self):
349349
client_address, service_id)
350350

351351
# Check client details
352-
self.assertEqual(updated_appt.client.name, client_name)
352+
self.assertEqual(updated_appt.client.get_full_name(), client_name)
353353
self.assertEqual(updated_appt.client.email, client_email)
354354

355355
# Check appointment request details

appointment/views_admin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ def fetch_service_list_for_staff(request):
255255
def update_appt_min_info(request):
256256
data = json.loads(request.body)
257257
is_creating = data.get('isCreating', False)
258-
print("this is the data", data)
259258

260259
if is_creating:
261260
# Logic for creating a new appointment

docs/explanation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ In the admin interface, you have various options to manage appointments, such as
8383

8484
For a more comprehensive guide, including visual demonstrations of these steps, please watch the following video tutorial:
8585

86-
[Link to Video Tutorial]
86+
[Link to Short Video Demo](https://youtu.be/q1LSruYWKbk)

0 commit comments

Comments
 (0)