forked from extern/django-helpdesk
Merge pull request #896 from Benbb96/enhance-ticketcc
Improvements in Ticketcc views and templates
This commit is contained in:
commit
b7070db718
@ -10,7 +10,7 @@ models.py - Model (and hence database) definitions. This is the core of the
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
@ -1666,6 +1666,10 @@ class TicketCC(models.Model):
|
||||
def __str__(self):
|
||||
return '%s for %s' % (self.display, self.ticket.title)
|
||||
|
||||
def clean(self):
|
||||
if self.user and not self.user.email:
|
||||
raise ValidationError('User has no email address')
|
||||
|
||||
|
||||
class CustomFieldManager(models.Manager):
|
||||
|
||||
|
@ -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 %}
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url 'helpdesk:list' %}">{% trans "Tickets" %}</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url 'helpdesk:list' %}{{ ticket.id }}/">{{ ticket.queue.slug }}-{{ ticket.id }}</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url 'helpdesk:ticket_cc' ticket.id %}">{% trans "CC Settings" %}</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item active">{% trans "Add CC" %}</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url 'helpdesk:list' %}">{% trans "Tickets" %}</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url 'helpdesk:list' %}{{ ticket.id }}/">{{ ticket.queue.slug }}-{{ ticket.id }}</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url 'helpdesk:ticket_cc' ticket.id %}">{% trans "CC Settings" %}</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item active">{% trans "Add CC" %}</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block helpdesk_body %}
|
||||
<h2>{% trans 'Add Ticket CC' %}</h2>
|
||||
<h2>{% trans 'Add Ticket CC' %}</h2>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<i class="fas fa-hand-pointer"></i>
|
||||
{% 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.' %}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<!-- Nav tabs -->
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="#EmailCC" data-toggle="tab">{% trans 'Email' %}</a>
|
||||
</li>
|
||||
<li><a href="#UserCC" data-toggle="tab">{% trans 'User' %}</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<i class="fas fa-hand-pointer"></i>
|
||||
{% 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.' %}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<!-- Nav tabs -->
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if not form.errors.user %} active{% endif %}" href="#EmailCC" data-toggle="tab">
|
||||
{% trans 'Email' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="divider"></li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if form.errors.user %} active{% endif %}" href="#UserCC" data-toggle="tab">
|
||||
{% trans 'User' %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane in active" id="EmailCC">
|
||||
<h4>{% trans 'Add Email' %}</h4>
|
||||
<form method='post' action='./'>
|
||||
<fieldset>
|
||||
<dl>{% for field in form_email %}
|
||||
<dt><label for='id_{{ field.name }}'>{{ field.label }}</label></dt>
|
||||
<dd>{{ field }}</dd>
|
||||
{% if field.errors %}<dd class='error'>{{ field.errors }}</dd>{% endif %}
|
||||
{% if field.help_text %}<dd class='form_help_text'>{{ field.help_text }}</dd>{% endif %}
|
||||
{% endfor %}</dl>
|
||||
</fieldset>
|
||||
<button class="btn btn-primary" type='submit'>{% trans "Save Ticket CC" %}</button>
|
||||
{% csrf_token %}</form>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="UserCC">
|
||||
<h4>{% trans 'Add User' %}</h4>
|
||||
<form method='post' action='./'>
|
||||
<fieldset>
|
||||
<dl>{% for field in form_user %}
|
||||
<dt><label for='id_{{ field.name }}'>{{ field.label }}</label></dt>
|
||||
<dd>{{ field }}</dd>
|
||||
{% if field.errors %}<dd class='error'>{{ field.errors }}</dd>{% endif %}
|
||||
{% if field.help_text %}<dd class='form_help_text'>{{ field.help_text }}</dd>{% endif %}
|
||||
{% endfor %}</dl>
|
||||
</fieldset>
|
||||
<button class="btn btn-primary" type='submit'>{% trans "Save Ticket CC" %}</button>
|
||||
{% csrf_token %}</form>
|
||||
{% if form.errors %}
|
||||
{% include 'helpdesk/include/alert_form_errors.html' %}
|
||||
<ul>{{ form.non_field_errors }}</ul>
|
||||
{% endif %}
|
||||
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane{% if not form.errors.user %} in active{% endif %}" id="EmailCC">
|
||||
<h4>{% trans 'Add Email' %}</h4>
|
||||
<form method='post'>
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
<dl>
|
||||
{% for field in form_email %}
|
||||
<dt>{{ field.label_tag }}</dt>
|
||||
<dd>{{ field }}</dd>
|
||||
{% if field.name == 'email' and form.errors.email %}
|
||||
<dd class='error'>{{ form.errors.email }}</dd>
|
||||
{% endif %}
|
||||
{% if field.help_text %}
|
||||
<dd class='form_help_text'>{{ field.help_text }}</dd>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</dl>
|
||||
</fieldset>
|
||||
<button class="btn btn-primary" type='submit'>{% trans "Save Ticket CC" %}</button>
|
||||
<a href="{% url 'helpdesk:ticket_cc' ticket.id %}" class="btn btn-secondary">
|
||||
{% trans "Cancel" %}
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
<div class="tab-pane{% if form.errors.user %} in active{% endif %}" id="UserCC">
|
||||
<h4>{% trans 'Add User' %}</h4>
|
||||
<form method='post'>
|
||||
{% csrf_token %}
|
||||
<fieldset>
|
||||
<dl>
|
||||
{% for field in form_user %}
|
||||
<dt>{{ field.label_tag }}</dt>
|
||||
<dd>{{ field }}</dd>
|
||||
{% if field.name == 'user' and form.errors.user %}
|
||||
<dd class='error'>{{ form.errors.user }}</dd>
|
||||
{% endif %}
|
||||
{% if field.help_text %}
|
||||
<dd class='form_help_text'>{{ field.help_text }}</dd>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</dl>
|
||||
</fieldset>
|
||||
<button class="btn btn-primary" type='submit'>{% trans "Save Ticket CC" %}</button>
|
||||
<a href="{% url 'helpdesk:ticket_cc' ticket.id %}" class="btn btn-secondary">
|
||||
{% trans "Cancel" %}
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.card-body -->
|
||||
</div>
|
||||
<!-- /.card-body -->
|
||||
</div>
|
||||
<!-- /.card -->
|
||||
|
||||
|
||||
<!-- /.card -->
|
||||
{% endblock %}
|
||||
|
@ -1,15 +1,17 @@
|
||||
{% extends "helpdesk/base.html" %}{% load i18n %}
|
||||
{% extends "helpdesk/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
{% block helpdesk_title %}{% trans "Ticket CC Settings" %}{% endblock %}
|
||||
|
||||
{% block helpdesk_breadcrumb %}
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url 'helpdesk:list' %}">{% trans "Tickets" %}</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url 'helpdesk:list' %}{{ ticket.id }}/">{{ ticket.queue.slug }}-{{ ticket.id }}</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item active">{% trans "CC Settings" %}</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url 'helpdesk:list' %}">{% trans "Tickets" %}</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="{% url 'helpdesk:list' %}{{ ticket.id }}/">{{ ticket.queue.slug }}-{{ ticket.id }}</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item active">{% trans "CC Settings" %}</li>
|
||||
{% endblock %}
|
||||
|
||||
{% block helpdesk_body %}{% blocktrans with ticket.title as ticket_title and ticket.id as ticket_id %}
|
||||
@ -19,47 +21,71 @@
|
||||
|
||||
<p>You can add a new recipient to the list or delete any of the items below as required.</p>{% endblocktrans %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
{% trans "Ticket CC List" %}
|
||||
</div>
|
||||
<!-- /.panel-heading -->
|
||||
<div class="panel-body">
|
||||
<div><a href='add/'><button class="btn btn-success btn-sm"><i class="fa fa-plus-circle"></i>{% trans "Add an Email or Helpdesk User" %}</button></a></div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "E-Mail Address or Helpdesk User" %}</th>
|
||||
<th>{% trans "View?" %}</th>
|
||||
<th>{% trans "Update?" %}</th>
|
||||
<th>{% trans "Delete" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for person in copies_to %}
|
||||
<tr class='row_{% cycle 'odd' 'even' %}'>
|
||||
<td>{{ person.display }}</td>
|
||||
<td>{{ person.can_view }}</td>
|
||||
<td>{{ person.can_update }}</td>
|
||||
<td><a href='{% url 'helpdesk:ticket_cc_del' ticket.id person.id %}'><button class="btn btn-danger btn-xs">{% trans "Delete" %}</button></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- /.table-responsive -->
|
||||
</div>
|
||||
<!-- /.panel-body -->
|
||||
</div>
|
||||
<!-- /.panel -->
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
{% trans "Ticket CC List" %}
|
||||
</div>
|
||||
<!-- /.col-lg-12 -->
|
||||
<!-- /.panel-heading -->
|
||||
<div class="panel-body">
|
||||
<div><a href='add/'><button class="btn btn-success btn-sm"><i class="fa fa-plus-circle"></i>{% trans "Add an Email or Helpdesk User" %}</button></a></div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "E-Mail Address or Helpdesk User" %}</th>
|
||||
<th class="text-center">{% trans "View?" %}</th>
|
||||
<th class="text-center">{% trans "Update?" %}</th>
|
||||
<th class="text-center">{% trans "Delete" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for person in copies_to %}
|
||||
<tr class='row_{% cycle 'odd' 'even' %}'>
|
||||
<td>{{ person.display }}</td>
|
||||
<td class="text-center">
|
||||
{% if person.can_view %}
|
||||
<i class="fa fa-2x fa-check text-success"></i>
|
||||
{% else %}
|
||||
<i class="fa fa-2x fa-times text-danger"></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="text-center">
|
||||
{% if person.can_update %}
|
||||
<i class="fa fa-2x fa-check text-success"></i>
|
||||
{% else %}
|
||||
<i class="fa fa-2x fa-times text-danger"></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<a href='{% url 'helpdesk:ticket_cc_del' ticket.id person.id %}'>
|
||||
<button class="btn btn-danger btn-xs">
|
||||
{% trans "Delete" %}
|
||||
</button>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- /.table-responsive -->
|
||||
</div>
|
||||
<!-- /.panel-body -->
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
<!-- /.panel -->
|
||||
</div>
|
||||
<!-- /.col-lg-12 -->
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
|
||||
<p><a href='{% url 'helpdesk:view' ticket.id %}'><button class="btn btn-primary btn-lg">{% blocktrans with ticket.title as ticket_title %}Return to <em>{{ ticket_title }}</em>{% endblocktrans %}</button></a></p>
|
||||
<p>
|
||||
<a href='{% url 'helpdesk:view' ticket.id %}'>
|
||||
<button class="btn btn-primary btn-lg">
|
||||
{% blocktrans with ticket.title as ticket_title %}Return to <em>{{ ticket_title }}</em>{% endblocktrans %}
|
||||
</button>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
{% endblock %}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user