Exemplo n.º 1
0
def contact(request):
    if request.method == 'POST':
        form = ContactUsForm(request.POST)
        if form.is_valid():
            email_context = Context({
                'contact_name':
                form.cleaned_data['name'],
                'contact_email':
                form.cleaned_data['email'],
                'comments':
                form.cleaned_data['comments'],
                'conatct_number':
                form.cleaned_data['contact_number'],
                'feedback_type':
                form.cleaned_data['feedback_type']
            })

            subject = "PythonExpress Feedback by %s" % (
                form.cleaned_data['name'])
            text_body = loader.get_template(
                'email_messages/contactus/message.txt').render(email_context)
            email_body = loader.get_template(
                'email_messages/contactus/message.html').render(email_context)
            user_subject = '[PythonExpress] Feedback Received'
            user_text_body = loader.get_template(
                'email_messages/contactus/message_user.txt').render(
                    email_context)
            user_email_body = loader.get_template(
                'email_messages/contactus/message_user.html').render(
                    email_context)
            site_admins = [email for name, email in settings.MANAGERS
                           ]  # @UnusedVariable
            try:
                regional_lead = Profile.objects.filter(
                    usertype__slug__in=['lead', 'admin']).values_list(
                        'user__email', flat=True)
                regional_lead.extend(site_admins)
                send_email_to_list(subject,
                                   users_list=regional_lead,
                                   body=email_body,
                                   text_body=text_body)

                send_email_to_id(user_subject,
                                 body=user_email_body,
                                 email_id=form.cleaned_data['email'],
                                 text_body=user_text_body)
            except Exception as e:
                print(e)
            return HttpResponseRedirect('/thankyou')
    else:
        if request.user.is_authenticated():
            form = ContactUsForm(
                initial={
                    'name': request.user.first_name + " " +
                    request.user.last_name,
                    'email': request.user.email
                })
        else:
            form = ContactUsForm()
    return render(request, 'contact.html', {'form': form})
Exemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        form = OrganisationForm(data=request.POST)
        if form.is_valid():
            form.instance.modified_by = request.user
            form.instance.created_by = request.user
            form.instance.save()
            form.instance.user.add(request.user)
            form.instance.save()
            host = "{}://{}".format(settings.SITE_PROTOCOL, request.META["HTTP_HOST"])
            email_context = Context(
                {
                    "full_name": "%s %s" % (request.user.first_name, request.user.last_name),
                    "org_id": form.instance.id,
                    "host": host,
                }
            )
            subject = "%s organisation for region %s is created" % (form.instance.name, form.instance.location.name)
            email_body = loader.get_template("email_messages/organisation/new.html").render(email_context)
            text_body = loader.get_template("email_messages/organisation/new.txt").render(email_context)

            try:

                send_email_to_id(subject, body=email_body, email_id=request.user.email, text_body=text_body)
            except Exception as e:
                print(e)
            try:
                regional_lead = Profile.objects.filter(
                    interested_locations=form.instance.location, usertype__slug="lead"
                ).values_list("user__email", flat=True)
                send_email_to_list(subject, body=email_body, users_list=regional_lead, text_body=text_body)
            except Exception as e:
                print(e)
            return HttpResponseRedirect(self.success_url)
        else:
            return render(request, self.template_name, {"form": form})
Exemplo n.º 3
0
def feedback_emails(organisation, email_context, email_id):
    subject = '[PythonExpress] Request for Workshop Feedback {}, {}'.format(
        organisation.name, organisation.location.name)
    email_body = loader.get_template(
        'email_messages/workshop/feedback_email.html').render(email_context)
    text_body = loader.get_template(
        'email_messages/workshop/feedback_email.txt').render(email_context)
    send_email_to_id(subject,
                     body=email_body,
                     email_id=email_id,
                     text_body=text_body)
Exemplo n.º 4
0
def remainder_email(organisation, email_context, email_id):
    subject = '[PythonExpress] Remainder for workshop at {}, {}'.format(
        organisation.name, organisation.location.name)
    email_body = loader.get_template(
        'email_messages/workshop/remainder.html').render(email_context)
    text_body = loader.get_template(
        'email_messages/workshop/remainder.txt').render(email_context)
    send_email_to_id(subject,
                     body=email_body,
                     email_id=email_id,
                     text_body=text_body)
