示例#1
0
def create_welcome_email(user, request):
    # fish out all the relevant information about the user and
    # then create an unsent WelcomeEmail

    subject = u"Welcome to %s" % settings.PROJECT_NAME
    try:
        person = user.get_profile()
    except KungfuPerson.DoesNotExist:
        return None

    alu = AutoLoginKey.get_or_create(user)
    profile_url = reverse('person.view', args=(user.username, ))
    upload_photo_url = reverse('upload_profile_photo', args=(user.username, ))
    change_password_url = reverse("edit_password", args=(user.username, ))
    edit_style_url = reverse("edit_style", args=(user.username, ))
    edit_club_url = reverse("edit_club", args=(user.username, ))
    edit_profile_url = reverse("edit_profile", args=(user.username, ))

    data = locals()

    domain = RequestSite(request).domain
    base_url = 'http://%s' % domain

    # for every variable that ends with _url make it an absolute url
    # and add the _alu variable
    def aluify_url(url):
        if '?' in url:
            return url + '&alu=%s' % alu.uuid
        else:
            return url + '?alu=%s' % alu.uuid

    keys = list(data.keys())
    for key in keys:
        if key.endswith('_url'):
            url = data[key]
            if url.startswith('/'):
                url = base_url + url
            data[key] = url
            data[key + '_alu'] = aluify_url(url)

    # now the interesting thing starts. We need to find out what they haven't
    # done with their profile and pester them about that.
    response = render(request, 'welcome-email.html', data)
    html = response.content

    html = Premailer(
        html,
        base_url=base_url,
        keep_style_tags=False,
    ).transform()

    return WelcomeEmail.objects.create(
        user=user,
        subject=subject,
        body=html,
    )
示例#2
0
def create_welcome_email(user, request):
    # fish out all the relevant information about the user and
    # then create an unsent WelcomeEmail
    
    subject = u"Welcome to %s" % settings.PROJECT_NAME
    try:
        person = user.get_profile()
    except KungfuPerson.DoesNotExist:
        return None
    
    alu = AutoLoginKey.get_or_create(user)
    profile_url = reverse('person.view', args=(user.username,))
    upload_photo_url = reverse('upload_profile_photo', args=(user.username,))
    change_password_url = reverse("edit_password", args=(user.username,))
    edit_style_url = reverse("edit_style", args=(user.username,))
    edit_club_url = reverse("edit_club", args=(user.username,))
    edit_profile_url = reverse("edit_profile", args=(user.username,))
    
    data = locals()
    
    domain = RequestSite(request).domain
    base_url = 'http://%s' % domain
    
    # for every variable that ends with _url make it an absolute url
    # and add the _alu variable
    def aluify_url(url):
        if '?' in url:
            return url + '&alu=%s' % alu.uuid
        else:
            return url + '?alu=%s' % alu.uuid
        
    keys = list(data.keys())
    for key in keys:
        if key.endswith('_url'):
            url = data[key]
            if url.startswith('/'):
                url = base_url + url
            data[key] = url
            data[key + '_alu'] = aluify_url(url)
            
    # now the interesting thing starts. We need to find out what they haven't
    # done with their profile and pester them about that.
    response = render(request, 'welcome-email.html', data)
    html = response.content
    
    
    html = Premailer(html, base_url=base_url,
                     keep_style_tags=False,
                    ).transform()
    
    return WelcomeEmail.objects.create(user=user,
                                       subject=subject,
                                       body=html,
                                      )
示例#3
0
 def _append_autologin_urls(self, person, context):
     """context is a dict like this:
       {'first_name': u'Peter', 
        'profile_url': 'http://example.com/peterbe',
        ...}
     
     Now, for every variable that ends with '_url' add
     '?alu=550269bc-bc67-4085-ba1a-04f3f0290288'
     (or &alu=... if ? is already in the URL)
     """
     alu = AutoLoginKey.get_or_create(person.user)
     for key in context.keys():
         if key.endswith('_url'):
             url = context[key]
         else:
             continue
         key += '_alu'
         if '?' in url:
             url += '&alu=%s' % alu.uuid
         else:
             url += '?alu=%s' % alu.uuid
         context[key] = url