-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
42 lines (34 loc) · 1.42 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#Import Modules
from random import Random
def generate_password(password_length=8, alternate_hands=True):
"""
A simple script for making random passwords, WITHOUT 1,l,O,0. Because
those characters are hard to tell the difference between in some fonts.
"""
rng = Random()
righthand = '23456qwertasdfgzxcvbQWERTASDFGZXCVB'
lefthand = '789yuiophjknmYUIPHJKLNM'
allchars = righthand + lefthand
for i in range(password_length):
if not alternate_hands:
return rng.choice(allchars)
else:
if i%2:
return rng.choice(lefthand)
else:
return rng.choice(righthand)
def html_email(subject, template, template_vars_dict, from_email, to):
"""
Function to send email with html template
"""
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.utils.html import strip_tags
html_content = render_to_string(template, template_vars_dict)
text_content = strip_tags(html_content) # this strips the html, so people will have the text as well.
# create the email, and attach the HTML version as well.
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
def format_cnpf(cnpf):
return cnpf.replace('.', '').replace('-', '').replace('/', '')