|
@@ -19,6 +19,7 @@ from django.contrib.sites.models import Site
|
|
|
# Stockage des fichiers privés (comme les factures par exemple)
|
|
|
private_files_storage = FileSystemStorage(location=settings.PRIVATE_FILES_ROOT)
|
|
|
|
|
|
+
|
|
|
def str_or_none(obj):
|
|
|
return str(obj) if obj else None
|
|
|
|
|
@@ -38,10 +39,10 @@ def send_templated_email(to, subject_template, body_template, context={}, attach
|
|
|
"""
|
|
|
Send a multialternative email based on html and optional txt template.
|
|
|
"""
|
|
|
-
|
|
|
+
|
|
|
# Ensure arrays when needed
|
|
|
if not isinstance(to, list):
|
|
|
- to = [to]
|
|
|
+ to = [to]
|
|
|
if not isinstance(attachements, list):
|
|
|
attachements = [attachements]
|
|
|
|
|
@@ -67,18 +68,19 @@ def send_templated_email(to, subject_template, body_template, context={}, attach
|
|
|
text_content = template_txt.render_to_string(Context(context))
|
|
|
except TemplateDoesNotExist:
|
|
|
text_content = html2text.html2text(html_content)
|
|
|
-
|
|
|
+
|
|
|
# make multipart email default : text, alternative : html
|
|
|
msg = EmailMultiAlternatives(subject=subject, body=text_content, to=to)
|
|
|
msg.attach_alternative(html_content, "text/html")
|
|
|
-
|
|
|
+
|
|
|
# Set attachements
|
|
|
for attachement in attachements:
|
|
|
msg.attach_file(attachement)
|
|
|
|
|
|
- #Send email
|
|
|
+ # Send email
|
|
|
msg.send()
|
|
|
|
|
|
+
|
|
|
def delete_selected(modeladmin, request, queryset):
|
|
|
"""Overrides QuerySet's delete() function to remove objects one by one
|
|
|
so, that they are deleted in the LDAP (Redmine issue #195)."""
|
|
@@ -88,12 +90,16 @@ def delete_selected(modeladmin, request, queryset):
|
|
|
delete_selected.short_description = "Supprimer tous les objets sélectionnés."
|
|
|
|
|
|
# Time-related functions
|
|
|
+
|
|
|
+
|
|
|
def in_one_year():
|
|
|
return date.today() + timedelta(365)
|
|
|
|
|
|
+
|
|
|
def start_of_month():
|
|
|
return date(date.today().year, date.today().month, 1)
|
|
|
|
|
|
+
|
|
|
def end_of_month():
|
|
|
return date(date.today().year, date.today().month + 1, 1) - timedelta(days=1)
|
|
|
|