Exemplo n.º 5
0
def partner_view(request):
    if request.method == 'POST':
        form = PartnerForm(request.POST)
        if form.is_valid():
            email_context = Context({
                'org_name': form.cleaned_data['org_name'],
                'org_url': form.cleaned_data['org_url'],
                'partner_type': form.cleaned_data['partner_type'],
                'description': form.cleaned_data['description'],
                'python_use': form.cleaned_data['python_use'],
                'comments': form.cleaned_data['comments'],
                'name': form.cleaned_data['name'],
                'email': form.cleaned_data['email'],
                'contact_name': form.cleaned_data['name'],
                'contact_email': form.cleaned_data['email'],
                'conatct_number': form.cleaned_data['contact_number'],

            })

            subject = "[PythonExpress] Partnership request by %s" % (
                form.cleaned_data['org_name'])
            text_body = loader.get_template(
                'email_messages/partner/partner_message.txt').render(
                email_context)
            email_body = loader.get_template(
                'email_messages/partner/partner_message.html').render
            (email_context)
            user_subject = '[PythonExpress] Partnership request Received'
            user_text_body = loader.get_template(
                'email_messages/partner/message_user.txt').render(
                email_context)
            user_email_body = loader.get_template(
                'email_messages/partner/message_user.html').render(
                email_context)

            try:
                send_email_to_list(
                    subject,
                    users_list=['*****@*****.**'],
                    body=email_body,
                    text_body=text_body)

                send_email_to_id(
                    user_subject,
                    body=user_email_body,
                    email_id=form.cleaned_data['email'],
                    text_body=user_text_body)
            except Exception as e:
                print(e)
            return HttpResponseRedirect('/thankyou')
    else:
        form = PartnerForm()
    return render(request, 'partner.html', {'form': form})
Exemplo n.º 6
0
    def post(self, request, *args, **kwargs):
        form = OrganisationForm(data=request.POST)
        if form.is_valid():
            form.instance.modified_by = request.user
            form.instance.created_by = request.user
            form.instance.save()
            form.instance.user.add(request.user)
            form.instance.save()
            user_profile = Profile.objects.get(
                user__id=self.request.user.id)
            if not ('poc' in user_profile.get_user_type):
                poc_type = UserType.objects.get(slug='poc')
                user_profile.usertype.add(poc_type)
                user_profile.save()

            host = '{}://{}'.format(settings.SITE_PROTOCOL,
                                    request.META['HTTP_HOST'])
            email_context = Context({
                'full_name': '%s %s' % (request.user.first_name,
                                        request.user.last_name),
                'org_id': form.instance.id,
                'host': host

            })
            subject = "%s organisation for region %s is created" % (
                form.instance.name, form.instance.location.name)
            email_body = loader.get_template(
                'email_messages/organisation/new.html').render(email_context)
            text_body = loader.get_template(
                'email_messages/organisation/new.txt').render(email_context)

            regional_lead = Profile.objects.filter(
                interested_locations=form.instance.location,
                usertype__slug='lead').values_list('user__email', flat=True)
            send_email_to_id(subject,
                             body=email_body,
                             email_id=request.user.email,
                             text_body=text_body)

            send_email_to_list(subject,
                               body=email_body,
                               users_list=regional_lead,
                               text_body=text_body)

            return HttpResponseRedirect(self.success_url)
        else:
            return render(request, self.template_name, {'form': form})
