Exemplo n.º 1
0
    def form_valid(self, form, **kwargs):
        context = self.get_context_data(**kwargs)

        data = form.cleaned_data

        email_context = {'data': data}

        # render text and html versions of email body
        # both plain txt for now
        text_content = render_to_string(
            'guides/_v2/emails/suggest_guide.txt',
            email_context,
        )
        html_content = render_to_string('guides/_v2/emails/suggest_guide.html',
                                        email_context)

        send_multipart_email(subject='Source: Guide suggestion from a reader',
                             from_email=settings.DEFAULT_FROM_EMAIL,
                             to=settings.EDITORIAL_EMAIL,
                             text_content=text_content,
                             html_content=html_content)

        context.update({'success': 'True'})

        return render(self.request, self.template_name, context)
Exemplo n.º 2
0
    def form_valid(self, form, **kwargs):
        context = self.get_context_data(**kwargs)

        data = form.cleaned_data

        # human-friendly version of `repo_difficulty` form value
        try:
            data['repo_difficulty'] = dict(REPO_DIFFICULTY_CHOICES)[
                data['repo_difficulty']]
        except:
            pass

        email_context = {'data': data}

        # render text and html versions of email body
        # both plain txt for now
        text_content = render_to_string(
            'code/_v2/emails/suggest_repo.txt',
            email_context,
        )
        html_content = render_to_string('code/_v2/emails/suggest_repo.html',
                                        email_context)

        send_multipart_email(subject='Source: Repo submission from a reader',
                             from_email=settings.DEFAULT_FROM_EMAIL,
                             to=settings.EDITORIAL_EMAIL,
                             text_content=text_content,
                             html_content=html_content)

        context.update({'success': 'True'})

        return render(self.request, self.template_name, context)
Exemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        email = request.POST.get('email')
        job_update_url = reverse('job_update')
        
        try:
            user = User.objects.get(username__iexact=email)
        except:
            # a User record is automatically created when
            # an OrganizationAdmin is added. If no User record
            # is found, the address shouldn't be logging in. 
            msg = 'Sorry, no admin account associated with this email address.'
            messages.error(request, msg)
            return redirect(job_update_url)        

        # use django-sesame to send magic login link
        site_url = '{}://{}'.format(request.scheme, get_current_site(request))
        login_token = sesame_utils.get_query_string(user)
        login_link = '{}{}{}'.format(site_url, job_update_url, login_token)
                
        msg = 'We just emailed you a login link! Please check your inbox.'
        
        email_context = {
            'site_url': site_url,
            'login_link': login_link,
        }
    
        text_content = render_to_string(
            'jobs/_v2/emails/jobs_admin_login.txt',
            email_context,
        )
        html_content = render_to_string(
            'jobs/_v2/emails/jobs_admin_login.html',
            email_context
        )

        send_multipart_email(
            subject = 'Source Jobs: Log in to your account',
            from_email = settings.DEFAULT_FROM_EMAIL,
            to = email,
            text_content = text_content,
            html_content = html_content
        )

        if request.is_ajax():
            result = {'message': msg}
            return render_json_to_response(result)

        messages.success(request, msg)
        return redirect(job_update_url)
Exemplo n.º 4
0
    def handle(self, *args, **options):
        logging.info('Started job: %s' % datetime.now())
        
        organizations_with_jobs_ids = set(Job.live_objects.values_list('organization', flat=True))
        organizations_with_jobs = Organization.objects.filter(id__in=organizations_with_jobs_ids)
        
        for organization in organizations_with_jobs:
            jobs = Job.live_objects.filter(organization=organization)
            
        
        
            # add context for rendering personalized emails
            subject = '[Source] Monthly update from Source Jobs'
            email_context = {
                'site_url': settings.BASE_SITE_URL,
                'organization': organization,
                'jobs': jobs,
            }
        
            # render text and html versions of email body
            text_content = render_to_string(
                'jobs/emails/job_post_reminder.txt',
                email_context,
            )
            html_content = render_to_string(
                'jobs/emails/job_post_reminder.html',
                email_context
            )

            send_multipart_email(
                subject = subject,
                from_email = settings.DEFAULT_FROM_EMAIL,
                to = organization.email,
                text_content = text_content,
                html_content = html_content
            )
            
            # avoid rate limit
            sleep(1)
            
        
        logging.info('Finished job: %s' % datetime.now())
    def handle(self, *args, **options):
        logging.info('Started job: %s' % datetime.now())

        organizations_with_jobs_ids = set(
            Job.live_objects.values_list('organization', flat=True))
        organizations_with_jobs = Organization.objects.filter(
            id__in=organizations_with_jobs_ids)

        for organization in organizations_with_jobs:
            jobs = Job.live_objects.filter(organization=organization)

            # add context for rendering personalized emails
            subject = '[Source] Monthly update from Source Jobs'
            email_context = {
                'site_url': settings.BASE_SITE_URL,
                'organization': organization,
                'jobs': jobs,
            }

            # render text and html versions of email body
            text_content = render_to_string(
                'jobs/emails/job_post_reminder.txt',
                email_context,
            )
            html_content = render_to_string(
                'jobs/emails/job_post_reminder.html', email_context)

            send_multipart_email(subject=subject,
                                 from_email=settings.DEFAULT_FROM_EMAIL,
                                 to=organization.email,
                                 text_content=text_content,
                                 html_content=html_content)

            # avoid rate limit
            sleep(1)

        logging.info('Finished job: %s' % datetime.now())