You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
767 B
28 lines
767 B
"""Utils for emencia.django.newsletter"""
|
|
from django.template import Context, Template
|
|
import random
|
|
from datetime import datetime
|
|
try:
|
|
from hashlib import sha1
|
|
except ImportError:
|
|
from django.utils.hashcompat import sha_constructor as sha1
|
|
|
|
|
|
|
|
|
|
def render_string(template_string, context={}):
|
|
"""Shortcut for render a template string with a context"""
|
|
t = Template(template_string)
|
|
c = Context(context)
|
|
return t.render(c)
|
|
|
|
|
|
def make_activation_code():
|
|
""" Generate a unique activation code. """
|
|
random_string = str(random.random())
|
|
random_digest = sha1(random_string).hexdigest()[:5]
|
|
time_string = str(datetime.now().microsecond)
|
|
|
|
combined_string = random_digest + time_string
|
|
|
|
return sha1(combined_string).hexdigest() |