示例#1
0
def handle(request): 
    try:
        logged_in_type = siteaction.getLoggedInAccountType(request)
        rcvr_usrname = dataplus.dictGetVal(request.REQUEST,'sendTo')
        
        if logged_in_type == 'U':
            myself = siteaction.getLoggedInUser(request)
        elif logged_in_type == 'R':
            myself = siteaction.getLoggedInRecruiter(request)
        else:
            return ajaxian.getFailureResp('not_logged_in')
        
        rcvr_account = models.Account.objects.get(username=dataplus.dictGetVal(request.REQUEST,'sendTo'))
        text_message = dataplus.dictGetSafeVal(request.REQUEST,'text')
        html_message = dataplus.replaceHtmlLineBreaks(text_message)
        subject = dataplus.dictGetSafeVal(request.REQUEST,'subject')
        
        def internalSender(rcvr_accounts):
            mailman.sendMessage(myself.username, [rcvr.username for rcvr in rcvr_accounts], subject, html_message)
        
        def externalSender(rcvr_accounts):
            sender = '"' + myself.name + '" <' + myself.username + '*****@*****.**>'
            receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>'  for rcvr in rcvr_accounts]
            mailman.sendMail(sender, receivers, subject, html_message, None, None, text_message, reply_to=myself.email)
            
        mailman.sendBySettings([rcvr_account], internalSender, externalSender, 'TextMessage')
                
        return ajaxian.getSuccessResp('')
    except:
        return ajaxian.getFailureResp('unknown')
def sendCommunityInvitationToUser(community, user, sender, message, add_as_friend=False):
    comm_invite = models.CommunityInvitation(sent_by=sender, community=community)
    comm_invite.invite_random_key = dataplus.getUniqueId()
    comm_invite.save()

    sender_email = '"' + sender.name + '" <' + sender.username + "*****@*****.**>"
    subject = sender.name + " has invited you to join " + community.name
    accept_url = (
        config.server_base_url
        + "/me/acceptinvite.htm?commInviteId="
        + str(comm_invite.invite_random_key)
        + "&amp;user="******"'
        + config.server_base_url
        + "/profiles/"
        + sender.username
        + '">'
        + sender.name
        + "</a>"
        + " feels that you will be interested in joining the "
        + community.name
        + " Community and has sent you the following message:</p>"
        + "<p>"
        + dataplus.replaceHtmlLineBreaks(message)
        + "</p>"
        + '<p>To accept this invitation, visit <a href="'
        + accept_url
        + '">'
        + accept_url
        + "</a> "
        + "<p>Regards,<br />from Socialray</p>"
    )

    text_message = (
        sender.name
        + " feels that you will be interested in joining the "
        + community.name
        + " Community and has sent you the following message:\r\n"
        + message
        + "\r\n\r\n"
        + "To accept this invitation, visit - "
        + accept_url
        + " \r\n"
        + "Regards,\r\n"
        + "from Socialray\r\n\r\n"
    )

    def internalSender(rcvr_accounts):
        mailman.sendToInbox(sender.username, user.username, subject, html_message)

    def externalSender(rcvr_accounts):
        mailman.sendMail(
            sender_email, [user.email], subject, html_message, None, None, text_message, reply_to=user.email
        )

    mailman.sendBySettings([user.account], internalSender, externalSender, "CommunityInvitation")