Exemplo n.º 7
0
    def post(self, request, *args, **kwargs):
        form = OrganisationForm(data=request.POST)
        if form.is_valid():
            form.instance.modified_by = request.user
            form.instance.created_by = request.user
            form.instance.save()
            form.instance.user.add(request.user)
            form.instance.save()
            user_profile = Profile.objects.get(user__id=self.request.user.id)
            if not ('poc' in user_profile.get_user_type):
                poc_type = UserType.objects.get(slug='poc')
                user_profile.usertype.add(poc_type)
                user_profile.save()

            host = '{}://{}'.format(settings.SITE_PROTOCOL,
                                    request.META['HTTP_HOST'])
            email_context = Context({
                'full_name':
                '%s %s' % (request.user.first_name, request.user.last_name),
                'org_id':
                form.instance.id,
                'host':
                host
            })
            subject = "%s organisation for region %s is created" % (
                form.instance.name, form.instance.location.name)
            email_body = loader.get_template(
                'email_messages/organisation/new.html').render(email_context)
            text_body = loader.get_template(
                'email_messages/organisation/new.txt').render(email_context)

            regional_lead = Profile.objects.filter(
                interested_locations=form.instance.location,
                usertype__slug='lead').values_list('user__email', flat=True)
            send_email_to_id(subject,
                             body=email_body,
                             email_id=request.user.email,
                             text_body=text_body)

            send_email_to_list(subject,
                               body=email_body,
                               users_list=regional_lead,
                               text_body=text_body)

            return HttpResponseRedirect(self.success_url)
        else:
            return render(request, self.template_name, {'form': form})
Exemplo n.º 8
0
def contact(request):
    if request.method == 'POST':
        form = ContactUsForm(request.POST)
        if form.is_valid():
            email_context = Context({
                'contact_name': form.cleaned_data['name'],
                'contact_email': form.cleaned_data['email'],
                'comments': form.cleaned_data['comments'],
                'conatct_number': form.cleaned_data['contact_number'],
                'feedback_type': form.cleaned_data['feedback_type']
            })

            subject = "PythonExpress Feedback by %s" % (
                form.cleaned_data['name'])
            text_body = loader.get_template(
                'email_messages/contactus/message.txt').render(email_context)
            email_body = loader.get_template(
                'email_messages/contactus/message.html').render(email_context)
            user_subject = '[PythonExpress] Feedback Received'
            user_text_body = loader.get_template(
                'email_messages/contactus/message_user.txt').render(
                email_context)
            user_email_body = loader.get_template(
                'email_messages/contactus/message_user.html').render(
                email_context)

            try:
                regional_lead = Profile.objects.filter(
                    usertype__slug__in=['lead', 'admin']).values_list(
                    'user__email', flat=True)
                send_email_to_list(
                    subject,
                    users_list=regional_lead,
                    body=email_body,
                    text_body=text_body)

                send_email_to_id(
                    user_subject,
                    body=user_email_body,
                    email_id=form.cleaned_data['email'],
                    text_body=user_text_body)
            except Exception as e:
                print(e)
            return HttpResponseRedirect('/thankyou')
    else:
        form = ContactUsForm()
    return render(request, 'contact.html', {'form': form})
Exemplo n.º 9
0
Arquivo: views.py Projeto: deshraj/wye
    def form_valid(self, form):

        email_context = Context({
            'contact_name':
            form.cleaned_data['name'],
            'contact_email':
            form.cleaned_data['email'],
            'comments':
            form.cleaned_data['comments'],
            'conatct_number':
            form.cleaned_data['contact_number'],
            'feedback_type':
            form.cleaned_data['feedback_type']
        })

        subject = "PythonExpress Feedback by %s" % (form.cleaned_data['name'])
        text_body = loader.get_template(
            'email_messages/contactus/message.txt').render(email_context)
        email_body = loader.get_template(
            'email_messages/contactus/message.html').render(email_context)
        user_subject = '[PythonExpress] Feedback Received'
        user_text_body = loader.get_template(
            'email_messages/contactus/message_user.txt').render(email_context)
        user_email_body = loader.get_template(
            'email_messages/contactus/message_user.html').render(email_context)

        try:
            regional_lead = Profile.objects.filter(
                usertype__slug__in=['lead', 'admin']).values_list(
                    'user__email', flat=True)
            send_email_to_list(subject,
                               users_list=regional_lead,
                               body=email_body,
                               text_body=text_body)

            send_email_to_id(user_subject,
                             body=user_email_body,
                             email_id=form.cleaned_data['email'],
                             text_body=user_text_body)
        except Exception as e:
            print(e)

        return super(ContactFormView, self).form_valid(form)
