Skip to content

Commit b007d68

Browse files
committed
version 1.0.3-snapshot
1 parent 66082bf commit b007d68

File tree

3 files changed

+62
-19
lines changed

3 files changed

+62
-19
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ Appointment Scheduler is a Django app designed for managing appointment scheduli
44
users to define custom configurations for time slots, lead time, and finish time, or use the default values provided.
55
The app also handles conflicts and availability for appointments, ensuring a smooth user experience.
66

7-
Detailed documentation is in the ["docs"](docs/README.md) directory.
7+
Detailed documentation is in the ["docs"](https://github.com/adamspd/django-appointment/tree/main/docs) directory.
88

99
## Features
1010

1111
1. Customizable time slots, lead time, and finish time.
1212
2. Handles appointment conflicts and availability.
1313
3. Easy integration with Django admin interface for appointment management.
1414
4. User-friendly interface for viewing available time slots and scheduling appointments.
15+
5. Sends email notifications to clients when they schedule an appointment.
1516

1617
## Quick start
1718

@@ -72,6 +73,11 @@ Detailed documentation is in the ["docs"](docs/README.md) directory.
7273
And the current year is 2023, the password will be "Chocolates2023". If you don't provide an
7374
APPOINTMENT_WEBSITE_NAME, the default value is "Website", so the password will be "Website2023".
7475

76+
This name is also used in the footer of the emails sent to the clients when they schedule an appointment.
77+
```html
78+
<p>® 2023 {{ APPOINTMENT_WEBSITE_NAME }}. All Right Reserved.</p>
79+
```
80+
7581
4. Run `python manage.py migrate` to create the appointment models.
7682

7783

@@ -99,8 +105,11 @@ Detailed documentation is in the ["docs"](docs/README.md) directory.
99105
# Additional configuration options
100106
APPOINTMENT_BASE_TEMPLATE = 'base_templates/base.html' # your base template
101107
APPOINTMENT_WEBSITE_NAME = 'Website'
102-
APPOINTMENT_PAYMENT_URL = None # example of pattern 'payment:payment_linked
103-
APPOINTMENT_THANK_YOU_URL = None # example of pattern 'payment:thank_you'
108+
APPOINTMENT_PAYMENT_URL = None # example of pattern 'payment:payment_linked
109+
APPOINTMENT_THANK_YOU_URL = None # example of pattern 'payment:thank_you'
110+
111+
# Additional to the default email settings
112+
APP_DEFAULT_FROM_EMAIL = "webmaster@localhost" # the default from email that you're using
104113
```
105114

106115
2. Modify these values as needed for your application, and the scheduler will adapt to the new settings.
Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
from django.core.mail import mail_admins, send_mail
22
from django.template import loader
3+
from django.conf import settings
34

5+
from appointment.settings import APP_DEFAULT_FROM_EMAIL
6+
7+
8+
def has_required_email_settings():
9+
required_settings = [
10+
'EMAIL_BACKEND',
11+
'EMAIL_HOST',
12+
'EMAIL_PORT',
13+
'EMAIL_HOST_USER',
14+
'EMAIL_HOST_PASSWORD',
15+
'EMAIL_USE_TLS',
16+
'EMAIL_USE_LOCALTIME',
17+
'ADMINS',
18+
]
19+
20+
for setting_name in required_settings:
21+
if not hasattr(settings, setting_name):
22+
print(f"Warning: '{setting_name}' not found in settings. Email functionality will be disabled.")
23+
return False
24+
25+
return True
426

527
def send_email(recipient_list, subject: str, template_url: str = None, context: dict = None, from_email=None,
628
message: str = None):
29+
if not has_required_email_settings():
30+
return
31+
732
if from_email is None:
8-
from_email = '[email protected]'
33+
from_email = APP_DEFAULT_FROM_EMAIL
934

1035
html_message = ""
1136

@@ -15,25 +40,33 @@ def send_email(recipient_list, subject: str, template_url: str = None, context:
1540
context=context
1641
)
1742

18-
send_mail(
19-
subject=subject,
20-
message=message if not template_url else "",
21-
html_message=html_message if template_url else None,
22-
from_email=from_email,
23-
recipient_list=recipient_list,
24-
fail_silently=False,
25-
)
26-
43+
try:
44+
send_mail(
45+
subject=subject,
46+
message=message if not template_url else "",
47+
html_message=html_message if template_url else None,
48+
from_email=from_email,
49+
recipient_list=recipient_list,
50+
fail_silently=False,
51+
)
52+
except Exception as e:
53+
print(f"Error sending email: {e}")
2754

2855
def notify_admin(subject: str, template_url: str = None, context: dict = None, message: str = None):
56+
if not has_required_email_settings():
57+
return
58+
2959
html_message = ""
3060
if template_url:
3161
html_message = loader.render_to_string(
3262
template_name=template_url,
3363
context=context
3464
)
35-
mail_admins(
36-
subject=subject,
37-
message=message if not template_url else "",
38-
html_message=html_message if template_url else None
39-
)
65+
try:
66+
mail_admins(
67+
subject=subject,
68+
message=message if not template_url else "",
69+
html_message=html_message if template_url else None
70+
)
71+
except Exception as e:
72+
print(f"Error sending email to admin: {e}")

appointment/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.conf import settings
2+
from django.conf.global_settings import DEFAULT_FROM_EMAIL
23

34
APPOINTMENT_CLIENT_MODEL = getattr(settings, 'APPOINTMENT_CLIENT_MODEL', 'auth.User')
45
APPOINTMENT_BASE_TEMPLATE = getattr(settings, 'APPOINTMENT_BASE_TEMPLATE', 'base_templates/base.html')
@@ -8,4 +9,4 @@
89
APPOINTMENT_SLOT_DURATION = getattr(settings, 'APPOINTMENT_SLOT_DURATION', 30)
910
APPOINTMENT_LEAD_TIME = getattr(settings, 'APPOINTMENT_LEAD_TIME', (9, 0))
1011
APPOINTMENT_FINISH_TIME = getattr(settings, 'APPOINTMENT_FINISH_TIME', (16, 30))
11-
12+
APP_DEFAULT_FROM_EMAIL = getattr(settings, 'DEFAULT_FROM_EMAIL', DEFAULT_FROM_EMAIL)

0 commit comments

Comments
 (0)