def handle(request):
    q_id = dataplus.dictGetVal(request.REQUEST, 'qid', '0', string.atoi)
    if q_id == 0:
        return HttpResponseRedirect('/login.htm')
    question = get_object_or_404(models.ResumeQuestion, id=q_id)
    
    myself = siteaction.getLoggedInUser(request)
    if not myself or myself.id != question.receiver.id:
        return HttpResponseRedirect('/login.htm?' + urllib.urlencode(
                {'returnUrl':'/me/answerresumequestion.htm?qid=' + str(q_id)}))
    
        
    if question.receiver.id != myself.id:
        return siteaction.render_to_response('me/showmessage.htm', 
            {'myself':myself, 
            'msg_heading': 'Error',
            'msg_html': 'Access Denied.'})
    
    if request.method == 'GET':
        return siteaction.render_to_response('me/answerresumequestion.htm',
            {'myself':myself,
            'question':question,
            'is_public_checked':dataplus.conditionalValue(lambda: question.is_public == True, 'checked="checked"', '')})
            
    elif request.method == 'POST':
        question.answer = dataplus.dictGetSafeVal(request.REQUEST, 'answer')
        question.is_public = dataplus.dictGetVal(request.REQUEST, 'is_public')
        question.is_answered = True
        question.save()

        html_message = myself.name + ' has answered your question (' + question.question + ').<br />' + \
            '<strong>Answer: </strong> ' + question.answer
            
        text_message = myself.name + ' has answered your question (' + question.question + ').\r\n' + \
            'Answer: ' + question.answer
        
        subject = myself.name + ' has answered your question'
        def internalSender(rcvr_accounts):
            rcvr = rcvr_accounts[0]
            mailman.sendToInbox(myself.username, rcvr.username, subject, html_message, 'TM', 'H')
        
        def externalSender(rcvr_accounts):
            sender = '"' + myself.name + '" <' + myself.username + '*****@*****.**>'
            receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>'  for rcvr in rcvr_accounts]
            mailman.sendMail(sender, receivers, subject, html_message, 
                None, None, text_message, reply_to=myself.email)
        
        mailman.sendBySettings([question.sender], internalSender, externalSender, 'AnswerToResumeQuestion')
        
        return HttpResponseRedirect('/me/?flashId=rqa_saved')
def handle(request):
    req_id = dataplus.dictGetVal(request.REQUEST, 'reqId', '0', string.atoi)
    myself = siteaction.getLoggedInUser(request)
    if not myself:
        return HttpResponseRedirect('/login.htm?' + urllib.urlencode(
                {'returnUrl':'/me/approvecommjoinreq.htm?reqId=' + str(req_id)}))
        
    join_req = dataplus.returnIfExists(models.CommunityJoinRequest.objects.filter(id=req_id))
    if not join_req:
        return siteaction.render_to_response('me/showmessage.htm',
            { 'myself':myself, 'msg_heading':'Request not found',
                'msg_html':'The community join request does not exist. It must have already been processed.'})
            
    if join_req.community.owner_username != myself.username:
        return siteaction.render_to_response('me/showmessage.htm',
            { 'myself':myself, 'msg_heading':'Error', 'msg_html':'Access denied.' })
    
    if request.method == 'GET':
        return siteaction.render_to_response('me/approvecommjoinreq.htm',
            {'myself':myself,
            'join_req':join_req})
            
    elif request.method == 'POST':
        allowed = False
        if dataplus.dictGetVal(request.REQUEST,'result') == 'allow':
            join_req.sent_by.communities.add(join_req.community)
            allowed = True
            flashId = 'comm_join_allowed'
        else:
            flashId = 'comm_join_denied'
            join_req.delete()
                
        approved_text = ('denied','approved')[allowed]
        subject = 'Re: Request to join ' + join_req.community.name
        html_message = '<p>Your request to join \'' + join_req.community.name + '\' was ' + \
                        approved_text + ' by the administrator.<p><p>Regards,<br />from Socialray</p>'
        text_message = 'Your request to join \'' + join_req.community.name + '\' was ' + \
                        approved_text + ' by the administrator.\r\n\r\nRegards,\r\n from Socialray\r\n\r\n'
        def internalSender(rcvr_accounts):
            mailman.sendToInbox(myself.username, rcvr_accounts[0].username, subject, html_message)
        
        def externalSender(rcvr_accounts):
            sender = '"' + myself.name + '" <' + myself.username + '*****@*****.**>'
            receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>'  for rcvr in rcvr_accounts]
            mailman.sendOneWayMail(sender, receivers, subject, html_message, None, None, text_message)
                
        mailman.sendBySettings([join_req.sent_by.account], internalSender, externalSender, 'SocialrayAlert')
    
        return HttpResponseRedirect('/me?flashId=' + flashId)
