Skip to content

Commit

Permalink
ticket competence transfer refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Oct 16, 2020
1 parent 503011b commit ec4b2d1
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 59 deletions.
Binary file modified .coverage
Binary file not shown.
8 changes: 5 additions & 3 deletions organizational_area/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ class OrganizationalStructureAdmin(AbstractAdmin):
@admin.register(OrganizationalStructureOffice)
class OrganizationalStructureOfficeAdmin(AbstractAdmin):
prepopulated_fields = {'slug': ('name',)}
list_display = ('name', 'organizational_structure', 'is_active')
list_display = ('name', 'organizational_structure',
'is_default', 'is_private', 'is_active')

list_filter = ('organizational_structure',
'is_active')
'is_active',
'is_private')

list_editable = ('is_active',)
list_editable = ('is_active', 'is_private')

inlines = [OrganizationalStructureOfficeEmployeeInline,
OrganizationalStructureOfficeLocationInline,]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.2 on 2020-10-16 07:14

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('organizational_area', '0031_auto_20200702_1126'),
]

operations = [
migrations.AddField(
model_name='organizationalstructureoffice',
name='is_private',
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions organizational_area/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class OrganizationalStructureOffice(models.Model):
on_delete=models.CASCADE)
description = models.TextField(max_length=1024, null=True,blank=True)
is_default = models.BooleanField(default=False)
is_private = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)

class Meta:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_04_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ def test_add_ticket_competence_and_manage(self):
self.ticket.refresh_from_db()
assert response.status_code == 200

