mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
* use new peeringdb client (1.0.0) for pdb_load_data sync (#599) * drop django-mobi for lack of py3/dj2 support (#492) remove django-forms-bootstrap for lack of py3/dj2 support (#492) * black formatted * django2.2 and py3 upgrade (#492) * drop ixlans (#21) ui and api changes * drop local_asn (#168) * org search (#193) * phone number validation (#50) * implement help text tooltips (#228) * Mark own ASN as transit-free (#394) * py3 fix for `pdb_migrate_ixlans` command when writing migration report * pdb_migrate_ixlans: properly handle py3 Runtime error if ixlan dict changes during iteration * set rest DEFAULT_SCHEMA_CLASS to coreapi to fix swagger apidocs fix migration 0027 missing from facsimile manifest * fix swagger doc strings * fix tests that were broken from api doc fixes * fix UniqueFieldValidator for netixlan ipaddress validation that broke during django/drf upgrade * fix org merge tool layout issues * travis config * update pipfile and lock * black formatting * update travis dist * beta mode banner (#411) * add beta banner template (#411) * automatically scheduled sync may not always be on, add a flag that lets us reflect that state in the beta banner message clean up beta banner implementation (#411) * add tests for beta banner (#411)
97 lines
3.1 KiB
Python
97 lines
3.1 KiB
Python
from django.core.mail.message import EmailMultiAlternatives
|
|
from django.conf import settings
|
|
from django.template import loader
|
|
from django.utils.html import strip_tags
|
|
from django.utils.translation import ugettext_lazy as _, override
|
|
|
|
|
|
def mail_admins_with_from(
|
|
subj, msg, from_addr, fail_silently=False, connection=None, html_message=None
|
|
):
|
|
"""
|
|
mail admins but allow specifying of from address
|
|
"""
|
|
|
|
if not settings.ADMINS:
|
|
return
|
|
|
|
# set plain text message
|
|
msg_raw = strip_tags(msg)
|
|
mail = EmailMultiAlternatives(
|
|
"%s%s" % (settings.EMAIL_SUBJECT_PREFIX, subj),
|
|
msg,
|
|
from_addr,
|
|
[a[1] for a in settings.ADMINS],
|
|
connection=connection,
|
|
)
|
|
|
|
# attach html message
|
|
mail.attach_alternative(msg.replace("\n", "<br />\n"), "text/html")
|
|
|
|
mail.send(fail_silently=fail_silently)
|
|
|
|
|
|
def mail_users_entity_merge(users_source, users_target, entity_source, entity_target):
|
|
"""
|
|
notifies the users specified in users_source that their entity (entity_source) has
|
|
been merged with another entity (entity_target)
|
|
|
|
notifies the users specified in users_target that an entity has ben merged into their
|
|
entity (entity_target)
|
|
|
|
Arguments:
|
|
- users_source <list>: list of User objects
|
|
- users_target <list>: list of User objects
|
|
- entity_source <HandleRef>: handleref object, entity that was merged
|
|
- entity_target <HandleRef>: handleref object, entity that was merged into
|
|
"""
|
|
msg = loader.get_template("email/notify-org-admin-merge.txt").render(
|
|
{
|
|
"entity_type_name": entity_source._meta.verbose_name.capitalize(),
|
|
"entity_source": entity_source,
|
|
"entity_target": entity_target,
|
|
"entity_target_url": "{}/{}/{}".format(
|
|
settings.BASE_URL, entity_target.ref_tag, entity_target.id
|
|
),
|
|
"support_email": settings.DEFAULT_FROM_EMAIL,
|
|
}
|
|
)
|
|
|
|
for user in set([u for u in users_source] + [u for u in users_target]):
|
|
# FIXME: why not have the `override` call in email_user in the first place?
|
|
with override(user.locale):
|
|
user.email_user(
|
|
_("{} Merge Notification: {} -> {}").format(
|
|
entity_source._meta.verbose_name.capitalize(),
|
|
entity_source.name,
|
|
entity_target.name,
|
|
),
|
|
msg,
|
|
)
|
|
|
|
|
|
def mail_username_retrieve(email, secret):
|
|
"""
|
|
Sends an email to the specified email address containing
|
|
the url for username retrieval.
|
|
|
|
Arguments:
|
|
- email <str>
|
|
- secret <str>: username retrieval secret in the user's session
|
|
"""
|
|
|
|
msg = loader.get_template("email/username-retrieve.txt").render(
|
|
{
|
|
"email": email,
|
|
"secret": secret,
|
|
"username_retrieve_url": "{}/username-retrieve/complete?secret={}".format(
|
|
settings.BASE_URL, secret
|
|
),
|
|
}
|
|
)
|
|
|
|
subject = "PeeringDB username retrieval"
|
|
|
|
mail = EmailMultiAlternatives(subject, msg, settings.DEFAULT_FROM_EMAIL, [email])
|
|
mail.send(fail_silently=False)
|