From e0b887ee3edd9133b917a8db749f38ef035c10e2 Mon Sep 17 00:00:00 2001 From: Mukhtar Date: Mon, 19 Sep 2016 20:58:57 +0300 Subject: [PATCH] #ARC-18 Fixes --- assets/js/chat.js | 15 ++++++++------- assets/js/chat_contractor.js | 9 +++++---- assets/js/chat_customer.js | 3 ++- chat/serializers.py | 2 +- chat/templates/chat_contractor.html | 9 +++++---- chat/templates/chat_customer.html | 6 +++--- chat/views.py | 29 ++++++++++++++++++++++++++--- projects/serializers.py | 2 +- users/models.py | 5 ----- users/templatetags/user_tags.py | 3 ++- 10 files changed, 53 insertions(+), 30 deletions(-) diff --git a/assets/js/chat.js b/assets/js/chat.js index 2f09eb5..e47ffb5 100644 --- a/assets/js/chat.js +++ b/assets/js/chat.js @@ -563,15 +563,14 @@ function dialog (message, yesCallback, notCallback) { var recipentId = $("#chat-order-add #recipentId").val(); var senderId = $("#chat-order-add #senderId").val(); var orderId = $("#chat-order-add #orderId").val(); - - if (chatMessage) { - var sendLinks = $("#document-send-order a"); + var sendLinks = $("#document-send-order a"); + if (chatMessage || sendLinks.length > 0) { var sendLinkIds = ""; var documentLinks = ""; var documentAttachFiles = ""; $.each(sendLinks, function (i, v) { sendLinkIds += $(this).attr('data-id') + ';'; - documentLinks += 'Входящий файл:
'+ $(this).text() +'
'; + documentLinks += 'Приложенный файл. скачать:
'+ $(this).text() +'
'; documentAttachFiles += '
  • ' + '' + $(this).text() + '' + '
  • '; @@ -605,16 +604,18 @@ function dialog (message, yesCallback, notCallback) { var chatMessage = $("#chat").val(); var recipentId = $("#recipentContactId").val(); var senderId = $("#senderContactId").val(); - if (chatMessage) { + var sendLinks = $("#document-send-contact a"); + + if (chatMessage || sendLinks.length > 0) { $("#contact-chat-form .errorEmptyMessage").hide(); - var sendLinks = $("#document-send-contact a"); + var sendLinkIds = ""; var documentLinks = ""; var documentAttachFiles = ""; $.each(sendLinks, function (i, v) { sendLinkIds += $(this).attr('data-id') + ';'; - documentLinks += 'Входящий файл:
    '+ $(this).text() +'
    '; + documentLinks += 'Приложенный файл. скачать:
    '+ $(this).text() +'
    '; documentAttachFiles += '
  • ' + '' + $(this).text() + '' + '
  • '; diff --git a/assets/js/chat_contractor.js b/assets/js/chat_contractor.js index 5ba73f1..778baa0 100644 --- a/assets/js/chat_contractor.js +++ b/assets/js/chat_contractor.js @@ -588,15 +588,14 @@ $(function () { var orderId = $("#team-chat-form #orderTeamId").val(); var documentSendIds = $("#documentSendIds").val(); var teamIds = $("#team-chat-form #teamIds").val(); - - if (chatMessage) { - var sendLinks = $("#document-send a"); + var sendLinks = $("#document-send a"); + if (chatMessage || sendLinks.length > 0) { var sendLinkIds = ""; var documentLinks = ""; var documentAttachFiles = ""; $.each(sendLinks, function (i, v) { sendLinkIds += $(this).attr('data-id') + ';'; - documentLinks += 'Входящий файл:
    ' + $(this).text() + '
    '; + documentLinks += 'Приложенный файл. скачать:
    ' + $(this).text() + '
    '; documentAttachFiles += '
  • ' + '' + $(this).text() + '' + '
  • '; @@ -622,6 +621,8 @@ $(function () { $("#team-chat-form #chatText").val(""); $("#document-send").html(""); $("#documentSendIds").val(""); + } else { + $("#team-chat-form .errorEmptyMessage").show(); } }); diff --git a/assets/js/chat_customer.js b/assets/js/chat_customer.js index b0c1be4..988eeb7 100644 --- a/assets/js/chat_customer.js +++ b/assets/js/chat_customer.js @@ -303,6 +303,7 @@ $(function () { $(".new-stages-form").each(function (i, v) { var _this = $(this); + console.log($(this).serialize()); $.ajax({ url: '/api/stages/', type: 'POST', @@ -332,7 +333,7 @@ $(function () { $(".update-stages-form").each(function (i, v) { var _this = $(this); var currentStageId = parseInt($(this).attr('data-stage-id')); - + console.log($(this).serialize()); $.ajax({ url: '/api/stages/' + currentStageId + '/', type: 'PUT', diff --git a/chat/serializers.py b/chat/serializers.py index 5b9b59f..3a38ce3 100644 --- a/chat/serializers.py +++ b/chat/serializers.py @@ -63,7 +63,7 @@ class MessageSerializer(ModelSerializer): out = obj.text documents = obj.documents.all() if len(documents)>0: - documents_str = '
    '.join(['Приложенный файл:
    ' + doc.file.name + '' for doc in documents]) + documents_str = '
    '.join(['Приложенный файл. скачать:
    ' + doc.file.name + '' for doc in documents]) out += '

    ' + documents_str return out diff --git a/chat/templates/chat_contractor.html b/chat/templates/chat_contractor.html index c4fdb07..75d7a3d 100644 --- a/chat/templates/chat_contractor.html +++ b/chat/templates/chat_contractor.html @@ -7,7 +7,7 @@
    -

    Чат {{ request.user }} {{ request.user.pk }}

    +

    Чат

    @@ -17,15 +17,15 @@ @@ -321,6 +321,7 @@ +
    diff --git a/chat/templates/chat_customer.html b/chat/templates/chat_customer.html index c8728f3..f95ad57 100644 --- a/chat/templates/chat_customer.html +++ b/chat/templates/chat_customer.html @@ -7,7 +7,7 @@
    -

    Чат {{ request.user.get_score }}

    +

    Чат

    @@ -15,10 +15,10 @@
    diff --git a/chat/views.py b/chat/views.py index 97bdb24..7dde354 100644 --- a/chat/views.py +++ b/chat/views.py @@ -9,7 +9,7 @@ from wsgiref.util import FileWrapper from .response import JSONResponse, response_mimetype from .utils import serialize -from .models import Message, Documents +from .models import Message, Documents, NewMessage from projects.models import Order, Project from wallets.models import Transaction from users.models import User, Team @@ -53,16 +53,25 @@ class ChatUserView(LoginRequiredMixin, View): users_ids.append(b) if user_id: users_ids.append(int(user_id)) - print(users_ids) + contacts_users = User.objects.filter(pk__in=users_ids) chat_messages = Message.objects.filter(Q(sender=request.user.pk) | Q(recipent=request.user.pk)) orders = request.user.customer_projects.select_related('order').filter(state='active').exclude(order__contractor__isnull=True, order__team__isnull=True) + order_ids = [order.order.pk for order in orders] transaction = Transaction.objects.get_or_create(customer=request.user, type='reservation', complete=False) - self.template_name = 'chat_customer.html' + contacts_users_count = request.user.new_messages.filter(message__sender__in=users_ids, + message__order__isnull=True, + message__team__isnull=True + ).count() + + orders_ms_count = request.user.new_messages.filter(message__order__in=order_ids, message__team__isnull=True).count() + self.template_name = 'chat_customer.html' return render(request, self.template_name, {'contacts_users': contacts_users, 'chat_messages': chat_messages, + 'contacts_users_count': contacts_users_count, + 'orders_ms_count': orders_ms_count, 'orders': orders, 'transaction': transaction[0], 'YANDEX_MONEY': settings.YANDEX_MONEY, @@ -90,17 +99,31 @@ class ChatUserView(LoginRequiredMixin, View): users_ids.append(b) if user_id: users_ids.append(int(user_id)) + contacts_users = User.objects.filter(pk__in=users_ids) + contacts_users_count = request.user.new_messages.filter(message__sender__in=users_ids, + message__order__isnull=True, + message__team__isnull=True + ).count() chat_messages = Message.objects.filter(Q(sender=request.user.pk) | Q(recipent=request.user.pk)).order_by( 'created') your_teams = Team.objects.filter(Q(contractors__id=request.user.pk) | Q(owner=request.user)) + + orders_ms_count = request.user.new_messages.filter(message__order__in=orders, message__team__isnull=True).count() + teams_ms_count = request.user.new_messages.filter(message__team__in=your_teams, message__order__isnull=True).count() + + self.template_name = 'chat_contractor.html' return render(request, self.template_name, {'orders': orders, 'contacts_users': contacts_users, + 'contacts_users_count': contacts_users_count, + 'orders_ms_count': orders_ms_count, + 'teams_ms_count': teams_ms_count, 'chat_messages': chat_messages, 'team_orders': team_orders, 'your_teams': your_teams, + }) diff --git a/projects/serializers.py b/projects/serializers.py index 5266ea5..1e5dd40 100755 --- a/projects/serializers.py +++ b/projects/serializers.py @@ -80,7 +80,7 @@ class StageSerializer(ModelSerializer): term = serializers.DateField(format="%d.%m.%Y", input_formats=['%d.%m.%Y',]) def validate(self, data): - if hasattr(data, 'pos') and data['pos'] > 1: + if 'pos' in data and data['pos'] > 1: pos = data['pos'] -1 stage_last = Stage.objects.filter(order=data['order'], pos=pos) if stage_last: diff --git a/users/models.py b/users/models.py index 9dc2437..3a31d36 100644 --- a/users/models.py +++ b/users/models.py @@ -5,8 +5,6 @@ from django.db import models from django.db.models import Sum from django.utils import timezone, formats from mptt.models import TreeForeignKey, TreeManyToManyField -from pprint import pprint -import datetime import pydash as _; _.map = _.map_; _.filter = _.filter_ from archilance import util @@ -216,9 +214,6 @@ class User(AbstractBaseUser, PermissionsMixin): def has_team(self): return self.is_contractor() and bool(util.get_related_or_none(self, 'team')) - def is_owner_profile(self, user_id): - pass - def is_owner_team(self): return Team.objects.filter(owner=self.pk).exists() diff --git a/users/templatetags/user_tags.py b/users/templatetags/user_tags.py index 048f621..49d3e23 100644 --- a/users/templatetags/user_tags.py +++ b/users/templatetags/user_tags.py @@ -61,9 +61,10 @@ def get_new_count_message(team_pk,user=None): count = NewMessage.objects.filter(user=user, message__team=team_pk, message__order__isnull=True).count() return count + @register.simple_tag def get_new_count_for_contact(contact, current_user): - count = current_user.new_messages.filter(message__sender=contact).count() + count = current_user.new_messages.filter(message__sender=contact, message__order__isnull=True, message__team__isnull=True).count() return count