|
|
|
@ -2,10 +2,13 @@ from chat.models import NewMessage |
|
|
|
from django import template |
|
|
|
from django import template |
|
|
|
from django.core.paginator import Page |
|
|
|
from django.core.paginator import Page |
|
|
|
from django.db.models import Q, Count |
|
|
|
from django.db.models import Q, Count |
|
|
|
|
|
|
|
import itertools |
|
|
|
import math |
|
|
|
import math |
|
|
|
|
|
|
|
|
|
|
|
from reviews.models import Review |
|
|
|
from archilance import util |
|
|
|
from projects.models import Order |
|
|
|
from projects.models import Order |
|
|
|
|
|
|
|
from reviews.models import Review |
|
|
|
|
|
|
|
from users.helpers import get_projects_grouped |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
register = template.Library() |
|
|
|
register = template.Library() |
|
|
|
@ -112,9 +115,11 @@ def get_customer_chat_open_projects(user): |
|
|
|
def get_project_message_count(user): |
|
|
|
def get_project_message_count(user): |
|
|
|
if user.is_customer(): |
|
|
|
if user.is_customer(): |
|
|
|
projects = user.customer_projects.filter(state='active').exclude(order__contractor__isnull=True, order__team__isnull=True) |
|
|
|
projects = user.customer_projects.filter(state='active').exclude(order__contractor__isnull=True, order__team__isnull=True) |
|
|
|
# elif user.is_contractor(): |
|
|
|
return projects.aggregate(c=Count('answers__messages'))['c'] |
|
|
|
# # projects = user.customer_projects.filter(state='active').exclude(order__contractor__isnull=True, order__team__isnull=True) |
|
|
|
elif user.is_contractor(): |
|
|
|
|
|
|
|
message_count = user.contractor_answers.filter(project__state='active', rejected=False).aggregate(c=Count('messages'))['c'] |
|
|
|
return projects.aggregate(message_count=Count('answers__messages'))['message_count'] |
|
|
|
|
|
|
|
else: |
|
|
|
if util.has_related(user, 'team'): |
|
|
|
return '' # TODO |
|
|
|
message_count += user.team.answers.filter(project__state='active', rejected=False).aggregate(c=Count('messages'))['c'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return message_count |
|
|
|
|