Пример #1
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)
Пример #2
0
 def form_valid(self, form):
     response = super(WorkshopCreate, self).form_valid(form)
     workshop = self.object
     context = {
         'workshop': workshop,
         'date': workshop.expected_date,
         'workshop_url': self.request.build_absolute_uri(reverse(
             'workshops:workshop_detail', args=[workshop.pk]
         ))
     }
     send_tweet(context)
     self.send_mail_to_group(context)
     return response
Пример #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 form_valid(self, form):
     response = super(WorkshopCreate, self).form_valid(form)
     workshop = self.object
     context = {
         'workshop':
         workshop,
         'date':
         workshop.expected_date,
         'workshop_url':
         self.request.build_absolute_uri(
             reverse('workshops:workshop_detail', args=[workshop.pk]))
     }
     send_tweet(context)
     self.send_mail_to_group(context)
     return response