示例#5
0
def send(html_filename, txt_filename, subject, to_list, parameters, mail_type='SocialrayAlert'):
    template_html = open(html_filename, 'r').read()
    template_text = open(txt_filename, 'r').read()
    def internalSender(rcvr_accts):
        pass
    
    for rcvr in to_list:
        def externalSender(rcvrs):
            sender = "Socialray Team <*****@*****.**>"
            rcvr = rcvrs[0]
            receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>']
            ext_html_message = replaceParams(template_html, parameters, rcvr)
            ext_text_message = replaceParams(template_text, parameters, rcvr)
            mailman.sendOneWayMail(sender, receivers, subject, ext_html_message, None, None, ext_text_message)
        
        mailman.sendBySettings([rcvr], internalSender, externalSender, mail_type)
示例#6
0
def sendRequestToAdmin(community, user, invited_by):
    message_to_admin = '<p><a href="' + config.server_base_url + '/profiles/' + user.username +'/">' + user.name + '</a>' + \
        ' has been invited to join ' + community.name + ' by one of the members, ' + '<p><a href="' + config.server_base_url + \
        '/profiles/' + invited_by.username +'/">' + invited_by.name + '</a>.</p>'
    
    join_req = models.CommunityJoinRequest()
    join_req.sent_by = user
    join_req.community = community
    join_req.sent_on = datetime.datetime.utcnow()
    join_req.msg_to_admin = message_to_admin
    join_req.save()
    
    msg_to_admin_html = message_to_admin + \
        '<p>To allow/deny membership to this user , <a href="/me/approvecommjoinreq.htm?reqId=' + \
        str(join_req.id) + '">click here</a></p>' 
    msg_to_admin_text = user.name + ' has been invited to join ' + community.name + ' by one of the members, ' + invited_by.username + '.\r\n' + \
        'You can view the profile of ' + user.name + ' at ' + config.server_base_url + '/profiles/' + user.username + '.' + \
        'Visit ' + config.server_base_url + '/me/approvecommjoinreq.htm?reqId=' + str(join_req.id) + \
        ' to allow/deny membership to this user.'
    
    def internalSender(rcvr_accounts):
        mailman.sendToInbox(None, rcvr_accounts[0].username, 'Request to join ' + community.name, msg_to_admin_html, 'SA', 'H')
    
    def externalSender(rcvr_accounts):    
        sender = '"' + user.name + '" <' + user.username + '*****@*****.**>'
        receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>'  for rcvr in rcvr_accounts]
        ext_msg_to_admin_html = msg_to_admin_html + \
            '<br /><br /><br /><br /><br />' + \
            'If you don\'t want to receive notification emails, change your Account Settings ' + \
            '<a href="' + config.server_base_url + '/me/editsettings.htm">here</a>'                
        ext_msg_to_admin_text = msg_to_admin_text + \
            '\r\n\r\n\r\n\r\n\r\n' + \
            'If you don\'t want to receive notification emails, change your Account Settings here\r\n' + \
            config.server_base_url + '/me/editsettings.htm'
        mailman.sendMail(sender, receivers, 'Request to join ' + community.name, ext_msg_to_admin_html, 
            None, None, ext_msg_to_admin_text)

    admin_account = models.Account.objects.get(username=community.owner_username)
    mailman.sendBySettings([admin_account], internalSender, externalSender, 'SocialrayAlert')
