#NEWLINE# def update_ticket( request , ticket_id , public = False ) : #NEWLINE# #INDENT# if ( not ( public or ( request . user . is_authenticated ( ) and request . user . is_active and ( request . user . is_staff or helpdesk_settings . HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE ) ) ) ) : #NEWLINE# #INDENT# return HttpResponseRedirect ( ( '%s?next=%s' % ( reverse ( 'login' ) , request . path ) ) ) #NEWLINE# #UNINDENT# ticket = get_object_or_404 ( Ticket , id = ticket_id ) #NEWLINE# comment = request . POST . get ( 'comment' , '' ) #NEWLINE# new_status = int ( request . POST . get ( 'new_status' , ticket . status ) ) #NEWLINE# title = request . POST . get ( 'title' , '' ) #NEWLINE# public = request . POST . get ( 'public' , False ) #NEWLINE# owner = int ( request . POST . get ( 'owner' , ( - 1 ) ) ) #NEWLINE# priority = int ( request . POST . get ( 'priority' , ticket . priority ) ) #NEWLINE# due_date_year = int ( request . POST . get ( 'due_date_year' , 0 ) ) #NEWLINE# due_date_month = int ( request . POST . get ( 'due_date_month' , 0 ) ) #NEWLINE# due_date_day = int ( request . POST . get ( 'due_date_day' , 0 ) ) #NEWLINE# if ( not ( due_date_year and due_date_month and due_date_day ) ) : #NEWLINE# #INDENT# due_date = ticket . due_date #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ticket . due_date : #NEWLINE# #INDENT# due_date = ticket . due_date #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# due_date = timezone . now ( ) #NEWLINE# #UNINDENT# due_date = due_date . replace ( due_date_year , due_date_month , due_date_day ) #NEWLINE# #UNINDENT# no_changes = all ( [ ( not request . FILES ) , ( not comment ) , ( new_status == ticket . status ) , ( title == ticket . title ) , ( priority == int ( ticket . priority ) ) , ( due_date == ticket . due_date ) , ( ( owner == ( - 1 ) ) or ( ( not owner ) and ( not ticket . assigned_to ) ) or ( owner and ( User . objects . get ( id = owner ) == ticket . assigned_to ) ) ) ] ) #NEWLINE# if no_changes : #NEWLINE# #INDENT# return return_to_ticket ( request . user , helpdesk_settings , ticket ) #NEWLINE# #UNINDENT# from django.template import loader , Context #NEWLINE# context = safe_template_context ( ticket ) #NEWLINE# try : #NEWLINE# #INDENT# from django.template import engines #NEWLINE# template_func = engines [ 'django' ] . from_string #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# template_func = loader . get_template_from_string #NEWLINE# #UNINDENT# if ( VERSION < ( 1 , 8 ) ) : #NEWLINE# #INDENT# context = Context ( context ) #NEWLINE# #UNINDENT# comment = template_func ( comment ) . render ( context ) #NEWLINE# if ( ( owner is ( - 1 ) ) and ticket . assigned_to ) : #NEWLINE# #INDENT# owner = ticket . assigned_to . id #NEWLINE# #UNINDENT# f = FollowUp ( ticket = ticket , date = timezone . now ( ) , comment = comment ) #NEWLINE# if ( request . user . is_staff or helpdesk_settings . HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE ) : #NEWLINE# #INDENT# f . user = request . user #NEWLINE# #UNINDENT# f . public = public #NEWLINE# reassigned = False #NEWLINE# if ( owner is not ( - 1 ) ) : #NEWLINE# #INDENT# if ( ( owner != 0 ) and ( ( ticket . assigned_to and ( owner != ticket . assigned_to . id ) ) or ( not ticket . assigned_to ) ) ) : #NEWLINE# #INDENT# new_user = User . objects . get ( id = owner ) #NEWLINE# f . title = ( _ ( 'Assigned to %(username)s' ) % { #NEWLINE# #INDENT# 'username' : new_user . get_username ( ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# ticket . assigned_to = new_user #NEWLINE# reassigned = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( owner == 0 ) and ( ticket . assigned_to is not None ) ) : #NEWLINE# #INDENT# f . title = _ ( 'Unassigned' ) #NEWLINE# ticket . assigned_to = None #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( new_status != ticket . status ) : #NEWLINE# #INDENT# ticket . status = new_status #NEWLINE# ticket . save ( ) #NEWLINE# f . new_status = new_status #NEWLINE# if f . title : #NEWLINE# #INDENT# f . title += ( ' and %s' % ticket . get_status_display ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# f . title = ( '%s' % ticket . get_status_display ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not f . title ) : #NEWLINE# #INDENT# if f . comment : #NEWLINE# #INDENT# f . title = _ ( 'Comment' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# f . title = _ ( 'Updated' ) #NEWLINE# #UNINDENT# #UNINDENT# f . save ( ) #NEWLINE# files = [ ] #NEWLINE# if request . FILES : #NEWLINE# #INDENT# import mimetypes , os #NEWLINE# for file in request . FILES . getlist ( 'attachment' ) : #NEWLINE# #INDENT# filename = file . name . encode ( 'ascii' , 'ignore' ) #NEWLINE# a = Attachment ( followup = f , filename = filename , mime_type = ( mimetypes . guess_type ( filename ) [ 0 ] or 'application/octet-stream' ) , size = file . size ) #NEWLINE# a . file . save ( filename , file , save = False ) #NEWLINE# a . save ( ) #NEWLINE# if ( file . size < getattr ( settings , 'MAX_EMAIL_ATTACHMENT_SIZE' , 512000 ) ) : #NEWLINE# #INDENT# files . append ( [ a . filename , a . file ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( title != ticket . title ) : #NEWLINE# #INDENT# c = TicketChange ( followup = f , field = _ ( 'Title' ) , old_value = ticket . title , new_value = title ) #NEWLINE# c . save ( ) #NEWLINE# ticket . title = title #NEWLINE# #UNINDENT# if ( priority != ticket . priority ) : #NEWLINE# #INDENT# c = TicketChange ( followup = f , field = _ ( 'Priority' ) , old_value = ticket . priority , new_value = priority ) #NEWLINE# c . save ( ) #NEWLINE# ticket . priority = priority #NEWLINE# #UNINDENT# if ( due_date != ticket . due_date ) : #NEWLINE# #INDENT# c = TicketChange ( followup = f , field = _ ( 'Due on' ) , old_value = ticket . due_date , new_value = due_date ) #NEWLINE# c . save ( ) #NEWLINE# ticket . due_date = due_date #NEWLINE# #UNINDENT# if ( new_status in [ Ticket . RESOLVED_STATUS , Ticket . CLOSED_STATUS ] ) : #NEWLINE# #INDENT# if ( ( new_status == Ticket . RESOLVED_STATUS ) or ( ticket . resolution is None ) ) : #NEWLINE# #INDENT# ticket . resolution = comment #NEWLINE# #UNINDENT# #UNINDENT# messages_sent_to = [ ] #NEWLINE# context = safe_template_context ( ticket ) #NEWLINE# context . update ( resolution = ticket . resolution , comment = f . comment ) #NEWLINE# if ( public and ( f . comment or ( f . new_status in ( Ticket . RESOLVED_STATUS , Ticket . CLOSED_STATUS ) ) ) ) : #NEWLINE# #INDENT# if ( f . new_status == Ticket . RESOLVED_STATUS ) : #NEWLINE# #INDENT# template = 'resolved_' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( f . new_status == Ticket . CLOSED_STATUS ) : #NEWLINE# #INDENT# template = 'closed_' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# template = 'updated_' #NEWLINE# #UNINDENT# #UNINDENT# template_suffix = 'submitter' #NEWLINE# if ticket . submitter_email : #NEWLINE# #INDENT# send_templated_mail ( ( template + template_suffix ) , context , recipients = ticket . submitter_email , sender = ticket . queue . from_address , fail_silently = True , files = files ) #NEWLINE# messages_sent_to . append ( ticket . submitter_email ) #NEWLINE# #UNINDENT# template_suffix = 'cc' #NEWLINE# for cc in ticket . ticketcc_set . all ( ) : #NEWLINE# #INDENT# if ( cc . email_address not in messages_sent_to ) : #NEWLINE# #INDENT# send_templated_mail ( ( template + template_suffix ) , context , recipients = cc . email_address , sender = ticket . queue . from_address , fail_silently = True , files = files ) #NEWLINE# messages_sent_to . append ( cc . email_address ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( ticket . assigned_to and ( request . user != ticket . assigned_to ) and ticket . assigned_to . email and ( ticket . assigned_to . email not in messages_sent_to ) ) : #NEWLINE# #INDENT# if reassigned : #NEWLINE# #INDENT# template_staff = 'assigned_owner' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( f . new_status == Ticket . RESOLVED_STATUS ) : #NEWLINE# #INDENT# template_staff = 'resolved_owner' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( f . new_status == Ticket . CLOSED_STATUS ) : #NEWLINE# #INDENT# template_staff = 'closed_owner' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# template_staff = 'updated_owner' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( ( ( not reassigned ) or ( reassigned and ticket . assigned_to . usersettings . settings . get ( 'email_on_ticket_assign' , False ) ) ) or ( ( not reassigned ) and ticket . assigned_to . usersettings . settings . get ( 'email_on_ticket_change' , False ) ) ) : #NEWLINE# #INDENT# send_templated_mail ( template_staff , context , recipients = ticket . assigned_to . email , sender = ticket . queue . from_address , fail_silently = True , files = files ) #NEWLINE# messages_sent_to . append ( ticket . assigned_to . email ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ticket . queue . updated_ticket_cc and ( ticket . queue . updated_ticket_cc not in messages_sent_to ) ) : #NEWLINE# #INDENT# if reassigned : #NEWLINE# #INDENT# template_cc = 'assigned_cc' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( f . new_status == Ticket . RESOLVED_STATUS ) : #NEWLINE# #INDENT# template_cc = 'resolved_cc' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( f . new_status == Ticket . CLOSED_STATUS ) : #NEWLINE# #INDENT# template_cc = 'closed_cc' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# template_cc = 'updated_cc' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# send_templated_mail ( template_cc , context , recipients = ticket . queue . updated_ticket_cc , sender = ticket . queue . from_address , fail_silently = True , files = files ) #NEWLINE# #UNINDENT# ticket . save ( ) #NEWLINE# if ( helpdesk_settings . HELPDESK_AUTO_SUBSCRIBE_ON_TICKET_RESPONSE and request . user . is_authenticated ( ) ) : #NEWLINE# #INDENT# ( ticketcc_string , SHOW_SUBSCRIBE ) = return_ticketccstring_and_show_subscribe ( request . user , ticket ) #NEWLINE# if SHOW_SUBSCRIBE : #NEWLINE# #INDENT# subscribe_staff_member_to_ticket ( ticket , request . user ) #NEWLINE# #UNINDENT# #UNINDENT# return return_to_ticket ( request . user , helpdesk_settings , ticket )