# Assign ticket to Category_3 (Structure 2)
# Assign ticket to Office (Structure 2)
# Follow and continue to manage ticket (staff_1, manager of Structure 1)
params = {'category_slug': self.category_1_str_2.slug,
params = {'office_slug': self.office_1_str_2.slug,
'follow': 'on',
# 'readonly': False,
}
Expand Down Expand Up @@ -290,7 +290,7 @@ def test_add_ticket_competence_and_readonly(self):

# Assign ticket to Category_3 (Structure 2)
# Follow and continue to manage ticket (staff_1, manager of Structure 1)
params = {'category_slug': self.category_1_str_2.slug,
params = {'office_slug': self.office_1_str_2.slug,
'follow': 'on',
'readonly': True,
}
Expand Down
14 changes: 10 additions & 4 deletions uni_ticket/admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from django.utils import timezone
from django.utils.html import strip_tags

from django_form_builder.utils import format_field_name

from . models import *


Expand All @@ -29,6 +31,7 @@ def _download_report_csv(modeladmin,

delimiter='$'
quotechar='"'
dialect='excel'

for cat in queryset:

Expand All @@ -39,21 +42,23 @@ def _download_report_csv(modeladmin,

file_name = "{}_MOD_{}_{}.csv".format(cat.name.replace('/','_'),
module.name.replace('/','_'),
module.created.strftime('%d-%m-%Y'))
module.created.strftime('%d-%m-%Y_%H-%M-%S'))

head = ['created',
'user',
'status',
'subject',
'description']

custom_head = []
fields = TicketCategoryInputList.objects.filter(category_module=module)
for field in fields:
custom_head.append(field.name)
head.append(field.name)

csv_file = HttpResponse(content_type='text/csv')
csv_file['Content-Disposition'] = 'attachment; filename="{}"'.format(file_name)
writer = csv.writer(csv_file,
dialect=dialect,
delimiter = delimiter,
quotechar = quotechar)

Expand All @@ -71,8 +76,9 @@ def _download_report_csv(modeladmin,
status,
richiesta.subject,
richiesta.description]
for k,v in content.items():
row.append(v)
# for k,v in content.items():
for column in custom_head:
row.append(content.get(format_field_name(column), ''))
writer.writerow(row)
f.writestr(file_name,
csv_file.content)
Expand Down
11 changes: 8 additions & 3 deletions uni_ticket/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,13 @@ class OfficeForm(ModelForm):
"""
class Meta:
model = OrganizationalStructureOffice
fields = ['name', 'description']
fields = ['name', 'description', 'is_private']
labels = {'name': _('Nome'),
'description': _('Descrizione'),}
'description': _('Descrizione'),
'is_private': _('Ad uso interno')}
help_texts = {'is_private': _("Visibile esclusivamente all'interno "
"della struttura quando si effettua "
"un trasferimento di competenza")}
widgets = {'description': forms.Textarea(attrs={'rows':2})}

class Media:
Expand Down Expand Up @@ -284,7 +288,8 @@ class TicketCompetenceSchemeForm(forms.Form):
(rendered manually to have js behaviour)
"""
# structure_slug = forms.CharField(label=_('Struttura'), required=True)
category_slug = forms.CharField(label=_('Categoria'), required=True)
# category_slug = forms.CharField(label=_('Categoria'), required=True)
office_slug = forms.CharField(label=_('Ufficio'), required=True)
follow = forms.BooleanField(label=_('Continua a seguire'), required=False)
readonly = forms.BooleanField(label=_('Sola lettura'), required=False)
selected_office = forms.CharField(label=_('Ufficio selezionato'), required=False)
Expand Down
63 changes: 26 additions & 37 deletions uni_ticket/views/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,26 +900,33 @@ def ticket_competence_add_final(request, structure_slug, ticket_id,
new_structure = get_object_or_404(OrganizationalStructure,
slug=new_structure_slug,
is_active=True)
categorie = TicketCategory.objects.filter(organizational_structure=new_structure.pk,
is_active=True)
offices = OrganizationalStructureOffice.objects.filter(organizational_structure=new_structure,
is_active=True)

# exclude private offices if not in same structure
if new_structure != structure:
offices = offices.exclude(is_private=True)

if request.method == 'POST':
form = TicketCompetenceSchemeForm(data=request.POST)
if form.is_valid():
category_slug = form.cleaned_data['category_slug']
office_slug = form.cleaned_data['office_slug']
follow = form.cleaned_data['follow']
readonly = form.cleaned_data['readonly']
selected_office_slug = form.cleaned_data['selected_office']
# Refactor
# follow_value = form.cleaned_data['follow']
# readonly_value = form.cleaned_data['readonly']
# follow = True if follow_value == 'on' else False
# readonly = True if readonly_value == 'on' else False

# La categoria passata in POST esiste?
categoria = get_object_or_404(TicketCategory,
slug=category_slug,
organizational_structure=new_structure,
is_active=True)

# L'ufficio passato in POST esiste?
new_office = get_object_or_404(OrganizationalStructureOffice,
slug=office_slug,
organizational_structure=new_structure,
is_active=True)

# se viene forzato il POST con un ufficio privato!
if new_structure != structure and new_office.is_private:
return custom_message(request,
_("Impossibile assegnare la richiesta "
"all'ufficio selezionato"),
structure_slug=structure.slug)

selected_office = None
if selected_office_slug:
Expand All @@ -928,28 +935,11 @@ def ticket_competence_add_final(request, structure_slug, ticket_id,
organizational_structure=structure,
is_active=True)

# Se alla categoria non è associato alcun ufficio,
# all'utente viene mostrato il messaggio di errore
# Perchè l'ufficio speciale Help-Desk è già competente sul ticket
if not categoria.organizational_office:
messages.add_message(request, messages.ERROR,
_("La richiesta è già di competenza"
" dell'ufficio speciale <b>{}</b>,"
" responsabile della tipologia di richiesta "
"<b>{}</b>").format(settings.DEFAULT_ORGANIZATIONAL_STRUCTURE_OFFICE,
categoria))
return redirect('uni_ticket:manage_ticket_url_detail',
structure_slug=structure_slug,
ticket_id=ticket_id)

new_office = categoria.organizational_office

if new_office in ticket_offices:
messages.add_message(request, messages.ERROR,
_("La richiesta è già di competenza"
" dell'ufficio <b>{}</b>, responsabile"
" della tipologia di richiesta <b>{}</b>"
"").format(new_office, categoria))
" dell'ufficio <b>{}</b>"
"").format(new_office))
return redirect('uni_ticket:manage_ticket_url_detail',
structure_slug=structure_slug,
ticket_id=ticket_id)
Expand Down Expand Up @@ -995,9 +985,8 @@ def ticket_competence_add_final(request, structure_slug, ticket_id,
user=request.user)
ticket.update_log(user=request.user,
note= _("Nuova competenza: {} - {}"
" - Categoria: {}".format(new_structure,
new_office,
categoria)))
"").format(new_structure,
new_office))