示例#7
0
def sendApprovalPendingMessageToUser(community, user):
    subject = 'Your membership to ' + community.name
    html_message = '<p>' + community.name + ' is a moderated community. Your membership to the community ' + \
        ' is subject to the approval of the administrator. You will informed once the administrator ' + \
        ' takes a decision on your membership.</p>' + \
        '<p>Regards,<br />from Socialray</p>'
        
    text_message = community.name + ' is a moderated community. Your membership to the community ' + \
        ' is subject to the approval of the administrator. You will informed once the administrator ' + \
        ' takes a decision on your membership.\r\n' + \
        'Regards,\r\n' + \
        'from Socialray\r\n\r\n'
        
    def internalSender(rcvr_accounts):
        for rcvr_account in rcvr_accounts:
            mailman.sendToInbox(None, rcvr_account.username, subject, html_message, 'SA')
    
    def externalSender(rcvr_accounts):
        mailman.sendOneWayMail(config.system_email, [rcvr_accounts[0].email], subject, html_message, None, None, text_message)
    
    mailman.sendBySettings([user.account], internalSender, externalSender, 'CommunityInvitation')
    
    return True, HttpResponseRedirect('/me/?flashId=comm_invite_approval_pending')
示例#8
0
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')
        
        comm_id = dataplus.dictGetVal(request.REQUEST, 'communityId')
        community = models.Community.objects.get(id=comm_id)
        
        if community.members.filter(id=myself.id):
            return ajaxian.getFailureResp('already_member')

        elif not community.is_moderated:            
            myself.communities.add(community)
            myself.save()
            return ajaxian.getSuccessResp('joined_community')
                
        else:
            join_reqs = community.join_requests.filter(sent_by__id=myself.id)
            if join_reqs.count() > 0:
                return ajaxian.getFailureResp('request_pending')            
            
            if dataplus.dictGetVal(request.REQUEST, 'message', '') == '':
                return ajaxian.getFailureResp('community_moderated')
            
            message_to_admin = dataplus.dictGetSafeVal(request.REQUEST, 'message','')
            
            join_req = models.CommunityJoinRequest()
            join_req.sent_by = myself
            join_req.community = community
            join_req.sent_on = datetime.datetime.utcnow()
            join_req.msg_to_admin = message_to_admin
            join_req.save()
            
            msg_to_admin_html = '<p><a href="' + config.server_base_url + '/profiles/' + myself.username + '">' + myself.name + '</a>' + \
                ' wants to join ' + community.name + ' and has sent you a message:<br />' + \
                dataplus.replaceHtmlLineBreaks(message_to_admin) + '</p>' + \
                '<p>To allow/deny membership to this user , <a href="/me/approvecommjoinreq.htm?reqId=' + \
                str(join_req.id) + '">Click Here</a></p>' 
            
            msg_to_admin_text = myself.name + ' wants to join ' + community.name + ' and has sent you a message:\r\n' + \
                message_to_admin + '\r\n\r\nVisit ' + config.server_base_url + '/me/approvecommjoinreq.htm?reqId=' + str(join_req.id) + \
                ' to allow/deny membership to this user.\r\n\r\n'   
            
            def internalSender(rcvr_accounts):
                mailman.sendToInbox(myself.username, rcvr_accounts[0].username, 'Request to join ' + community.name, msg_to_admin_html, 'TM', 'H')
            
            def externalSender(rcvr_accounts):    
                sender = '"' + myself.name + '" <' + myself.username + '*****@*****.**>'
                receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>'  for rcvr in rcvr_accounts]                
                ext_msg_to_admin_html = msg_to_admin_html + \
                    '<br /><br /><br /><br /><br />' + \
                    'If you don\'t want to receive notification emails, change your Account Settings ' + \
                    '<a href="' + config.server_base_url + '/me/editsettings.htm">here</a>'                
                ext_msg_to_admin_text = msg_to_admin_text + \
                    '\r\n\r\n\r\n\r\n\r\n' + \
                    'If you don\'t want to receive notification emails, change your Account Settings here\r\n' + \
                    config.server_base_url + '/me/editsettings.htm'                                
                mailman.sendMail(sender, receivers, 'Request to join ' + community.name, ext_msg_to_admin_html, 
                    None, None, ext_msg_to_admin_text, reply_to=myself.email)

            admin_account = models.Account.objects.get(username=community.owner_username)
            mailman.sendBySettings([admin_account], internalSender, externalSender, 'SocialrayAlert')
            
            return ajaxian.getSuccessResp('request_sent')
        
    except:
        return ajaxian.getFailureResp('unknown')