Exemplo n.º 10
0
    def form_valid(self, form):

        email_context = Context({
            'contact_name': form.cleaned_data['name'],
            'contact_email': form.cleaned_data['email'],
            'comments': form.cleaned_data['comments'],
            'conatct_number': form.cleaned_data['contact_number'],
            'feedback_type': form.cleaned_data['feedback_type']
            })

        subject = "PythonExpress Feedback by %s" % (form.cleaned_data['name'])
        text_body = loader.get_template(
            'email_messages/contactus/message.txt').render(email_context)
        email_body = loader.get_template(
            'email_messages/contactus/message.html').render(email_context)
        user_subject = '[PythonExpress] Feedback Received'
        user_text_body = loader.get_template(
            'email_messages/contactus/message_user.txt').render(email_context)
        user_email_body = loader.get_template(
            'email_messages/contactus/message_user.html').render(email_context)

        try:
            regional_lead = models.Profile.objects.filter(
                usertype__slug__in=['lead', 'admin']).values_list('user__email', flat=True)
            send_email_to_list(
                subject,
                users_list=regional_lead,
                body=email_body,
                text_body=text_body)
        except Exception as e:
            print(e)
        try:
            send_email_to_id(
                user_subject,
                body=user_email_body,
                email_id=form.cleaned_data['email'],
                text_body=user_text_body)
        except Exception as e:
            print(e)

        return super(ContactFormView, self).form_valid(form)
Exemplo n.º 11
0
    def save(self, force_insert=False, force_update=False, using=None):
        """
        send mail to region interested member whenever new workshop
        is requested in respective region, therefore overriding
        pre save method so mails are only send when new object
        is created.
        :param force_insert: bool force_insert
        :param force_update: bool force_insert
        :param using: using
        :return: instance
        """
        from wye.profiles.models import Profile
        if not self.id:
            domain = Site.objects.get_current().domain
            # get region_interested_member email ids to notify them
            region_interested_member = Profile.objects.filter(
                interested_locations=self.requester.location,
                usertype__slug='tutor').values_list('user__email', flat=True)

            if self and self.id:
                context = {
                    'workshop': self,
                    'date': self.expected_date,
                    'workshop_url': domain + '/workshop/{}/'.format(self.id),
                    'workshop_topic': self.workshop_section.name
                }
                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)
                for email_id in region_interested_member:
                    send_email_to_id(subject,
                                     body=email_body,
                                     email_id=email_id,
                                     text_body=text_body)

        super(Workshop, self).save(force_insert, force_update, using)
Exemplo n.º 12
0
 def post(self, request, *args, **kwargs):
     form = OrganisationForm(data=request.POST)
     if form.is_valid():
         form.instance.modified_by = request.user
         form.instance.created_by = request.user
         form.instance.save()
         form.instance.user.add(request.user)
         form.instance.save()
         email_context = Context({})
         subject = "%s organisation for region %s is created" % (
             form.instance.name, form.instance.location.name)
         email_body = loader.get_template(
             'email_messages/organisation/new.html').render(email_context)
         text_body = loader.get_template(
             'email_messages/organisation/new.txt').render(email_context)
         try:
             send_email_to_id(
                 subject,
                 body=email_body,
                 email_id=request.user.email,
                 text_body=text_body)
         except Exception as e:
             print(e)
         try:
             regional_lead = Profile.objects.filter(
                 interested_locations=form.instance.location,
                 usertype__slug='lead').values_list('user__email', flat=True)
             send_email_to_list(
                 subject,
                 body=email_body,
                 users_list=regional_lead,
                 text_body=text_body)
         except Exception as e:
             print(e)
         return HttpResponseRedirect(self.success_url)
     else:
         return render(request, self.template_name, {'form': form})
