Пример #1
0
    def send_mail_to_group(self, context, exclude_emails=None):
        """
        Send email to org/group users.
        @param context: Is dict of data required by email template.
        @exclude_emails: Is list of email to be excluded from
        email update.
        """

        if exclude_emails is None:
            exclude_emails = []

        # Collage POC and admin email
        poc_admin_user = Profile.get_user_with_type(
            user_type=['Collage POC', 'admin']).values_list('email', flat=True)
        # Org user email
        org_user_emails = self.object.requester.user.filter(
            is_active=True).values_list('email', flat=True)
        # all presenter if any
        all_presenter_email = self.object.presenter.values_list('email',
                                                                flat=True)
        # List of tutor who have shown interest in that location
        region_interested_member = Profile.objects.filter(
            interested_locations=self.object.requester.location,
            usertype__slug='tutor').values_list('user__email', flat=True)

        all_email = []
        all_email.extend(org_user_emails)
        all_email.extend(all_presenter_email)
        all_email.extend(poc_admin_user)
        all_email.extend(region_interested_member)
        all_email = set(all_email)
        all_email = list(all_email.difference(exclude_emails))
        send_mail(all_email, context, self.email_dir)
Пример #2
0
def workshop_create(request):
    template_name = 'workshops/workshop_create.html'
    context_dict = {}
    if not Organisation.list_user_organisations(request.user).exists():
        msg = """
                To request workshop you need to create organisaiton.\n\n
                Please use organisation tab above to create your organisation
            """
        return render(request, 'error.html', {'message': msg})
    if request.method == 'GET':
        form = WorkshopForm(user=request.user)
        context_dict['form'] = form
        return render(request, template_name, context_dict)
    form = WorkshopForm(user=request.user, data=request.POST)
    if not form.is_valid():
        context_dict['form'] = form
        context_dict['errors'] = form.errors
        return render(request, template_name, context_dict)
    workshop = form.save()
    domain = Site.objects.get_current().domain
    context = {
        'workshop': workshop,
        'date': workshop.expected_date,
        'workshop_url': domain + '/workshop/{}/'.format(workshop.id)
    }
    # Collage POC and admin email
    poc_admin_user = Profile.get_user_with_type(
        user_type=['Collage POC', 'admin']
    ).values_list('email', flat=True)

    org_user_emails = workshop.requester.user.filter(
        is_active=True).values_list('email', flat=True)
    # all presenter if any
    all_presenter_email = workshop.presenter.values_list(
        'email', flat=True)
    # List of tutor who have shown interest in that location
    region_interested_member = Profile.objects.filter(
        interested_locations=workshop.requester.location,
        usertype__slug='tutor'
    ).values_list('user__email', flat=True)
    all_email = []
    all_email.extend(org_user_emails)
    all_email.extend(all_presenter_email)
    all_email.extend(poc_admin_user)
    all_email.extend(region_interested_member)
    all_email = set(all_email)
    send_tweet(context)

    subject = '[PythonExpress] Workshop request status.'
    email_body = loader.get_template(
        'email_messages/workshop/create_workshop/message.html').render(context)
    text_body = loader.get_template(
        'email_messages/workshop/create_workshop/message.txt').render(context)
    send_email_to_list(
        subject,
        body=email_body,
        users_list=all_email,
        text_body=text_body)
    success_url = reverse_lazy('workshops:workshop_list')
    return HttpResponseRedirect(success_url)
