import datetime
from django.core.mail import EmailMessage
from django.template import RequestContext
from django.template.loader import get_template

__author__ = 'tmehta'


def divide_timedelta(td, divisor):
    divided_seconds = td.total_seconds() / float(divisor)
    return datetime.timedelta(seconds=divided_seconds)


def welcome_new_user(backend, details, uid, request, user=None, is_new=False, *args, **kwargs):
    if is_new:
        request.user = user
        send_welcome_email(request)
    return None


def send_welcome_email(request):
    try:
        email_data = {
            'user': request.user,
        }
        email_data = RequestContext(request, email_data)
        msg = create_email('email/welcome_email.html', email_data, [request.user.email])
        msg.send()
    except Exception as e:
        print e


def create_email(template, data, to_list):
    t = get_template(template)
    content = t.render(data)
    msg = EmailMessage('Welcome to Wisely', content, 'contact@projectwisely.com', to_list)
    msg.content_subtype = "html"
    return msg
@@ -9,16 +9,45 @@
 atetime%0A
+from actstream import action%0A
 from dja
@@ -80,16 +80,16 @@
 Message%0A
-
 from dja
@@ -170,16 +170,53 @@
 template
+%0Afrom users.models import UserProfile
 %0A%0A__auth
@@ -534,34 +534,288 @@
     
-send_welcome_email(request
+try:%0A            user_profile = UserProfile.objects.get(user=request.user)%0A        except UserProfile.DoesNotExist:%0A            user_profile = UserProfile.objects.create(user=request.user)%0A        send_welcome_email(request)%0A        action.send(user_profile, verb='joined Wisely!'
 )%0A  

Add social user action