Exemplo n.º 13
0
    def post(self, request, *args, **kwargs):
        form = OrganisationMemberAddForm(data=request.POST)
        if form.is_valid():
            existing_user = form.cleaned_data['existing_user']
            new_user = form.cleaned_data['new_user']

            org = Organisation.objects.get(id=self.kwargs['pk'])
            host = '{}://{}'.format(settings.SITE_PROTOCOL,
                                    request.META['HTTP_HOST'])

            context = {
                'full_name': '%s %s' % (request.user.first_name,
                                        request.user.last_name),
                'org_name': org.name,
                'host': host
            }

            if existing_user:
                # add user to organisation
                user = existing_user
                org.user.add(user)
                org.save()

                # set email user's name in context
                context['new_member_name'] = '%s %s' % (user.first_name,
                                                        user.last_name)
                email_context = Context(context)

                # send mail to user being added
                subject = "You are added in %s organisation" % (
                    org.location.name)
                email_body = loader.get_template(
                    'email_messages/organisation/to_new_member_existing.html').render(
                        email_context)
                text_body = loader.get_template(
                    'email_messages/organisation/to_new_member_existing.txt').render(email_context)

                send_email_to_id(subject,
                                 body=email_body,
                                 email_id=user.email,
                                 text_body=text_body)

            elif new_user:
                # generate a random password
                random_password = User.objects.make_random_password()

                # create a user with the email from form
                user = User(username=self.get_username(new_user),
                            email=new_user,
                            password=random_password)

                # user is inactive initialy
                user.is_active = False
                user.save()

                # add the user to organisation
                org.user.add(user.id)
                org.save()

                # set the email context, the token will be used to generate a unique varification
                # link
                token = self.get_token(user)

                context['new_member_name'] = '%s' % (user.email)
                context['token'] = token
                context['user'] = user
                email_context = Context(context)

                # set the meta
                subject = "[Python Express]:You are added in %s organisation" % (
                    org.location.name)
                email_body = loader.get_template(
                    'email_messages/organisation/to_new_member.html').render(email_context)
                text_body = loader.get_template(
                    'email_messages/organisation/to_new_member.txt').render(email_context)

                # send the mail to new user
                send_email_to_id(subject,
                                 body=email_body,
                                 email_id=new_user,
                                 text_body=text_body)

            # These mails will be sent in both cases.
            subject = "user %s %s added in %s organisation" % (
                user.first_name, user.last_name, org.location.name)
            email_body = loader.get_template(
                'email_messages/organisation/member_addition_to_user.html').render(
                    email_context)
            text_body = loader.get_template(
                'email_messages/organisation/member_addition_to_user.txt').render(
                    email_context)

            # send mail to the user who added the new member
            send_email_to_id(subject,
                             body=email_body,
                             email_id=request.user.email,
                             text_body=text_body)

            regional_lead = Profile.objects.filter(
                interested_locations=org.location,
                usertype__slug='lead').values_list('user__email', flat=True)

            email_body = loader.get_template(
                'email_messages/organisation/member_addition_to_lead.html').render(
                    email_context)
            text_body = loader.get_template(
                'email_messages/organisation/member_addition_to_lead.txt').render(
                    email_context)

            # send mail to the regional leads
            send_email_to_list(subject,
                               body=email_body,
                               users_list=regional_lead,
                               text_body=text_body)

            return HttpResponseRedirect(self.success_url)

        else:
            return render(request, self.template_name, {'form': form})
Exemplo n.º 14
0
def partner_view(request):
    if request.method == 'POST':
        form = PartnerForm(request.POST)
        if form.is_valid():
            email_context = Context({
                'org_name':
                form.cleaned_data['org_name'],
                'org_url':
                form.cleaned_data['org_url'],
                'partner_type':
                form.cleaned_data['partner_type'],
                'description':
                form.cleaned_data['description'],
                'python_use':
                form.cleaned_data['python_use'],
                'comments':
                form.cleaned_data['comments'],
                'name':
                form.cleaned_data['name'],
                'email':
                form.cleaned_data['email'],
                'contact_name':
                form.cleaned_data['name'],
                'contact_email':
                form.cleaned_data['email'],
                'conatct_number':
                form.cleaned_data['contact_number'],
            })

            subject = "[PythonExpress] Partnership request by %s" % (
                form.cleaned_data['org_name'])
            text_body = loader.get_template(
                'email_messages/partner/partner_message.txt').render(
                    email_context)
            email_body = loader.get_template(
                'email_messages/partner/partner_message.html').render
            (email_context)
            user_subject = '[PythonExpress] Partnership request Received'
            user_text_body = loader.get_template(
                'email_messages/partner/message_user.txt').render(
                    email_context)
            user_email_body = loader.get_template(
                'email_messages/partner/message_user.html').render(
                    email_context)

            try:
                send_email_to_list(subject,
                                   users_list=['*****@*****.**'],
                                   body=email_body,
                                   text_body=text_body)

                send_email_to_id(user_subject,
                                 body=user_email_body,
                                 email_id=form.cleaned_data['email'],
                                 text_body=user_text_body)
            except Exception as e:
                print(e)
            return HttpResponseRedirect('/thankyou')
    else:
        form = PartnerForm()
    return render(request, 'partner.html', {'form': form})