def handle(request):
    myself = siteaction.getLoggedInUser(request)    
    if not myself:
        return HttpResponseRedirect('/login.htm')
    
    rcvr = rcvr_comm = None    
    rcvr_id = dataplus.dictGetVal(request.REQUEST, 'rcvrId', 0, string.atoi)
    rcvr_type = dataplus.dictGetVal(request.REQUEST,'rcvrType')
    
    if rcvr_type == 'u':
        rcvr = dataplus.returnIfExists(models.User.objects.filter(id=rcvr_id))
        if not rcvr:
            return  siteaction.render_to_response('me/showmessage.htm', 
                                {'myself':myself, 'msg_heading':'Error', 'msg_html':'Invalid Request'})
        receivers =  [rcvr]
    elif rcvr_type == 'c':
        rcvr_comm = dataplus.returnIfExists(models.Community.objects.filter(id=rcvr_id))
        if not rcvr_comm:
            return  siteaction.render_to_response('me/showmessage.htm', 
                                {'myself':myself, 'msg_heading':'Error', 'msg_html':'Invalid Request'})
    
    if request.method == 'GET':
        if rcvr:
            receiver_html = '<a href="' + config.profiles_url + '/' + rcvr.username + '" >' + rcvr.name + '</a>'
        elif rcvr_comm:
            receiver_html = 'Members of <a href="' + config.communities_url + '/' + str(rcvr_comm.id) + '" >' + rcvr_comm.name + '</a>' 
        
        experience_select_html = hotmetal.elemSelect([('Select', '-1')], range(0,30),
            lambda x:x, lambda x:x, '', 'name="experience" id="experience" style="width:80px"')
        
        industry_categories_select_html = hotmetal.elemSelect([('Select', '-1')], models.IndustryCategory.objects.all().order_by('name'),
            lambda x:x.name, lambda x:x.name, '', 'name="industry_category" id="industry_category" style="width:180px"')
            
        old_referrals = myself.posted_referrals.order_by('-created_at')[:20]
        old_referrals_select_html = hotmetal.elemSelect([('Select', '0')], old_referrals,
            lambda x:x.subject + ' (' + dataplus.getStrDate(x.created_at) + ')', lambda x:x.id, '', 'name="old_referral" id="old_referral" style="width:280px;" onchange="resetReferral();"')
            
        return siteaction.render_to_response('me/sendjobreferral.htm',
            {'myself': myself,
            'rcvrId':rcvr_id,
            'rcvrType':rcvr_type,
            'receiver_html':receiver_html,
            'has_old_referrals': (old_referrals.count() > 0),
            'old_referrals_select_html':old_referrals_select_html,
            'experience_select_html':experience_select_html,
            'sending_to_user': (rcvr_type == 'u'),
            'industry_categories_select_html':industry_categories_select_html,})
            
    elif request.method == 'POST':
        job_ref_id = dataplus.dictGetVal(request.REQUEST, 'referral_id', 0, string.atoi)
        if job_ref_id > 0:
            job_ref = models.JobReferral.objects.get(id=job_ref_id)
        else:
            job_ref = models.JobReferral()
            job_ref.sender = myself        
            if rcvr:
                receivers = [rcvr]
                job_ref.industry_category = rcvr.industry_category
                if rcvr.working_since:
                    job_ref.min_experience_years = (datetime.datetime.utcnow() - rcvr.working_since).days/365
            else:
                receivers = [x for x in rcvr_comm.members.all() if x.username != myself.username]
                job_ref.industry_category = models.IndustryCategory.objects.get(name=dataplus.dictGetVal(request.REQUEST, 'industry_category'))
                job_ref.min_experience_years = dataplus.dictGetVal(request.REQUEST, 'experience', 0, string.atoi)
                
            job_ref.subject = dataplus.dictGetSafeVal(request.REQUEST, 'subject')
            job_ref.reply_to_email = dataplus.dictGetSafeVal(request.REQUEST, 'reply_to')
            job_ref.text = dataplus.dictGetSafeVal(request.REQUEST, 'text')
            job_ref.save()
        
        for receiver in receivers:
            job_ref.receivers.add(receiver)
        
        html_message = dataplus.replaceHtmlLineBreaks(job_ref.text) + '<p><a href="' + config.server_base_url + '/me/viewreferral.htm?id=' + str(job_ref.id) + '">Forward your resume</a></p>'
        text_message = job_ref.text + '\r\n Visit ' + config.server_base_url + '/me/viewreferral.htm?id=' + str(job_ref.id) + ' to forward your resume.\r\n\r\n'
        
        subject = 'Job Referral: ' + job_ref.subject
        def internalSender(rcvr_accounts):
            mailman.sendMessage(myself.username, [rcvr.username for rcvr in rcvr_accounts], subject, html_message)
            
        def externalSender(rcvr_accounts):
            sender = '"' + myself.name + '" <' + myself.username + '*****@*****.**>'
            receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>' for rcvr in rcvr_accounts]
            ext_html_message = html_message + \
                '<br /><br /><br /><br /><br />' + \
                'If you don\'t want to receive notification emails, change your Account Settings ' + \
                '<a href="' + config.server_base_url + '/me/editsettings.htm">here</a>'                
            ext_text_message = text_message + \
                '\r\n\r\n\r\n\r\n\r\n' + \
                'If you don\'t want to receive notification emails, change your Account Settings here\r\n' + \
                config.server_base_url + '/me/editsettings.htm'
            mailman.sendMail(sender, receivers, subject, ext_html_message, None, None, ext_text_message, reply_to=myself.email)
        
        mailman.sendBySettings([rcvr.account for rcvr in receivers], internalSender, externalSender, 'JobReferral')
        
        return HttpResponseRedirect('/me/?flashId=jobref_sent')
