diff --git a/helpdesk/templates/helpdesk/ticket_cc_add.html b/helpdesk/templates/helpdesk/ticket_cc_add.html index 07ee9f0f..b3bffd17 100644 --- a/helpdesk/templates/helpdesk/ticket_cc_add.html +++ b/helpdesk/templates/helpdesk/ticket_cc_add.html @@ -1,72 +1,104 @@ -{% extends "helpdesk/base.html" %}{% load i18n %} +{% extends "helpdesk/base.html" %} + +{% load i18n %} {% block helpdesk_title %}{% trans "Add Ticket CC" %}{% endblock %} {% block helpdesk_breadcrumb %} - - - - + + + + {% endblock %} {% block helpdesk_body %} -

{% trans 'Add Ticket CC' %}

+

{% trans 'Add Ticket CC' %}

-
-
- - {% trans 'To automatically send an email to a user or e-mail address when this ticket is updated, select the user or enter an e-mail address below.' %} -
-
- - +
+
+ + {% trans 'To automatically send an email to a user or e-mail address when this ticket is updated, select the user or enter an e-mail address below.' %} +
+
+ + - -
-
-

{% trans 'Add Email' %}

-
-
-
{% for field in form_email %} -
-
{{ field }}
- {% if field.errors %}
{{ field.errors }}
{% endif %} - {% if field.help_text %}
{{ field.help_text }}
{% endif %} - {% endfor %}
-
- - {% csrf_token %}
-
-
-

{% trans 'Add User' %}

-
-
-
{% for field in form_user %} -
-
{{ field }}
- {% if field.errors %}
{{ field.errors }}
{% endif %} - {% if field.help_text %}
{{ field.help_text }}
{% endif %} - {% endfor %}
-
- - {% csrf_token %}
+ {% if form.errors %} + {% include 'helpdesk/include/alert_form_errors.html' %} +
    {{ form.non_field_errors }}
+ {% endif %} + + +
+
+

{% trans 'Add Email' %}

+
+ {% csrf_token %} +
+
+ {% for field in form_email %} +
{{ field.label_tag }}
+
{{ field }}
+ {% if field.name == 'email' and form.errors.email %} +
{{ form.errors.email }}
+ {% endif %} + {% if field.help_text %} +
{{ field.help_text }}
+ {% endif %} + {% endfor %} +
+
+ + + {% trans "Cancel" %} + +
+
+
+

{% trans 'Add User' %}

+
+ {% csrf_token %} +
+
+ {% for field in form_user %} +
{{ field.label_tag }}
+
{{ field }}
+ {% if field.name == 'user' and form.errors.user %} +
{{ form.errors.user }}
+ {% endif %} + {% if field.help_text %} +
{{ field.help_text }}
+ {% endif %} + {% endfor %} +
+
+ + + {% trans "Cancel" %} + +
+
+
- -
- - - + {% endblock %} diff --git a/helpdesk/templates/helpdesk/ticket_cc_list.html b/helpdesk/templates/helpdesk/ticket_cc_list.html index c186e08e..e959eb5a 100644 --- a/helpdesk/templates/helpdesk/ticket_cc_list.html +++ b/helpdesk/templates/helpdesk/ticket_cc_list.html @@ -1,65 +1,91 @@ -{% extends "helpdesk/base.html" %}{% load i18n %} +{% extends "helpdesk/base.html" %} + +{% load i18n %} {% block helpdesk_title %}{% trans "Ticket CC Settings" %}{% endblock %} {% block helpdesk_breadcrumb %} - - - + + + {% endblock %} {% block helpdesk_body %}{% blocktrans with ticket.title as ticket_title and ticket.id as ticket_id %} -

Ticket CC Settings

+

Ticket CC Settings

-

The following people will receive an e-mail whenever {{ ticket_title }} is updated. Some people can also view or edit the ticket via the public ticket views.

+

The following people will receive an e-mail whenever {{ ticket_title }} is updated. Some people can also view or edit the ticket via the public ticket views.

-

You can add a new recipient to the list or delete any of the items below as required.

{% endblocktrans %} +

You can add a new recipient to the list or delete any of the items below as required.

{% endblocktrans %} -
-
-
-
- {% trans "Ticket CC List" %} -
- -
- -
- - - - - - - - - - - {% for person in copies_to %} - - - - - - - {% endfor %} - -
{% trans "E-Mail Address or Helpdesk User" %}{% trans "View?" %}{% trans "Update?" %}{% trans "Delete" %}
{{ person.display }}{{ person.can_view }}{{ person.can_update }}
-
- -
- -
- +
+
+
+
+ {% trans "Ticket CC List" %}
- + +
+ +
+ + + + + + + + + + + {% for person in copies_to %} + + + + + + + {% endfor %} + +
{% trans "E-Mail Address or Helpdesk User" %}{% trans "View?" %}{% trans "Update?" %}{% trans "Delete" %}
{{ person.display }} + {% if person.can_view %} + + {% else %} + + {% endif %} + + {% if person.can_update %} + + {% else %} + + {% endif %} + + + + +
+
+ +
+
- + +
+ +
+ -

+

+ + + +

{% endblock %} diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index 9fa1b869..d24c109e 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -1508,21 +1508,27 @@ def ticket_cc_add(request, ticket_id): ticket = get_object_or_404(Ticket, id=ticket_id) ticket_perm_check(request, ticket) + form = None if request.method == 'POST': form = TicketCCForm(request.POST) if form.is_valid(): - ticketcc = form.save(commit=False) - ticketcc.ticket = ticket - ticketcc.save() - return HttpResponseRedirect(reverse('helpdesk:ticket_cc', - kwargs={'ticket_id': ticket.id})) - else: - form_email = TicketCCEmailForm() - form_user = TicketCCUserForm() + user = form.cleaned_data.get('user') + email = form.cleaned_data.get('email') + if user and ticket.ticketcc_set.filter(user=user).exists(): + form.add_error('user', _('Impossible to add twice the same user')) + elif email and ticket.ticketcc_set.filter(email=email).exists(): + form.add_error('email', _('Impossible to add twice the same email address')) + else: + ticketcc = form.save(commit=False) + ticketcc.ticket = ticket + ticketcc.save() + return HttpResponseRedirect(reverse('helpdesk:ticket_cc', kwargs={'ticket_id': ticket.id})) + return render(request, 'helpdesk/ticket_cc_add.html', { 'ticket': ticket, - 'form_email': form_email, - 'form_user': form_user, + 'form': form, + 'form_email': TicketCCEmailForm(), + 'form_user': TicketCCUserForm(), }) @@ -1531,13 +1537,14 @@ ticket_cc_add = staff_member_required(ticket_cc_add) @helpdesk_staff_member_required def ticket_cc_del(request, ticket_id, cc_id): + ticket = get_object_or_404(Ticket, id=ticket_id) cc = get_object_or_404(TicketCC, ticket__id=ticket_id, id=cc_id) if request.method == 'POST': cc.delete() - return HttpResponseRedirect(reverse('helpdesk:ticket_cc', - kwargs={'ticket_id': cc.ticket.id})) - return render(request, 'helpdesk/ticket_cc_del.html', {'cc': cc}) + return HttpResponseRedirect(reverse('helpdesk:ticket_cc', kwargs={'ticket_id': cc.ticket.id})) + + return render(request, 'helpdesk/ticket_cc_del.html', {'ticket': ticket, 'cc': cc}) ticket_cc_del = staff_member_required(ticket_cc_del)