import logging
logger = logging.getLogger(__name__)

import random

from django.utils.hashcompat import sha_constructor
from django.contrib.sites.models import Site

from datetime import datetime

# Conditional import of 'now'
# Django 1.4 should use timezone.now, Django 1.3 datetime.now
try:
    from django.utils.timezone import now
except ImportError:
    logger.warn('Timezone support not enabled.')
    now = datetime.now


# Generic helper functions
def make_activation_code():
    """ Generate a unique activation code. """
    random_string = str(random.random())
    random_digest = sha_constructor(random_string).hexdigest()[:5]
    time_string = str(datetime.now().microsecond)

    combined_string = random_digest + time_string

    return sha_constructor(combined_string).hexdigest()


def get_default_sites():
    """ Get a list of id's for all sites; the default for newsletters. """
    return [site.id for site in Site.objects.all()]

@@ -61,16 +61,74 @@
 random%0A%0A
+try:%0A    from hashlib import sha1%0Aexcept ImportError:%0A    
 from dja
@@ -170,16 +170,29 @@
 structor
+ as sha1%0A    
 %0Afrom dj
@@ -660,28 +660,17 @@
 st = sha
-_constructor
+1
 (random_
@@ -809,28 +809,17 @@
 turn sha
-_constructor
+1
 (combine

Fix deprecation warnings with Django 1.5