示例#10
0
def handle(request):
    testimonial_id = dataplus.dictGetVal(request.REQUEST,'testimonialId')
    test_req = dataplus.returnIfExists(models.TestimonialRequest.objects.filter(req_random_key=testimonial_id))
    if test_req is None:
        return siteaction.render_to_response('me/showmessage.htm',
            { 'msg_heading':'Error', 'msg_html':'This testimonial request does not exist.' })
    
    if request.method == 'GET':       
        return siteaction.render_to_response('me/writetestimonial.htm',
            {'from_name':test_req.sent_to_name,
             'to_name':test_req.sent_by.name})
            
    elif request.method == 'POST':                
        testimonial = models.Testimonial()
        testimonial.written_by = dataplus.dictGetSafeVal(request.REQUEST, 'name')
        testimonial.written_for = test_req.sent_by
        testimonial.text = dataplus.dictGetSafeVal(request.REQUEST, 'body')
        testimonial.designation = dataplus.dictGetSafeVal(request.REQUEST, 'designation')
        testimonial.company = dataplus.dictGetSafeVal(request.REQUEST, 'company')
        testimonial.relationship = dataplus.dictGetSafeVal(request.REQUEST, 'relationship')
        testimonial.written_on = datetime.datetime.utcnow()
        testimonial.writer_email = test_req.sent_to_email
        testimonial.save()
        
        #we need to delete the test-request since it should not be re-used
        test_req.delete()
        

        html_message = '<p>You can see the testimonial ' + testimonial.written_by + ' has written on ' + \
            '<a href="' + config.server_base_url + '/profiles/' +  testimonial.written_for.username + '">your profile</a>.</p>' + \
            '<p>Regards,<br />Socialray</p>'
            
        text_message = 'To see the testimonial ' + testimonial.written_by + ' has written, you can visit your profile at ' + \
            config.server_base_url + '/profiles/' +  testimonial.written_for.username + '.\r\n' + \
            'Regards,\r\nSocialray\r\n\r\n'
        
        subject = testimonial.written_by + ' has written a testimonial'
        def internalSender(rcvr_accounts):
            mailman.sendToInbox(None, rcvr_accounts[0].username, subject, html_message, 'SA', 'H')
        
        def externalSender(rcvr_accounts):
            receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>'  for rcvr in rcvr_accounts]
            ext_html_message = html_message + \
                '<br /><br /><br /><br /><br />' + \
                'If you don\'t want to receive notification emails, change your Account Settings ' + \
                '<a href="' + config.server_base_url + '/me/editsettings.htm">here</a>'                
            ext_text_message = text_message + \
                '\r\n\r\n\r\n\r\n\r\n' + \
                'If you don\'t want to receive notification emails, change your Account Settings here\r\n' + \
                config.server_base_url + '/me/editsettings.htm'
            mailman.sendOneWayMail(config.system_email, receivers, subject, ext_html_message, 
                None, None, ext_text_message)
        
        mailman.sendBySettings([testimonial.written_for.account], internalSender, externalSender, 'SocialrayAlert')
        
        myself = siteaction.getLoggedInUser(request)
        if myself:
            return HttpResponseRedirect('/me/?flashId=test_added')
        else:
            return siteaction.render_to_response('me/showmessage.htm',
            { 'msg_heading':'Testimonial Added', 
              'msg_html': '<p>Thanks for adding a testimonial.</p>' + \
              '<p><strong>Have you joined Socialray?</strong><br />Socialray is a Professional Networking and Jobs site. ' + \
              'But There is a lot more to Socialray than just being a place where people post their resumes and ' + \
              'hunt for jobs. You can\'t call Socialray a regular Social Networking site either.</p>' + \
              '<p>We invite you to <a href="' + config.server_base_url + '/me/signup.htm">Join us</a>.</p>' + \
              '<p>To find out more, you can start with the <a href="' + config.server_base_url + '">Home Page</a>.</p>'            
            })
