Revert changes, updating objects missed somewhere

This commit is contained in:
Martin Whitehouse 2022-07-25 04:15:53 +02:00
parent a248181857
commit 40a243c23b
No known key found for this signature in database
GPG Key ID: 3FCE1D3E9DEC09C1

View File

@ -989,7 +989,7 @@ mass_update = staff_member_required(mass_update)
# Prepare ticket attributes which will be displayed in the table to choose # Prepare ticket attributes which will be displayed in the table to choose
# which value to keep when merging # which value to keep when merging
TICKET_ATTRIBUTES = ( ticket_attributes = (
('created', _('Created date')), ('created', _('Created date')),
('due_date', _('Due on')), ('due_date', _('Due on')),
('get_status_display', _('Status')), ('get_status_display', _('Status')),
@ -1008,7 +1008,7 @@ def merge_ticket_values(
for ticket in tickets: for ticket in tickets:
ticket.values = {} ticket.values = {}
# Prepare the value for each attributes of this ticket # Prepare the value for each attributes of this ticket
for attribute, __ in TICKET_ATTRIBUTES: for attribute, __ in ticket_attributes:
value = getattr(ticket, attribute, TicketCustomFieldValue.default_value) value = getattr(ticket, attribute, TicketCustomFieldValue.default_value)
# Check if attr is a get_FIELD_display # Check if attr is a get_FIELD_display
if attribute.startswith('get_') and attribute.endswith('_display'): if attribute.startswith('get_') and attribute.endswith('_display'):
@ -1031,14 +1031,37 @@ def merge_ticket_values(
} }
def redirect_from_chosen_ticket( @staff_member_required
request, def merge_tickets(request):
chosen_ticket, """
tickets, An intermediate view to merge up to 3 tickets in one main ticket.
custom_fields The user has to first select which ticket will receive the other tickets information and can also choose which
) -> HttpResponseRedirect: data to keep per attributes as well as custom fields.
Follow-ups and ticketCC will be moved to the main ticket and other tickets won't be able to receive new answers.
"""
ticket_select_form = MultipleTicketSelectForm(request.GET or None)
tickets = custom_fields = None
if ticket_select_form.is_valid():
tickets = ticket_select_form.cleaned_data.get('tickets')
custom_fields = CustomField.objects.all()
merge_ticket_values(request, tickets, custom_fields)
if request.method == 'POST':
# Find which ticket has been chosen to be the main one
try:
chosen_ticket = tickets.get(
id=request.POST.get('chosen_ticket'))
except Ticket.DoesNotExist:
ticket_select_form.add_error(
field='tickets',
error=_(
'Please choose a ticket in which the others will be merged into.')
)
else:
# Save ticket fields values # Save ticket fields values
for attribute, __ in TICKET_ATTRIBUTES: for attribute, __ in ticket_attributes:
id_for_attribute = request.POST.get(attribute) id_for_attribute = request.POST.get(attribute)
if id_for_attribute != chosen_ticket.id: if id_for_attribute != chosen_ticket.id:
try: try:
@ -1126,46 +1149,9 @@ def redirect_from_chosen_ticket(
ticketcc=ticketcc) ticketcc=ticketcc)
return redirect(chosen_ticket) return redirect(chosen_ticket)
@staff_member_required
def merge_tickets(request):
"""
An intermediate view to merge up to 3 tickets in one main ticket.
The user has to first select which ticket will receive the other tickets information and can also choose which
data to keep per attributes as well as custom fields.
Follow-ups and ticketCC will be moved to the main ticket and other tickets won't be able to receive new answers.
"""
ticket_select_form = MultipleTicketSelectForm(request.GET or None)
tickets = custom_fields = None
if ticket_select_form.is_valid():
tickets = ticket_select_form.cleaned_data.get('tickets')
custom_fields = CustomField.objects.all()
merge_ticket_values(request, tickets, custom_fields)
if request.method == 'POST':
# Find which ticket has been chosen to be the main one
try:
chosen_ticket = tickets.get(
id=request.POST.get('chosen_ticket'))
except Ticket.DoesNotExist:
ticket_select_form.add_error(
field='tickets',
error=_(
'Please choose a ticket in which the others will be merged into.')
)
else:
return redirect_from_chosen_ticket(
request,
chosen_ticket,
tickets,
custom_fields
)
return render(request, 'helpdesk/ticket_merge.html', { return render(request, 'helpdesk/ticket_merge.html', {
'tickets': tickets, 'tickets': tickets,
'TICKET_ATTRIBUTES': TICKET_ATTRIBUTES, 'ticket_attributes': ticket_attributes,
'custom_fields': custom_fields, 'custom_fields': custom_fields,
'ticket_select_form': ticket_select_form 'ticket_select_form': ticket_select_form
}) })