Exemplo n.º 15
0
    def post(self, request, *args, **kwargs):
        form = OrganisationMemberAddForm(data=request.POST)
        if form.is_valid():
            existing_user = form.cleaned_data['existing_user']
            new_user = form.cleaned_data['new_user']

            org = Organisation.objects.get(id=self.kwargs['pk'])
            host = '{}://{}'.format(settings.SITE_PROTOCOL,
                                    request.META['HTTP_HOST'])

            context = {
                'full_name':
                '%s %s' % (request.user.first_name, request.user.last_name),
                'org_name':
                org.name,
                'host':
                host
            }

            if existing_user:
                # add user to organisation
                user = existing_user
                org.user.add(user)
                org.save()

                # set email user's name in context
                context['new_member_name'] = '%s %s' % (user.first_name,
                                                        user.last_name)
                email_context = Context(context)

                # send mail to user being added
                subject = "You are added in %s organisation" % (
                    org.location.name)
                email_body = loader.get_template(
                    'email_messages/organisation/to_new_member_existing.html'
                ).render(email_context)
                text_body = loader.get_template(
                    'email_messages/organisation/to_new_member_existing.txt'
                ).render(email_context)

                send_email_to_id(subject,
                                 body=email_body,
                                 email_id=user.email,
                                 text_body=text_body)

            elif new_user:
                # generate a random password
                random_password = User.objects.make_random_password()

                # create a user with the email from form
                user = User(username=self.get_username(new_user),
                            email=new_user,
                            password=random_password)

                # user is inactive initialy
                user.is_active = False
                user.save()

                # add the user to organisation
                org.user.add(user.id)
                org.save()

                # set the email context, the token will be used to generate a unique varification
                # link
                token = self.get_token(user)

                context['new_member_name'] = '%s' % (user.email)
                context['token'] = token
                context['user'] = user
                email_context = Context(context)

                # set the meta
                subject = "[Python Express]:You are added in %s organisation" % (
                    org.location.name)
                email_body = loader.get_template(
                    'email_messages/organisation/to_new_member.html').render(
                        email_context)
                text_body = loader.get_template(
                    'email_messages/organisation/to_new_member.txt').render(
                        email_context)

                # send the mail to new user
                send_email_to_id(subject,
                                 body=email_body,
                                 email_id=new_user,
                                 text_body=text_body)

            # These mails will be sent in both cases.
            subject = "user %s %s added in %s organisation" % (
                user.first_name, user.last_name, org.location.name)
            email_body = loader.get_template(
                'email_messages/organisation/member_addition_to_user.html'
            ).render(email_context)
            text_body = loader.get_template(
                'email_messages/organisation/member_addition_to_user.txt'
            ).render(email_context)

            # send mail to the user who added the new member
            send_email_to_id(subject,
                             body=email_body,
                             email_id=request.user.email,
                             text_body=text_body)

            regional_lead = Profile.objects.filter(
                interested_locations=org.location,
                usertype__slug='lead').values_list('user__email', flat=True)

            email_body = loader.get_template(
                'email_messages/organisation/member_addition_to_lead.html'
            ).render(email_context)
            text_body = loader.get_template(
                'email_messages/organisation/member_addition_to_lead.txt'
            ).render(email_context)

            # send mail to the regional leads
            send_email_to_list(subject,
                               body=email_body,
                               users_list=regional_lead,
                               text_body=text_body)

            return HttpResponseRedirect(self.success_url)

        else:
            return render(request, self.template_name, {'form': form})