Пример #3
0
def workshop_create(request):
    template_name = "workshops/workshop_create.html"
    context_dict = {}
    if not Organisation.list_user_organisations(request.user).exists():
        msg = """
                To request workshop you need to create organisaiton.\n\n
                Please use organisation tab above to create your organisation
            """
        return render(request, "error.html", {"message": msg})
    if request.method == "GET":
        form = WorkshopForm(user=request.user)
        context_dict["form"] = form
        return render(request, template_name, context_dict)
    form = WorkshopForm(user=request.user, data=request.POST)
    if not form.is_valid():
        context_dict["form"] = form
        context_dict["errors"] = form.errors
        return render(request, template_name, context_dict)
    workshop = form.save()
    domain = Site.objects.get_current().domain
    context = {
        "workshop": workshop,
        "date": workshop.expected_date,
        "workshop_url": domain + "/workshop/{}/".format(workshop.id),
    }
    # Collage POC and admin email
    poc_admin_user = Profile.get_user_with_type(user_type=["Collage POC", "admin"]).values_list("email", flat=True)

    org_user_emails = workshop.requester.user.filter(is_active=True).values_list("email", flat=True)
    # all presenter if any
    all_presenter_email = workshop.presenter.values_list("email", flat=True)
    # List of tutor who have shown interest in that location
    region_interested_member = Profile.objects.filter(
        interested_locations=workshop.requester.location, usertype__slug="tutor"
    ).values_list("user__email", flat=True)
    all_email = []
    all_email.extend(org_user_emails)
    all_email.extend(all_presenter_email)
    all_email.extend(poc_admin_user)
    all_email.extend(region_interested_member)
    all_email = set(all_email)
    send_tweet(context)

    subject = "[PythonExpress] Workshop request status."
    email_body = loader.get_template("email_messages/workshop/create_workshop/message.html").render(context)
    text_body = loader.get_template("email_messages/workshop/create_workshop/message.txt").render(context)
    send_email_to_list(subject, body=email_body, users_list=all_email, text_body=text_body)
    success_url = reverse_lazy("workshops:workshop_list")
    return HttpResponseRedirect(success_url)
Пример #4
0
    def send_mail(self, user, assigned):
        """Send email to presenter and org users."""

        workshop = self.object
        email_dir = 'workshops/email/assign_me/'
        last_presenter = user
        # Collage POC and admin email
        poc_admin_user = Profile.get_user_with_type(
            user_type=['Collage POC', 'admin']
        ).values_list('email', flat=True)
        # Org user email
        org_user_emails = workshop.requester.user.filter(
            is_active=True
        ).values_list('email', flat=True)
        # all presenter except current assigned presenter
        all_presenter_email = workshop.presenter.exclude(
            pk=last_presenter.pk
        ).values_list(
            'email', flat=True
        )
        context = {
            'presenter': True,
            'assigned': assigned,
            'date': workshop.expected_date,
            'presenter_name': last_presenter.username,
            'workshop_organization': workshop.requester,
            'workshop_url': self.request.build_absolute_uri(reverse(
                'workshops:workshop_detail', args=[workshop.pk]
            ))
        }
        # Send email to presenter
        send_mail([last_presenter.email], context, email_dir)
        # Send email to org users and other presenter(s).
        context['presenter'] = False
        all_email = []
        all_email.extend(org_user_emails)
        all_email.extend(all_presenter_email)
        all_email.extend(poc_admin_user)
        all_email = list(set(all_email))
        send_mail(all_email, context, email_dir)
Пример #5
0
    def send_mail_to_group(self, context, exclude_emails=None):
        """
        Send email to org/group users.
        @param context: Is dict of data required by email template.
        @exclude_emails: Is list of email to be excluded from
        email update.
        """

        if exclude_emails is None:
            exclude_emails = []

        # Collage POC and admin email
        poc_admin_user = Profile.get_user_with_type(
            user_type=['Collage POC', 'admin']
        ).values_list('email', flat=True)
        # Org user email
        org_user_emails = self.object.requester.user.filter(
            is_active=True
        ).values_list('email', flat=True)
        # all presenter if any
        all_presenter_email = self.object.presenter.values_list(
            'email', flat=True
        )
        # List of tutor who have shown interest in that location
        region_interested_member = Profile.objects.filter(
            interested_locations=self.object.requester.location,
            usertype__slug='tutor'
        ).values_list('user__email', flat=True)

        all_email = []
        all_email.extend(org_user_emails)
        all_email.extend(all_presenter_email)
        all_email.extend(poc_admin_user)
        all_email.extend(region_interested_member)
        all_email = set(all_email)
        all_email = list(all_email.difference(exclude_emails))
        send_mail(all_email, context, self.email_dir)