Ejemplo n.º 1
0
def external_add(request):
    """
    Allow users who don't have access to the rest of the ticket system to file a ticket in a specific list.
    This is useful if, for example, a core web team are in a group that can file todos for each other,
    but you also want students to be able to post trouble tickets to a list just for the sysadmin. This
    way we don't have to put all students into a group that gives them access to the whole ticket system.
    """
    if request.POST:
            form = AddExternalItemForm(request.POST)

            if form.is_valid():
                # Don't commit the save until we've added in the fields we need to set
                item = form.save(commit=False)
                item.list_id = 20 # Hate hard-coding in IDs like this.
                item.created_by = request.user
                item.assigned_to = User.objects.get(username='******')
                item.save()
                
                # Send email
                email_subject = render_to_string("todo/email/assigned_subject.txt", { 'task': item.title })                    
                email_body = render_to_string("todo/email/assigned_body.txt", { 'task': item, 'site': current_site, })
                try:
                    send_mail(email_subject, email_body, item.created_by.email, [item.assigned_to.email], fail_silently=False)
                except:
                    request.user.message_set.create(message="Task saved but mail not sent. Contact your administrator." )                

                request.user.message_set.create(message="Your trouble ticket has been submitted. We'll get back to you soon.")
                return HttpResponseRedirect(reverse('intranet_home'))
            
        
    else:
        form = AddExternalItemForm()

    return render_to_response('todo/add_external_task.html', locals(), context_instance=RequestContext(request))
Ejemplo n.º 2
0
def external_add(request):
    """
    Allow users who don't have access to the rest of the ticket system to file a ticket in a specific list.
    Public tickets are unassigned unless settings.DEFAULT_ASSIGNEE exists.
    """
    if request.POST:
        form = AddExternalItemForm(request.POST)

        if form.is_valid():
            item = form.save(commit=False)
            item.list_id = settings.DEFAULT_LIST_ID
            item.created_by = request.user
            if settings.DEFAULT_ASSIGNEE:
                item.assigned_to = User.objects.get(username=settings.DEFAULT_ASSIGNEE)
            item.save()

            email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': item.title})
            email_body = render_to_string("todo/email/assigned_body.txt", {'task': item, 'site': current_site, })
            try:
                send_mail(
                    email_subject, email_body, item.created_by.email, [item.assigned_to.email, ], fail_silently=False)
            except:
                messages.error(request, "Task saved but mail not sent. Contact your administrator.")

            messages.success(request, "Your trouble ticket has been submitted. We'll get back to you soon.")

            return HttpResponseRedirect(settings.PUBLIC_SUBMIT_REDIRECT)
    else:
        form = AddExternalItemForm()

    return render(request, 'todo/add_external_task.html', locals())
Ejemplo n.º 3
0
def external_add(request):
    """
    Allow users who don't have access to the rest of the ticket system to file a ticket in a specific list.
    This is useful if, for example, a core web team are in a group that can file todos for each other,
    but you also want students to be able to post trouble tickets to a list just for the sysadmin. This
    way we don't have to put all users into a group that gives them access to the whole ticket system.
    """
    if request.POST:
        form = AddExternalItemForm(request.POST)

        if form.is_valid():
            item = form.save(commit=False)
            item.list_id = settings.DEFAULT_LIST_ID
            item.created_by = request.user
            item.assigned_to = User.objects.get(username=settings.DEFAULT_ASSIGNEE)
            item.save()

            email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': item.title})
            email_body = render_to_string("todo/email/assigned_body.txt", {'task': item, 'site': current_site, })
            try:
                send_mail(
                    email_subject, email_body, item.created_by.email, [item.assigned_to.email, ], fail_silently=False)
            except:
                messages.error(request, "Task saved but mail not sent. Contact your administrator.")

            messages.success(request, "Your trouble ticket has been submitted. We'll get back to you soon.")

            return HttpResponseRedirect(settings.PUBLIC_SUBMIT_REDIRECT)
    else:
        form = AddExternalItemForm()

    return render(request, 'todo/add_external_task.html', locals())
Ejemplo n.º 4
0
def external_add(request):
    """
    Allow users who don't have access to the rest of the ticket system to file a ticket in a specific list.
    This is useful if, for example, a core web team are in a group that can file todos for each other,
    but you also want students to be able to post trouble tickets to a list just for the sysadmin. This
    way we don't have to put all users into a group that gives them access to the whole ticket system.
    """
    if request.POST:
        form = AddExternalItemForm(request.POST)

        if form.is_valid():
            # Don't commit the save until we've added in the fields we need to set
            item = form.save(commit=False)
            item.list_id = settings.DEFAULT_LIST_ID
            item.created_by = request.user
            item.assigned_to = User.objects.get(username=settings.DEFAULT_ASSIGNEE)
            item.save()

            # Send email
            email_subject = render_to_string("todo/email/assigned_subject.txt", {'task': item.title})
            email_body = render_to_string("todo/email/assigned_body.txt", {'task': item, 'site': current_site, })
            try:
                send_mail(email_subject, email_body, item.created_by.email, [item.assigned_to.email],
                          fail_silently=False)
            except:
                messages.error(request, "Task saved but mail not sent. Contact your administrator.")

            messages.success(request, "Your trouble ticket has been submitted. We'll get back to you soon.")

            return HttpResponseRedirect(settings.PUBLIC_SUBMIT_REDIRECT)
    else:
        form = AddExternalItemForm()

    return render_to_response('todo/add_external_task.html', locals(), context_instance=RequestContext(request))
Ejemplo n.º 5
0
def external_add(request):
    """
    Allow users who don't have access to the rest of the ticket system to file a ticket in a specific list.
    Public tickets are unassigned unless settings.DEFAULT_ASSIGNEE exists.
    """
    if request.POST:
        form = AddExternalItemForm(request.POST)

        if form.is_valid():
            item = form.save(commit=False)
            item.list_id = settings.DEFAULT_LIST_ID
            item.created_by = request.user
            if settings.DEFAULT_ASSIGNEE:
                item.assigned_to = User.objects.get(
                    username=settings.DEFAULT_ASSIGNEE)
            item.save()

            email_subject = render_to_string("todo/email/assigned_subject.txt",
                                             {'task': item.title})
            email_body = render_to_string("todo/email/assigned_body.txt", {
                'task': item,
                'site': current_site,
            })
            try:
                send_mail(email_subject,
                          email_body,
                          item.created_by.email, [
                              item.assigned_to.email,
                          ],
                          fail_silently=False)
            except:
                messages.error(
                    request,
                    "Задача збережена але електронний лист не відправлено. Повідомте про проблему адміністтратора."
                )

            messages.success(
                request,
                "Your trouble ticket has been submitted. We'll get back to you soon."
            )

            return HttpResponseRedirect(settings.PUBLIC_SUBMIT_REDIRECT)
    else:
        form = AddExternalItemForm()

    return render(request, 'todo/add_external_task.html', locals())