def handle(request):
    try:
        logged_in_type = siteaction.getLoggedInAccountType(request)
        if logged_in_type == "U":
            myself = siteaction.getLoggedInUser(request)
        elif logged_in_type == "R":
            myself = siteaction.getLoggedInRecruiter(request)
        else:
            return ajaxian.getFailureResp("not_logged_in")

        quest_to_user = dataplus.dictGetVal(request.REQUEST, "questToUser")
        question_text = dataplus.dictGetSafeVal(request.REQUEST, "question")

        question = models.ResumeQuestion()
        question.sender = myself.account
        question.receiver = models.User.objects.get(username=quest_to_user)
        question.question = question_text
        question.answer = ""
        question.is_answered = False
        question.is_public = False
        question.sent_at = datetime.datetime.utcnow()
        question.save()

        html_message = (
            myself.name
            + ' wants to know more about your resume and has asked this question, <strong>"'
            + question_text
            + '"</strong><br /><br />You may want to <a href="'
            + config.server_base_url
            + "/me/answerresumequestion.htm?qid="
            + str(question.id)
            + '">Answer this question</a>'
        )

        text_message = (
            myself.name
            + ' wants to know more about your resume and has asked this question, "'
            + question_text
            + '"\r\n\r\nYou can answer this question by visiting this url: '
            + config.server_base_url
            + "/me/answerresumequestion.htm?qid="
            + str(question.id)
        )

        def internalSender(rcvr_accounts):
            mailman.sendToInbox(
                myself.username, rcvr_accounts[0].username, "A question for you!", html_message, "TM", "H"
            )

        def externalSender(rcvr_accounts):
            sender = '"' + myself.name + '" <' + myself.username + "*****@*****.**>"
            receivers = ['"' + rcvr.name + '" <' + rcvr.email + ">" for rcvr in rcvr_accounts]
            mailman.sendMail(
                sender, receivers, "A question for you!", html_message, None, None, text_message, reply_to=myself.email
            )

        mailman.sendBySettings([question.receiver.account], internalSender, externalSender, "ResumeQuestion")

        return ajaxian.getSuccessResp("")
    except:
        return ajaxian.getFailureResp("unknown")