-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
39 lines (33 loc) · 968 Bytes
/
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
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.core.mail import EmailMessage
def verify_email(email):
try:
validate_email(email)
return True
except ValidationError:
return False
def send_email(subject, message, to_email):
'''
# The subject is the subject of the email.
# The message is the body of the email.
# The to_email is the email address to send the email to.
'''
email = EmailMessage(
subject=subject,
body=message,
to=[to_email]
)
email.send()
def round_rating(avaliacao):
if avaliacao is None:
return None
valor = avaliacao * 2
if valor - int(valor) == 0.5:
valor += 0.1
valor_arredondado = round(valor)
if valor % 1 == 0.25:
valor_arredondado += 1
elif valor % 1 == 0.75:
valor_arredondado += 1
return valor_arredondado / 2