Skip to content

Commit

Permalink
messages in dashboard refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Oct 15, 2020
1 parent f17fcc6 commit 503011b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 34 deletions.
15 changes: 8 additions & 7 deletions organizational_area/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,20 @@ class Meta:
verbose_name = _("Organizational Structure Office Employee")
verbose_name_plural = _("Organizational Structure Office Employees")

@classmethod
def get_default_operator_or_manager(cls, office):
@staticmethod
def get_default_operator_or_manager(office):
"""
Returns an use randomly.
Try to get an office employee if exists.
Else returns one of managers.
"""
office_employees = cls.objects.filter(office=office,
employee__is_active=True).order_by('?')
osoe = OrganizationalStructureOfficeEmployee
office_employees = osoe.objects.filter(office=office,
employee__is_active=True).order_by('?')
if not office_employees:
office_employees = cls.objects.filter(office__name=settings.DEFAULT_ORGANIZATIONAL_STRUCTURE_OFFICE,
office__organizational_structure=office.organizational_structure,
employee__is_active=True).order_by('?')
office_employees = osoe.objects.filter(office__name=settings.DEFAULT_ORGANIZATIONAL_STRUCTURE_OFFICE,
office__organizational_structure=office.organizational_structure,
employee__is_active=True).order_by('?')
random_office_operator = office_employees.first()
return random_office_operator.employee

Expand Down
25 changes: 18 additions & 7 deletions uni_ticket/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,16 @@ class Meta:
verbose_name = _("Domande/Risposte Ticket")
verbose_name_plural = _("Domande/Risposte Ticket")

@staticmethod
def get_unread_messages_count(tickets, by_operator=False):
unread_messages = TicketReply.objects.filter(ticket__in=tickets,
read_date=None)
# show messages sent by operator
if by_operator:
return unread_messages.exclude(structure=None).count()
# show messages sent by user
return unread_messages.filter(structure=None).count()

def get_folder(self):
"""
Returns ticket attachments folder path
Expand Down Expand Up @@ -973,11 +983,11 @@ class Meta:
verbose_name = _("Dipendenza Ticket")
verbose_name_plural = _("Dipendenze Ticket")

@classmethod
def main_is_already_used(cls, ticket):
@staticmethod
def main_is_already_used(ticket):
"""
"""
relations = cls.objects.filter(subordinate_ticket=ticket)
relations = Ticket2Ticket.objects.filter(subordinate_ticket=ticket)
if not relations: return False
for relation in relations:
main = relation.main_ticket
Expand Down Expand Up @@ -1230,10 +1240,11 @@ def disable_other_configurations(self):
other.is_active = False
other.save(update_fields = ['is_active', 'modified'])

@classmethod
def get_active_protocol_configuration(cls, organizational_structure):
conf = cls.objects.filter(organizational_structure=organizational_structure,
is_active=True).first()
@staticmethod
def get_active_protocol_configuration(organizational_structure):
oswsap = OrganizationalStructureWSArchiPro
conf = oswsap.objects.filter(organizational_structure=organizational_structure,
is_active=True).first()
return conf if conf else False

def __str__(self):
Expand Down
12 changes: 4 additions & 8 deletions uni_ticket/views/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,16 @@ def dashboard(request, structure_slug, structure):
cm = TicketCategory
categories = cm.objects.filter(organizational_structure=structure)

messages = 0
for ticket in tickets:
# if not ticket.is_followed_in_structure(structure=structure):
# continue
messages += ticket.get_messages_count()[1]

d = {'ticket_messages': messages,
'categories': categories,
messages = TicketReply.get_unread_messages_count(tickets=tickets)

d = {'categories': categories,
'offices': offices,
'structure': structure,
'sub_title': sub_title,
'ticket_aperti': opened,
'ticket_assegnati_a_me': my_opened,
'ticket_chiusi': chiusi,
'ticket_messages': messages,
'ticket_non_gestiti': unassigned,
'title': title,}
return render(request, template, d)
Expand Down
11 changes: 4 additions & 7 deletions uni_ticket/views/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,16 @@ def dashboard(request, structure_slug, structure, office_employee):
unassigned += 1
# chiusi = tickets.filter(is_closed=True)
chiusi = tickets.filter(is_closed=True).count()
messages = 0
for ticket in tickets:
# if not ticket.is_followed_by_one_of_offices(offices):
# continue
messages += ticket.get_messages_count()[1]

d = {'ticket_messages': messages,
'offices': offices,
messages = TicketReply.get_unread_messages_count(tickets=tickets)

d = {'offices': offices,
'structure': structure,
'sub_title': sub_title,
'title': title,
'ticket_aperti': opened,
'ticket_assegnati_a_me': my_opened,
'ticket_chiusi': chiusi,
'ticket_messages': messages,
'ticket_non_gestiti': unassigned,}
return render(request, template, d)
9 changes: 4 additions & 5 deletions uni_ticket/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,15 +636,14 @@ def dashboard(request):
# chiusi = tickets.filter(is_closed=True)
chiusi = tickets.filter(is_closed=True).count()

messages = 0
for ticket in tickets:
messages += ticket.get_messages_count(by_operator=True)[1]
messages = TicketReply.get_unread_messages_count(tickets=tickets,
by_operator=True)

d = {'ticket_messages': messages,
'priority_levels': settings.PRIORITY_LEVELS,
d = {'priority_levels': settings.PRIORITY_LEVELS,
'sub_title': sub_title,
'ticket_aperti': opened,
'ticket_chiusi': chiusi,
'ticket_messages': messages,
'ticket_non_gestiti': unassigned,
'title': title,}

Expand Down

0 comments on commit 503011b

Please sign in to comment.