def email_caller_on_new_ticket(sender, instance, created, **kwargs): "When a new ticket is created send an email to the caller" if created: send_email_to_caller = False try: conf = ModuleSetting.get_for_module( 'anaf.services', 'send_email_to_caller')[0] send_email_to_caller = conf.value except: send_email_to_caller = settings.ANAF_SEND_EMAIL_TO_CALLER if send_email_to_caller: # don't send email to yourself creator_contact = None if instance.creator: creator_contact = instance.creator.get_contact() if instance.caller and instance.caller != creator_contact: if not instance.reference: if instance.queue: instance.reference = instance.queue.ticket_code + \ str(instance.id) else: instance.reference = str(instance.id) instance.save() subject = "[#{0!s}] {1!s}".format(instance.reference, instance.name) # Construct context and render to html, body context = {'ticket': instance} try: conf = ModuleSetting.get_for_module( 'anaf.services', 'send_email_template')[0] send_email_template = conf.value html = render_string_template(send_email_template, context) except: html = render_to_string( 'services/emails/notify_caller', context, response_format='html') body = strip_tags(html) if instance.queue and instance.queue.message_stream: stream = instance.queue.message_stream if stream.outgoing_server_name: try: caller_email = instance.caller.get_email() if caller_email: toaddr = caller_email ssl = False if stream.outgoing_server_type == 'SMTP-SSL': ssl = True email = BaseEmail(stream.outgoing_server_name, stream.outgoing_server_username, stream.outgoing_password, stream.outgoing_email, toaddr, subject, body, html=html, ssl=ssl) email.process_email() except: pass
def email_caller_on_new_ticket(sender, instance, created, **kwargs): "When a new ticket is created send an email to the caller" if created: send_email_to_caller = False try: conf = ModuleSetting.get_for_module('anaf.services', 'send_email_to_caller')[0] send_email_to_caller = conf.value except: send_email_to_caller = settings.ANAF_SEND_EMAIL_TO_CALLER if send_email_to_caller: # don't send email to yourself creator_contact = None if instance.creator: creator_contact = instance.creator.get_contact() if instance.caller and instance.caller != creator_contact: if not instance.reference: if instance.queue: instance.reference = instance.queue.ticket_code + \ str(instance.id) else: instance.reference = str(instance.id) instance.save() subject = "[#{0!s}] {1!s}".format(instance.reference, instance.name) # Construct context and render to html, body context = {'ticket': instance} try: conf = ModuleSetting.get_for_module( 'anaf.services', 'send_email_template')[0] send_email_template = conf.value html = render_string_template(send_email_template, context) except: html = render_to_string('services/emails/notify_caller', context, response_format='html') body = strip_tags(html) if instance.queue and instance.queue.message_stream: stream = instance.queue.message_stream if stream.outgoing_server_name: try: caller_email = instance.caller.get_email() if caller_email: toaddr = caller_email ssl = False if stream.outgoing_server_type == 'SMTP-SSL': ssl = True email = BaseEmail( stream.outgoing_server_name, stream.outgoing_server_username, stream.outgoing_password, stream.outgoing_email, toaddr, subject, body, html=html, ssl=ssl) email.process_email() except: pass
def settings_view(request, response_format='html'): "Settings" if not request.user.profile.is_admin('anaf.services'): return user_denied(request, message="You don't have administrator access to the Service Support module") # default ticket status try: conf = ModuleSetting.get_for_module( 'anaf.services', 'default_ticket_status')[0] default_ticket_status = TicketStatus.objects.get(pk=long(conf.value)) except Exception: default_ticket_status = None # default queue try: conf = ModuleSetting.get_for_module( 'anaf.services', 'default_ticket_queue')[0] default_ticket_queue = TicketQueue.objects.get(pk=long(conf.value)) except Exception: default_ticket_queue = None # notify ticket caller by email try: conf = ModuleSetting.get_for_module( 'anaf.services', 'send_email_to_caller')[0] send_email_to_caller = conf.value except Exception: send_email_to_caller = settings.ANAF_SEND_EMAIL_TO_CALLER # notification template send_email_example = '' try: conf = ModuleSetting.get_for_module( 'anaf.services', 'send_email_template')[0] send_email_template = conf.value except Exception: send_email_template = None queues = TicketQueue.objects.filter(trash=False, parent__isnull=True) statuses = TicketStatus.objects.filter(trash=False) if send_email_to_caller: # Render example e-mail try: ticket = Object.filter_by_request( request, Ticket.objects.filter(status__hidden=False, caller__isnull=False))[0] except IndexError: ticket = Ticket(reference='REF123', name='New request') if not ticket.caller: try: caller = Object.filter_by_request(request, Contact.objects)[0] except IndexError: caller = Contact(name='John Smith') ticket.caller = caller try: ticket.status except: try: ticket.status = statuses[0] except IndexError: ticket.status = TicketStatus(name='Open') if send_email_template: try: send_email_example = render_string_template( send_email_template, {'ticket': ticket}) except: send_email_example = render_to_string( 'services/emails/notify_caller', {'ticket': ticket}, response_format='html') else: send_email_example = render_to_string( 'services/emails/notify_caller', {'ticket': ticket}, response_format='html') context = _get_default_context(request) context.update({'settings_queues': queues, 'settings_statuses': statuses, 'default_ticket_status': default_ticket_status, 'default_ticket_queue': default_ticket_queue, 'send_email_to_caller': send_email_to_caller, 'send_email_example': send_email_example}) return render_to_response('services/settings_view', context, context_instance=RequestContext(request), response_format=response_format)
def settings_view(request, response_format='html'): "Settings" if not request.user.profile.is_admin('anaf.services'): return user_denied( request, message= "You don't have administrator access to the Service Support module" ) # default ticket status try: conf = ModuleSetting.get_for_module('anaf.services', 'default_ticket_status')[0] default_ticket_status = TicketStatus.objects.get(pk=long(conf.value)) except Exception: default_ticket_status = None # default queue try: conf = ModuleSetting.get_for_module('anaf.services', 'default_ticket_queue')[0] default_ticket_queue = TicketQueue.objects.get(pk=long(conf.value)) except Exception: default_ticket_queue = None # notify ticket caller by email try: conf = ModuleSetting.get_for_module('anaf.services', 'send_email_to_caller')[0] send_email_to_caller = conf.value except Exception: send_email_to_caller = settings.ANAF_SEND_EMAIL_TO_CALLER # notification template send_email_example = '' try: conf = ModuleSetting.get_for_module('anaf.services', 'send_email_template')[0] send_email_template = conf.value except Exception: send_email_template = None queues = TicketQueue.objects.filter(trash=False, parent__isnull=True) statuses = TicketStatus.objects.filter(trash=False) if send_email_to_caller: # Render example e-mail try: ticket = Object.filter_by_request( request, Ticket.objects.filter(status__hidden=False, caller__isnull=False))[0] except IndexError: ticket = Ticket(reference='REF123', name='New request') if not ticket.caller: try: caller = Object.filter_by_request(request, Contact.objects)[0] except IndexError: caller = Contact(name='John Smith') ticket.caller = caller try: ticket.status except: try: ticket.status = statuses[0] except IndexError: ticket.status = TicketStatus(name='Open') if send_email_template: try: send_email_example = render_string_template( send_email_template, {'ticket': ticket}) except: send_email_example = render_to_string( 'services/emails/notify_caller', {'ticket': ticket}, response_format='html') else: send_email_example = render_to_string( 'services/emails/notify_caller', {'ticket': ticket}, response_format='html') context = _get_default_context(request) context.update({ 'settings_queues': queues, 'settings_statuses': statuses, 'default_ticket_status': default_ticket_status, 'default_ticket_queue': default_ticket_queue, 'send_email_to_caller': send_email_to_caller, 'send_email_example': send_email_example }) return render_to_response('services/settings_view', context, context_instance=RequestContext(request), response_format=response_format)