# log action
logger.info('[{}] {} added new competence to'
Expand All @@ -1020,7 +1009,7 @@ def ticket_competence_add_final(request, structure_slug, ticket_id,
title = _('Trasferisci competenza richiesta')
sub_title = '{} ({})'.format(ticket.subject, ticket_id)
d = {'can_manage': can_manage,
'categorie': categorie,
'offices': offices,
'operator_offices': operator_offices_list,
'structure': structure,
'structure_slug': new_structure_slug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% endblock top_buttons %}

{% block page_content %}
{% if categorie %}
{% if offices %}
<form method="post" enctype="multipart/form-data">
{% endif %}

Expand All @@ -38,14 +38,14 @@
</div>

<div style="padding: 1.5rem 0 1rem">
<b><label for="category_slug">{% trans "Categoria" %}</label></b>
<b><label for="office_slug">{% trans "Ufficio" %}</label></b>
{% if not structure_slug %}
<div class="alert alert-warning" role="alert">
{% trans "Seleziona la struttura a cui inoltrare la richiesta" %}
{% trans "Seleziona l'ufficio a cui inoltrare la richiesta" %}
</div>
{% elif not categorie %}
{% elif not offices %}
<div class="alert alert-danger" role="alert">
{% trans "Nessuna tipologia di richiesta disponibile per questa struttura" %}
{% trans "Nessun ufficio disponibile per questa struttura" %}
</div>
{% else %}
{% comment %}
Expand All @@ -55,12 +55,12 @@
<div class="bootstrap-select-wrapper">
<select required
{% if not structure_slug %}disabled{% endif %}
name="category_slug"
name="office_slug"
title="{% trans 'A chi è indirizzata la richiesta?' %}"
data-live-search="true">
<option value="">{% trans "Seleziona un'opzione" %}</option>
{% for categoria in categorie %}
<option value="{{ categoria.slug }}">{{ categoria }}</option>
{% for office in offices %}
<option value="{{ office.slug }}">{{ office.name }}</option>
{% endfor %}
</select>
</div>
Expand Down Expand Up @@ -95,7 +95,7 @@
{% endif %}
</div>

{% if categorie %}
{% if offices %}

<div style="padding: 0 0 1.5rem">
<b>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@
{% else %}-{% endif %}
</td>
</tr>
<tr>
<th scope="row">{% trans 'Ad uso interno' %}</th>
<td>
<svg class="icon icon-sm icon-secondary">
{% if office.is_private %}
<use xlink:href="{% static 'svg/sprite.svg' %}#it-check"></use>
{% else %}
<use xlink:href="{% static 'svg/sprite.svg' %}#it-close"></use>
{% endif %}
</svg>
</td>
</tr>
<tr>
<th scope="row">{% trans 'Tipologie di competenza' %}</th>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ <h5 class="card-title">{{ office.name }}</h5>
<b>{% trans 'Operatori' %}:</b>
{{ office.organizationalstructureofficeemployee_set.all|length }}
<br>
<b>{% trans 'Ad uso interno' %}:</b>
<svg class="icon icon-sm icon-secondary">
{% if office.is_private %}
<use xlink:href="{% static 'svg/sprite.svg' %}#it-check"></use>
{% else %}
<use xlink:href="{% static 'svg/sprite.svg' %}#it-close"></use>
{% endif %}
</svg>
<br>
<b>{% trans 'Richieste assegnate' %}:</b>
{{ office.ticketassignment_set.all|length }}
<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ <h5 class="card-title">{{ office.name }}</h5>
<p class="card-text">
<b>{% trans 'Operatori' %}:</b>
{{ office.organizationalstructureofficeemployee_set.all|length }}
<br>
<b>{% trans 'Ad uso interno' %}:</b>
<svg class="icon icon-sm icon-secondary">
{% if office.is_private %}
<use xlink:href="{% static 'svg/sprite.svg' %}#it-check"></use>
{% else %}
<use xlink:href="{% static 'svg/sprite.svg' %}#it-close"></use>
{% endif %}
</svg>
<br>
<b>{% trans 'Categorie di competenza' %}:</b>
{% if office.ticketcategory_set.all %}
Expand Down

0 comments on commit ec4b2d1

Please sign in to comment.