From a74c7e131f922fa4192cba46f2eac43b31c497f5 Mon Sep 17 00:00:00 2001 From: Mukhtar Date: Fri, 5 Aug 2016 17:16:31 +0300 Subject: [PATCH] #ARC-10 Add managements command and template tags for contractor --- chat/templates/chat.js | 1366 ++++++++--------- chat/templates/chat_customer.html | 5 - ratings/__init__.py | 1 + .../management}/__init__.py | 0 ratings/management/commands/__init__.py | 0 .../management/commands/recalculation_spec.py | 23 + ratings/models.py | 5 +- .../templatetags/specializations_widget.html | 9 + ratings/templatetags/__init__.py | 0 .../templatetags/specializtions_tags.py | 9 +- .../templatetags/specializations_widget.html | 21 - users/templates/contractor_profile.html | 12 - 12 files changed, 721 insertions(+), 730 deletions(-) rename {specializations/templatetags => ratings/management}/__init__.py (100%) create mode 100644 ratings/management/commands/__init__.py create mode 100644 ratings/management/commands/recalculation_spec.py create mode 100644 ratings/templates/templatetags/specializations_widget.html create mode 100644 ratings/templatetags/__init__.py rename {specializations => ratings}/templatetags/specializtions_tags.py (69%) delete mode 100644 specializations/templates/templatetags/specializations_widget.html diff --git a/chat/templates/chat.js b/chat/templates/chat.js index f40e51a..1afb936 100644 --- a/chat/templates/chat.js +++ b/chat/templates/chat.js @@ -1,683 +1,683 @@ - // - // function csrfSafeMethod(method) { - // // these HTTP methods do not require CSRF protection - // return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); - // } - // - // var SocketHandler = function () { - // var userId = {{ request.user.pk }}; - // var url = 'ws://127.0.0.1:8888/chat/' + userId + '/'; - // var sock = new WebSocket(url); - // var intervalId; - // sock.onopen = function () { - // console.log("Start connect"); - // intervalId = setInterval(function () { - // sock.send('{"dummy": 1}'); - // }, 150000); - // }; - // sock.onmessage = function (event) { - // console.log(event.data); - // var message = JSON.parse(event.data); - // var inbox; - // - // if (message.answer_type == 'contact' || message.answer_type == 'add_message_contact') { - // inbox = document.getElementById('message-chat-space'); - // } else if (message.answer_type == 'order' || message.answer_type == 'add_message_order') { - // inbox = document.getElementById('message-chat-order-space'); - // } else if(message.answer_type == 'add_message_team'){ - // inbox = document.getElementById('message-chat-team-space'); - // } - // console.log(message.answer_type); - // console.log(message.msg); - // - // inbox.innerHTML += '
' + - // '

ВЫ

13.0.2016
' + - // '

' + message.msg + '

'; - // }; - // - // this.send_contact_message = function (userId) { - // var data = { - // "format_type": "add_message", - // "user_id": userId - // } - // sock.send(JSON.stringify(data)); - // console.log(data); - // }; - // - // this.add_team_message = function(messageData){ - // - // console.log(messageData); - // sock.send(JSON.stringify(messageData)); - // } - // - // this.add_contact_message = function (messageData) { - // console.log(messageData); - // sock.send(JSON.stringify(messageData)); - // }; - // - // this.send_message = function (form) { - // var elements = form.elements; - // var data = {}; - // var i = 0; - // for (var i; i < elements.length; i++) { - // if (elements[i].name == 'message') { - // data[elements[i].name] = elements[i].value; - // } - // } - // sock.send(JSON.stringify(data)); - // var textareaMessage = document.getElementById("message"); - // textareaMessage.value = ""; - // } - // - // } - // - // $(function () { - // var currentChatUser = {{ request.user.pk }}; - // var socket = new SocketHandler(); - // var form = document.getElementById('message_form'); - // var csrftoken = getCookie('csrftoken'); - // - // setTimeout(function(){ - // $(".user-block").first().trigger('click'); - // }, 10); - // - // setTimeout(function(){ - // $(".order-block").first().trigger('click'); - // }, 100); - // - // setTimeout(function(){ - // $(".team-order-block").first().trigger('click'); - // }, 1000); - // - // - // var url = '/work_sell/basic/'; - // $('#upload-document-team').fileupload({ - // url: url, - // crossDomain: false, - // beforeSend: function (xhr, settings) { - // $('#progress .progress-bar').css( - // 'width', - // '0%' - // ); - // if (!csrfSafeMethod(settings.type)) { - // xhr.setRequestHeader("X-CSRFToken", csrftoken); - // } - // }, - // dataType: 'json', - // done: function (e, data) {; - // $.each(data.result.files, function (index, file) { - // var currentValue = $("#documentSendIds").val(); - // currentValue += file.id + ';'; - // $("#documentSendIds").val(currentValue); - // var htmlImg = '

'+ file.name+'

'; - // var document_send = $(htmlImg).appendTo("#document-send"); - // }); - // }, - // progressall: function (e, data) { - // var progress = parseInt(data.loaded / data.total * 100, 10); - // $('#progress .progress-bar').css( - // 'width', - // progress + '%' - // ); - // } - // }).prop('disabled', !$.support.fileInput) - // .parent().addClass($.support.fileInput ? undefined : 'disabled'); - // - // - // $("#approve-stages").on('click', function(){ - // $(".stage-block-approve").each(function(){ - // var stageId = $(this).attr('data-id'); - // }); - // }); - // - // $(".team-chat-user").on('click',function(e){ - // e.stopPropagation(); - // var recipentId = $(this).attr('data-id'); - // $("#team-chat-form #recipentId").val(recipentId); - // }); - // - // $(".team-order-block").on('click', function(){ - // - // $('.team-order-block').each(function () { - // $(this).removeClass('orAct'); - // }); - // $(this).addClass('orAct'); - // - // var teamId = $(this).attr('data-team-id'); - // var orderId = $(this).attr('data-order-id'); - // $("#team-chat-form #teamId").val(teamId); - // $("#team-chat-form #orderId").val(orderId); - // - // var inbox = document.getElementById('message-chat-team-space'); - // inbox.innerHTML = ''; - // - // $.ajax({ - // url: '/api/message', - // type: 'GET', - // data: {csrfmiddlewaretoken: csrftoken, 'team': teamId,'order': orderId}, - // dataType: 'json', - // success: function (json) { - // $.each(json.results, function (i, v) { - // var senderName = 'Вы'; - // var className = 'youChat'; - // if (v.sender.id !== currentChatUser) { - // senderName = v.sender.username; - // className = ''; - // } - // inbox.innerHTML += '
' + - // '

' + senderName + '

' + v.created + '
' + - // '

' + v.text + '

'; - // }); - // } - // }); - // - // }); - // - // // Вытащить сообщения для чата заказа - // $('.order-block').on('click', function () { - // $('.order-block').each(function () { - // $(this).removeClass('orAct'); - // }); - // $(this).addClass('orAct'); - // - // var orderId = $(this).attr('data-id'); - // var recipentId = $(this).attr('data-recipent-id'); - // $("#chat-contractor-order #orderId").val(orderId); - // $("#add-form-order-note #orderNote").val(orderId); - // - // $("#chat-contractor-order #recipentOrderId").val(recipentId); - // $("#add-form-order-note #recipentNote").val(recipentId); - // - // var inbox = document.getElementById('message-chat-order-space'); - // inbox.innerHTML = ''; - // - // $.ajax({ - // url: '/api/message', - // type: 'GET', - // data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, - // dataType: 'json', - // success: function (json) { - // $.each(json.results, function (i, v) { - // var senderName = 'Вы'; - // var className = 'youChat'; - // if (v.sender.id !== currentChatUser) { - // senderName = v.sender.username; - // className = ''; - // } - // inbox.innerHTML += '
' + - // '

' + senderName + '

' + v.created + '
' + - // '

' + v.text + '

'; - // }); - // } - // }); - // - // $.ajax({ - // url: '/api/note/', - // type: 'GET', - // data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, - // dataType: 'json', - // success: function (json) { - // console.log(json.results); - // var noteHtmlInbox = ''; - // $.each(json.results, function (i, v) { - // noteHtmlInbox += '
  • '+ v.text +'
  • '; - // - // }); - // $(".notes-block").html(noteHtmlInbox); - // } - // }); - // - // $.ajax({ - // url: '/api/stages/', - // type: 'GET', - // data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, - // dataType: 'json', - // success: function (json) { - // console.log(json.results); - // var htmlInbox = ""; - // var stagesReservedHtml = ""; - // if (json.results.length > 0) { - // - // $.each(json.results, function (i, v) { - // if(v.is_paid){ - // stagesReservedHtml += '
  • Сумма за этап '+ i +'.Зарезервирована.
  • '; - // }else{ - // stagesReservedHtml += '
  • Сумма за этап '+ i +'.Не зарезервирована.
  • '; - // } - // htmlInbox += '
    ' + - // '

    Этап ' + v.pos + '' + v.name + '

    ' + - // '

    Результаты этапа:' + v.result + '

    ' + - // '

    '+ v.status+'

    ' + v.cost + '
    '; - // }); - // htmlInbox += '
    согласовать
    '; - // - // } - // $("#order-stages").html(htmlInbox); - // $(".stages-paid").html(stagesReservedHtml); - // - // } - // }); - // - // }); - // - // $('#add-note-button').on('click', function(){ - // $.ajax({ - // url: '/api/note/', - // type: 'POST', - // beforeSend: function (xhr) { - // xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) - // }, - // data:$("#add-form-order-note").serialize(), - // dataType: 'json', - // success: function (json) { - // console.log(json); - // $("#add-form-order-note #chat2").val(""); - // - // }, - // error: function(e){ - // console.log('error'); - // console.log(e); - // } - // }); - // }); - // - // // Вытащить сообщения для конактов - // $('.user-block').on('click', function () { - // var userId = $(this).attr('data-id'); - // $("#contact-chat-form #recipentId").val(userId); - // var inbox = document.getElementById('message-chat-space'); - // inbox.innerHTML = ''; - // $.ajax({ - // url: '/api/message', - // type: 'GET', - // data: { - // csrfmiddlewaretoken: csrftoken, - // 'operand': 'in', - // 'sender_id': currentChatUser, - // 'recipent_id': userId - // }, - // dataType: 'json', - // success: function (json) { - // $.each(json.results, function (i, v) { - // console.log(v.sender.id); - // var senderName = 'Вы'; - // var className = 'youChat'; - // if (v.sender.id == userId) { - // senderName = v.sender.username; - // className = ''; - // } - // inbox.innerHTML += '
    ' + - // '

    ' + senderName + '

    ' + v.created + '
    ' + - // '

    ' + v.text + '

    '; - // }); - // } - // }); - // - // }); - // - // //Добавить сообщение для исполнителей в группе - // $("#add-team-chat-message").on('click', function(){ - // var chatMessage = $("#team-chat-form #chatText").val(); - // var recipentId = $("#team-chat-form #recipentId").val(); - // var senderId = $("#team-chat-form #senderId").val(); - // var teamId = $("#team-chat-form #teamId").val(); - // var orderId = $("#team-chat-form #orderId").val(); - // - // var documentSendIds = $("#documentSendIds").val(); - // console.log(documentSendIds); - // var teamDocumentIds = documentSendIds.split(';'); - // teamDocumentIds.pop(); - // console.log(teamDocumentIds); - // socket.add_team_message({ - // "format_type": "add_message_team", - // "data": { - // "sender_id": senderId, - // "recipent_id": recipentId, - // "chat_message": chatMessage, - // "team_id": teamId, - // "order_id": orderId, - // } - // }); - // - // - // - // $("#team-chat-form #chatText").val(""); - // }); - // - // // Добавить сообщение для контакта - // $('#contact-chat-add-message').on('click', function () { - // var chatMessage = $("#chat").val(); - // var recipentId = $("#recipentId").val(); - // var senderId = $("#senderId").val(); - // - // socket.add_contact_message({ - // "format_type": "add_message_contact", - // "data": { - // "sender_id": senderId, - // "recipent_id": recipentId, - // "chat_message": chatMessage, - // } - // }); - // - // var inbox = $('#message-chat-space').html(); - // $('#message-chat-space').html(inbox + '
    ' + - // '

    Вы

    Сейчас
    ' + - // '

    ' + chatMessage + '

    '); - // - // $("#chat").val(""); - // }); - // - // $('#order-chat-add-message').on('click', function () { - // var chatMessage = $("#chat-contractor-order #chat").val(); - // var recipentId = $("#chat-contractor-order #recipentOrderId").val(); - // var senderId = $("#chat-contractor-order #senderOrderId").val(); - // var orderId = $("#chat-contractor-order #orderId").val(); - // - // socket.add_contact_message({ - // "format_type": "add_message_order", - // "data": { - // "sender_id": senderId, - // "recipent_id": recipentId, - // "chat_message": chatMessage, - // "order_id": orderId, - // - // } - // }); - // - // $("#chat-contractor-order #chat").val(""); - // - // }); - // - // }); - // - // - //$(function () { - // var currentChatUser = {{ request.user.pk }}; - // var socket = new SocketHandler(); - // var form = document.getElementById('message_form'); - // var csrftoken = getCookie('csrftoken'); - // setTimeout(function(){ - // $(".user-block").first().trigger('click'); - // }, 10); - // - // setTimeout(function(){ - // $(".order-block").first().trigger('click'); - // }, 100); - // - // $("#order-stages").on('click', "#addStagesForm", function(){ - // $(".new-stages-form").each(function(i,v){ - // console.log($(this).serialize()); - // alert($(this).serialize()); - // - // $.ajax({ - // url: '/api/stages/', - // type: 'POST', - // beforeSend: function (xhr) { - // xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) - // }, - // data:$(this).serialize(), - // dataType: 'json', - // success: function (json) { - // console.log(json); - // }, - // error: function(e){ - // console.log('error'); - // console.log(e); - // } - // }); - // - // }); - // }); - // - // $('#order-stages-tab').on('change', '#countStage', function(){ - // var countStage = parseInt($(this).val()); - // var updateFormStages = $(".update-stages-form"); - // - // alert(updateFormStages.length); - // alert(typeof updateFormStages.length); - // var limitCount = countStage + 1; - // for (var i = 2; i < limitCount; i++) { - // var stageCopy = $("#stage1").clone().attr("id", "stage" + i).addClass("stages_form"); - // $("#stage1").after(stageCopy); - // } - // }); - // - // $('.order-block').on('click', function () { - // $("#chat-order-add").css("display", "block"); - // $("#formsetStage").css("display","block"); - // - // $('.order-block').each(function () { - // $(this).removeClass('orAct'); - // }); - // - // $(this).addClass('orAct'); - // var orderId = $(this).attr('data-id'); - // var recipentId = $(this).attr('data-recipent-id'); - // $("#chat-order-add #orderId").val(orderId); - // $("#chat-order-add #recipentId").val(recipentId); - // $(".orderStagesInput").val(orderId); - // var inbox = document.getElementById('message-chat-order-space'); - // inbox.innerHTML = ''; - // $.ajax({ - // url: '/api/message', - // type: 'GET', - // data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, - // dataType: 'json', - // success: function (json) { - // $.each(json.results, function (i, v) { - // var senderName = 'Вы'; - // var className = 'youChat'; - // - // if (v.sender.id !== currentChatUser) { - // senderName = v.sender.username; - // className = ''; - // } - // - // inbox.innerHTML += '
    ' + - // '

    ' + senderName + '

    ' + v.created + '
    ' + - // '

    ' + v.text + '

    '; - // }); - // } - // }); - // - // $.ajax({ - // url: '/api/stages/', - // type: 'GET', - // data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, - // dataType: 'json', - // success: function (json) { - // var stageCount = json.results.length; - // if (stageCount == 0){ - // stageCountVal = 1; - // }else{ - // stageCountVal = stageCount; - // } - // - // var htmlInbox = ""; - // - // var htmlInboxStage = '

    Какое кол-во этапов подразумевает работа? ' + - // '

    '; - // - // if (stageCount == 0){ - // htmlInboxStage += '
    ' + - // '

    Этап 1

    ' + - // '' + - // '' + - // ' />' + - // '' + - // '' + - // '
    '; - // } - // var statusNotAgreed = true; - // $.each(json.results, function (i, v) { - // if (v.status == "not_agreed") { - // htmlInbox += '
    ' + - // '

    Этап

    ' + - // '' + - // '' + - // '' + - // '' + - // '' + - // '
    '; - // } else { - // statusNotAgreed = false; - // htmlInboxStage = ""; - // htmlInbox += '
    ' + - // '

    Этап ' + v.pos + '' + v.name + '

    ' + - // '

    Результаты этапа:' + v.result + '

    ' + - // '

    до 16.03.2015

    ' + v.cost + '
    '; - // - // } - // }); - // - // if (statusNotAgreed) { - // htmlInbox += '
    Перейти в режим безопасной сделки' + - // '
    ' + - // 'отправить на согласование
    '; - // } - // htmlInbox = htmlInboxStage + htmlInbox; - // $("#order-stages").html(htmlInbox); - // } - // }); - // - // - // }); - // - // // Вытащить сообщения для конактов - // $('.user-block').on('click', function () { - // var userId = $(this).attr('data-id'); - // $("#contact-chat-form #recipentId").val(userId); - // var inbox = document.getElementById('message-chat-space'); - // inbox.innerHTML = ''; - // $.ajax({ - // url: '/api/message', - // type: 'GET', - // data: { - // csrfmiddlewaretoken: csrftoken, - // 'operand': 'in', - // 'sender_id': currentChatUser, - // 'recipent_id': userId - // }, - // dataType: 'json', - // success: function (json) { - // $.each(json.results, function (i, v) { - // var senderName = 'Вы'; - // var className = 'youChat'; - // if (v.sender.id == userId) { - // senderName = v.sender.username; - // className = ''; - // } - // inbox.innerHTML += '
    ' + - // '

    ' + senderName + '

    ' + v.created + '
    ' + - // '

    ' + v.text + '

    '; - // }); - // } - // }); - // - // }); - // - // $('#contact-chat-add-message').on('click', function () { - // var chatMessage = $("#chat").val(); - // var recipentId = $("#recipentId").val(); - // var senderId = $("#senderId").val(); - // - // socket.add_contact_message({ - // "format_type": "add_message_contact", - // "data": { - // "sender_id": senderId, - // "recipent_id": recipentId, - // "chat_message": chatMessage, - // } - // }); - // - // $("#chat").val(""); - // }); - // - // $('#order-chat-add-message').on('click', function () { - // var chatMessage = $("#chat-order-add #chat").val(); - // var recipentId = $("#chat-order-add #recipentId").val(); - // var senderId = $("#chat-order-add #senderId").val(); - // var orderId = $("#chat-order-add #orderId").val(); - // - // socket.add_contact_message({ - // "format_type": "add_message_order", - // "data": { - // "sender_id": senderId, - // "recipent_id": recipentId, - // "chat_message": chatMessage, - // "order_id": orderId, - // - // } - // }); - // - // $("#chat-order-add #chat").val(""); - // }); - // - // }); - // - // var userId = '{{ request.user.pk }}'; - // - // var SocketHandler = function () { - // var url = 'ws://127.0.0.1:8888/chat/' + userId + '/'; - // var sock = new WebSocket(url); - // var intervalId; - // sock.onopen = function () { - // console.log("Start connect"); - // intervalId = setInterval(function () { - // sock.send('{"dummy": 1}'); - // }, 150); - // }; - // sock.onmessage = function (event) { - // console.log(event.data); - // var message = JSON.parse(event.data); - // var inbox; - // if (message.answer_type == 'contact') { - // inbox = document.getElementById('message-chat-space'); - // } else if (message.answer_type == 'order' || message.answer_type == 'add_order') { - // inbox = document.getElementById('message-chat-order-space') - // } - // inbox.innerHTML += '
    ' + - // '

    Иванов

    13.0.2016
    ' + - // '

    ' + message.msg + '

    '; - // - // }; - // - // this.send_order_message = function (orderId) { - // var data = { - // "format_type": "order_message", - // "order_id": orderId - // } - // sock.send(JSON.stringify(data)); - // console.log(data); - // }; - // - // this.send_contact_message = function (userId) { - // var data = { - // "format_type": "add_message", - // "user_id": userId - // } - // sock.send(JSON.stringify(data)); - // console.log(data); - // }; - // - // this.add_contact_message = function (messageData) { - // console.log(messageData); - // sock.send(JSON.stringify(messageData)); - // }; - // - // this.send_message = function (form) { - // var elements = form.elements; - // var data = {}; - // var i = 0; - // for (var i; i < elements.length; i++) { - // if (elements[i].name == 'message') { - // data[elements[i].name] = elements[i].value; - // } - // } - // sock.send(JSON.stringify(data)); - // var textareaMessage = document.getElementById("message"); - // textareaMessage.value = ""; - // - // } - // } - // + + function csrfSafeMethod(method) { + // these HTTP methods do not require CSRF protection + return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); + } + + var SocketHandler = function () { + var userId = {{ request.user.pk }}; + var url = 'ws://127.0.0.1:8888/chat/' + userId + '/'; + var sock = new WebSocket(url); + var intervalId; + sock.onopen = function () { + console.log("Start connect"); + intervalId = setInterval(function () { + sock.send('{"dummy": 1}'); + }, 150000); + }; + sock.onmessage = function (event) { + console.log(event.data); + var message = JSON.parse(event.data); + var inbox; + + if (message.answer_type == 'contact' || message.answer_type == 'add_message_contact') { + inbox = document.getElementById('message-chat-space'); + } else if (message.answer_type == 'order' || message.answer_type == 'add_message_order') { + inbox = document.getElementById('message-chat-order-space'); + } else if(message.answer_type == 'add_message_team'){ + inbox = document.getElementById('message-chat-team-space'); + } + console.log(message.answer_type); + console.log(message.msg); + + inbox.innerHTML += '
    ' + + '

    ВЫ

    13.0.2016
    ' + + '

    ' + message.msg + '

    '; + }; + + this.send_contact_message = function (userId) { + var data = { + "format_type": "add_message", + "user_id": userId + } + sock.send(JSON.stringify(data)); + console.log(data); + }; + + this.add_team_message = function(messageData){ + + console.log(messageData); + sock.send(JSON.stringify(messageData)); + } + + this.add_contact_message = function (messageData) { + console.log(messageData); + sock.send(JSON.stringify(messageData)); + }; + + this.send_message = function (form) { + var elements = form.elements; + var data = {}; + var i = 0; + for (var i; i < elements.length; i++) { + if (elements[i].name == 'message') { + data[elements[i].name] = elements[i].value; + } + } + sock.send(JSON.stringify(data)); + var textareaMessage = document.getElementById("message"); + textareaMessage.value = ""; + } + + } + + $(function () { + var currentChatUser = {{ request.user.pk }}; + var socket = new SocketHandler(); + var form = document.getElementById('message_form'); + var csrftoken = getCookie('csrftoken'); + + setTimeout(function(){ + $(".user-block").first().trigger('click'); + }, 10); + + setTimeout(function(){ + $(".order-block").first().trigger('click'); + }, 100); + + setTimeout(function(){ + $(".team-order-block").first().trigger('click'); + }, 1000); + + + var url = '/work_sell/basic/'; + $('#upload-document-team').fileupload({ + url: url, + crossDomain: false, + beforeSend: function (xhr, settings) { + $('#progress .progress-bar').css( + 'width', + '0%' + ); + if (!csrfSafeMethod(settings.type)) { + xhr.setRequestHeader("X-CSRFToken", csrftoken); + } + }, + dataType: 'json', + done: function (e, data) {; + $.each(data.result.files, function (index, file) { + var currentValue = $("#documentSendIds").val(); + currentValue += file.id + ';'; + $("#documentSendIds").val(currentValue); + var htmlImg = '

    '+ file.name+'

    '; + var document_send = $(htmlImg).appendTo("#document-send"); + }); + }, + progressall: function (e, data) { + var progress = parseInt(data.loaded / data.total * 100, 10); + $('#progress .progress-bar').css( + 'width', + progress + '%' + ); + } + }).prop('disabled', !$.support.fileInput) + .parent().addClass($.support.fileInput ? undefined : 'disabled'); + + + $("#approve-stages").on('click', function(){ + $(".stage-block-approve").each(function(){ + var stageId = $(this).attr('data-id'); + }); + }); + + $(".team-chat-user").on('click',function(e){ + e.stopPropagation(); + var recipentId = $(this).attr('data-id'); + $("#team-chat-form #recipentId").val(recipentId); + }); + + $(".team-order-block").on('click', function(){ + + $('.team-order-block').each(function () { + $(this).removeClass('orAct'); + }); + $(this).addClass('orAct'); + + var teamId = $(this).attr('data-team-id'); + var orderId = $(this).attr('data-order-id'); + $("#team-chat-form #teamId").val(teamId); + $("#team-chat-form #orderId").val(orderId); + + var inbox = document.getElementById('message-chat-team-space'); + inbox.innerHTML = ''; + + $.ajax({ + url: '/api/message', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'team': teamId,'order': orderId}, + dataType: 'json', + success: function (json) { + $.each(json.results, function (i, v) { + var senderName = 'Вы'; + var className = 'youChat'; + if (v.sender.id !== currentChatUser) { + senderName = v.sender.username; + className = ''; + } + inbox.innerHTML += '
    ' + + '

    ' + senderName + '

    ' + v.created + '
    ' + + '

    ' + v.text + '

    '; + }); + } + }); + + }); + + // Вытащить сообщения для чата заказа + $('.order-block').on('click', function () { + $('.order-block').each(function () { + $(this).removeClass('orAct'); + }); + $(this).addClass('orAct'); + + var orderId = $(this).attr('data-id'); + var recipentId = $(this).attr('data-recipent-id'); + $("#chat-contractor-order #orderId").val(orderId); + $("#add-form-order-note #orderNote").val(orderId); + + $("#chat-contractor-order #recipentOrderId").val(recipentId); + $("#add-form-order-note #recipentNote").val(recipentId); + + var inbox = document.getElementById('message-chat-order-space'); + inbox.innerHTML = ''; + + $.ajax({ + url: '/api/message', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, + dataType: 'json', + success: function (json) { + $.each(json.results, function (i, v) { + var senderName = 'Вы'; + var className = 'youChat'; + if (v.sender.id !== currentChatUser) { + senderName = v.sender.username; + className = ''; + } + inbox.innerHTML += '
    ' + + '

    ' + senderName + '

    ' + v.created + '
    ' + + '

    ' + v.text + '

    '; + }); + } + }); + + $.ajax({ + url: '/api/note/', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, + dataType: 'json', + success: function (json) { + console.log(json.results); + var noteHtmlInbox = ''; + $.each(json.results, function (i, v) { + noteHtmlInbox += '
  • '+ v.text +'
  • '; + + }); + $(".notes-block").html(noteHtmlInbox); + } + }); + + $.ajax({ + url: '/api/stages/', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, + dataType: 'json', + success: function (json) { + console.log(json.results); + var htmlInbox = ""; + var stagesReservedHtml = ""; + if (json.results.length > 0) { + + $.each(json.results, function (i, v) { + if(v.is_paid){ + stagesReservedHtml += '
  • Сумма за этап '+ i +'.Зарезервирована.
  • '; + }else{ + stagesReservedHtml += '
  • Сумма за этап '+ i +'.Не зарезервирована.
  • '; + } + htmlInbox += '
    ' + + '

    Этап ' + v.pos + '' + v.name + '

    ' + + '

    Результаты этапа:' + v.result + '

    ' + + '

    '+ v.status+'

    ' + v.cost + '
    '; + }); + htmlInbox += '
    согласовать
    '; + + } + $("#order-stages").html(htmlInbox); + $(".stages-paid").html(stagesReservedHtml); + + } + }); + + }); + + $('#add-note-button').on('click', function(){ + $.ajax({ + url: '/api/note/', + type: 'POST', + beforeSend: function (xhr) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) + }, + data:$("#add-form-order-note").serialize(), + dataType: 'json', + success: function (json) { + console.log(json); + $("#add-form-order-note #chat2").val(""); + + }, + error: function(e){ + console.log('error'); + console.log(e); + } + }); + }); + + // Вытащить сообщения для конактов + $('.user-block').on('click', function () { + var userId = $(this).attr('data-id'); + $("#contact-chat-form #recipentId").val(userId); + var inbox = document.getElementById('message-chat-space'); + inbox.innerHTML = ''; + $.ajax({ + url: '/api/message', + type: 'GET', + data: { + csrfmiddlewaretoken: csrftoken, + 'operand': 'in', + 'sender_id': currentChatUser, + 'recipent_id': userId + }, + dataType: 'json', + success: function (json) { + $.each(json.results, function (i, v) { + console.log(v.sender.id); + var senderName = 'Вы'; + var className = 'youChat'; + if (v.sender.id == userId) { + senderName = v.sender.username; + className = ''; + } + inbox.innerHTML += '
    ' + + '

    ' + senderName + '

    ' + v.created + '
    ' + + '

    ' + v.text + '

    '; + }); + } + }); + + }); + + //Добавить сообщение для исполнителей в группе + $("#add-team-chat-message").on('click', function(){ + var chatMessage = $("#team-chat-form #chatText").val(); + var recipentId = $("#team-chat-form #recipentId").val(); + var senderId = $("#team-chat-form #senderId").val(); + var teamId = $("#team-chat-form #teamId").val(); + var orderId = $("#team-chat-form #orderId").val(); + + var documentSendIds = $("#documentSendIds").val(); + console.log(documentSendIds); + var teamDocumentIds = documentSendIds.split(';'); + teamDocumentIds.pop(); + console.log(teamDocumentIds); + socket.add_team_message({ + "format_type": "add_message_team", + "data": { + "sender_id": senderId, + "recipent_id": recipentId, + "chat_message": chatMessage, + "team_id": teamId, + "order_id": orderId, + } + }); + + + + $("#team-chat-form #chatText").val(""); + }); + + // Добавить сообщение для контакта + $('#contact-chat-add-message').on('click', function () { + var chatMessage = $("#chat").val(); + var recipentId = $("#recipentId").val(); + var senderId = $("#senderId").val(); + + socket.add_contact_message({ + "format_type": "add_message_contact", + "data": { + "sender_id": senderId, + "recipent_id": recipentId, + "chat_message": chatMessage, + } + }); + + var inbox = $('#message-chat-space').html(); + $('#message-chat-space').html(inbox + '
    ' + + '

    Вы

    Сейчас
    ' + + '

    ' + chatMessage + '

    '); + + $("#chat").val(""); + }); + + $('#order-chat-add-message').on('click', function () { + var chatMessage = $("#chat-contractor-order #chat").val(); + var recipentId = $("#chat-contractor-order #recipentOrderId").val(); + var senderId = $("#chat-contractor-order #senderOrderId").val(); + var orderId = $("#chat-contractor-order #orderId").val(); + + socket.add_contact_message({ + "format_type": "add_message_order", + "data": { + "sender_id": senderId, + "recipent_id": recipentId, + "chat_message": chatMessage, + "order_id": orderId, + + } + }); + + $("#chat-contractor-order #chat").val(""); + + }); + + }); + + + $(function () { + var currentChatUser = {{ request.user.pk }}; + var socket = new SocketHandler(); + var form = document.getElementById('message_form'); + var csrftoken = getCookie('csrftoken'); + setTimeout(function(){ + $(".user-block").first().trigger('click'); + }, 10); + + setTimeout(function(){ + $(".order-block").first().trigger('click'); + }, 100); + + $("#order-stages").on('click', "#addStagesForm", function(){ + $(".new-stages-form").each(function(i,v){ + console.log($(this).serialize()); + alert($(this).serialize()); + + $.ajax({ + url: '/api/stages/', + type: 'POST', + beforeSend: function (xhr) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')) + }, + data:$(this).serialize(), + dataType: 'json', + success: function (json) { + console.log(json); + }, + error: function(e){ + console.log('error'); + console.log(e); + } + }); + + }); + }); + + $('#order-stages-tab').on('change', '#countStage', function(){ + var countStage = parseInt($(this).val()); + var updateFormStages = $(".update-stages-form"); + + alert(updateFormStages.length); + alert(typeof updateFormStages.length); + var limitCount = countStage + 1; + for (var i = 2; i < limitCount; i++) { + var stageCopy = $("#stage1").clone().attr("id", "stage" + i).addClass("stages_form"); + $("#stage1").after(stageCopy); + } + }); + + $('.order-block').on('click', function () { + $("#chat-order-add").css("display", "block"); + $("#formsetStage").css("display","block"); + + $('.order-block').each(function () { + $(this).removeClass('orAct'); + }); + + $(this).addClass('orAct'); + var orderId = $(this).attr('data-id'); + var recipentId = $(this).attr('data-recipent-id'); + $("#chat-order-add #orderId").val(orderId); + $("#chat-order-add #recipentId").val(recipentId); + $(".orderStagesInput").val(orderId); + var inbox = document.getElementById('message-chat-order-space'); + inbox.innerHTML = ''; + $.ajax({ + url: '/api/message', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, + dataType: 'json', + success: function (json) { + $.each(json.results, function (i, v) { + var senderName = 'Вы'; + var className = 'youChat'; + + if (v.sender.id !== currentChatUser) { + senderName = v.sender.username; + className = ''; + } + + inbox.innerHTML += '
    ' + + '

    ' + senderName + '

    ' + v.created + '
    ' + + '

    ' + v.text + '

    '; + }); + } + }); + + $.ajax({ + url: '/api/stages/', + type: 'GET', + data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, + dataType: 'json', + success: function (json) { + var stageCount = json.results.length; + if (stageCount == 0){ + stageCountVal = 1; + }else{ + stageCountVal = stageCount; + } + + var htmlInbox = ""; + + var htmlInboxStage = '

    Какое кол-во этапов подразумевает работа? ' + + '

    '; + + if (stageCount == 0){ + htmlInboxStage += '
    ' + + '

    Этап 1

    ' + + '' + + '' + + ' />' + + '' + + '' + + '
    '; + } + var statusNotAgreed = true; + $.each(json.results, function (i, v) { + if (v.status == "not_agreed") { + htmlInbox += '
    ' + + '

    Этап

    ' + + '' + + '' + + '' + + '' + + '' + + '
    '; + } else { + statusNotAgreed = false; + htmlInboxStage = ""; + htmlInbox += '
    ' + + '

    Этап ' + v.pos + '' + v.name + '

    ' + + '

    Результаты этапа:' + v.result + '

    ' + + '

    до 16.03.2015

    ' + v.cost + '
    '; + + } + }); + + if (statusNotAgreed) { + htmlInbox += '
    Перейти в режим безопасной сделки' + + '
    ' + + 'отправить на согласование
    '; + } + htmlInbox = htmlInboxStage + htmlInbox; + $("#order-stages").html(htmlInbox); + } + }); + + + }); + + // Вытащить сообщения для конактов + $('.user-block').on('click', function () { + var userId = $(this).attr('data-id'); + $("#contact-chat-form #recipentId").val(userId); + var inbox = document.getElementById('message-chat-space'); + inbox.innerHTML = ''; + $.ajax({ + url: '/api/message', + type: 'GET', + data: { + csrfmiddlewaretoken: csrftoken, + 'operand': 'in', + 'sender_id': currentChatUser, + 'recipent_id': userId + }, + dataType: 'json', + success: function (json) { + $.each(json.results, function (i, v) { + var senderName = 'Вы'; + var className = 'youChat'; + if (v.sender.id == userId) { + senderName = v.sender.username; + className = ''; + } + inbox.innerHTML += '
    ' + + '

    ' + senderName + '

    ' + v.created + '
    ' + + '

    ' + v.text + '

    '; + }); + } + }); + + }); + + $('#contact-chat-add-message').on('click', function () { + var chatMessage = $("#chat").val(); + var recipentId = $("#recipentId").val(); + var senderId = $("#senderId").val(); + + socket.add_contact_message({ + "format_type": "add_message_contact", + "data": { + "sender_id": senderId, + "recipent_id": recipentId, + "chat_message": chatMessage, + } + }); + + $("#chat").val(""); + }); + + $('#order-chat-add-message').on('click', function () { + var chatMessage = $("#chat-order-add #chat").val(); + var recipentId = $("#chat-order-add #recipentId").val(); + var senderId = $("#chat-order-add #senderId").val(); + var orderId = $("#chat-order-add #orderId").val(); + + socket.add_contact_message({ + "format_type": "add_message_order", + "data": { + "sender_id": senderId, + "recipent_id": recipentId, + "chat_message": chatMessage, + "order_id": orderId, + + } + }); + + $("#chat-order-add #chat").val(""); + }); + + }); + + var userId = '{{ request.user.pk }}'; + + var SocketHandler = function () { + var url = 'ws://127.0.0.1:8888/chat/' + userId + '/'; + var sock = new WebSocket(url); + var intervalId; + sock.onopen = function () { + console.log("Start connect"); + intervalId = setInterval(function () { + sock.send('{"dummy": 1}'); + }, 150); + }; + sock.onmessage = function (event) { + console.log(event.data); + var message = JSON.parse(event.data); + var inbox; + if (message.answer_type == 'contact') { + inbox = document.getElementById('message-chat-space'); + } else if (message.answer_type == 'order' || message.answer_type == 'add_order') { + inbox = document.getElementById('message-chat-order-space') + } + inbox.innerHTML += '
    ' + + '

    Иванов

    13.0.2016
    ' + + '

    ' + message.msg + '

    '; + + }; + + this.send_order_message = function (orderId) { + var data = { + "format_type": "order_message", + "order_id": orderId + } + sock.send(JSON.stringify(data)); + console.log(data); + }; + + this.send_contact_message = function (userId) { + var data = { + "format_type": "add_message", + "user_id": userId + } + sock.send(JSON.stringify(data)); + console.log(data); + }; + + this.add_contact_message = function (messageData) { + console.log(messageData); + sock.send(JSON.stringify(messageData)); + }; + + this.send_message = function (form) { + var elements = form.elements; + var data = {}; + var i = 0; + for (var i; i < elements.length; i++) { + if (elements[i].name == 'message') { + data[elements[i].name] = elements[i].value; + } + } + sock.send(JSON.stringify(data)); + var textareaMessage = document.getElementById("message"); + textareaMessage.value = ""; + + } + } + diff --git a/chat/templates/chat_customer.html b/chat/templates/chat_customer.html index 296a404..a805400 100644 --- a/chat/templates/chat_customer.html +++ b/chat/templates/chat_customer.html @@ -248,7 +248,6 @@ $("#order-stages").on('click', "#addStagesForm", function(){ $(".new-stages-form").each(function(i,v){ console.log($(this).serialize()); - alert($(this).serialize()); $.ajax({ url: '/api/stages/', @@ -273,9 +272,6 @@ $('#order-stages-tab').on('change', '#countStage', function(){ var countStage = parseInt($(this).val()); var updateFormStages = $(".update-stages-form"); - - alert(updateFormStages.length); - alert(typeof updateFormStages.length); var limitCount = countStage + 1; for (var i = 2; i < limitCount; i++) { var stageCopy = $("#stage1").clone().attr("id", "stage" + i).addClass("stages_form"); @@ -457,7 +453,6 @@ }); var userId = '{{ request.user.pk }}'; - var SocketHandler = function () { var url = 'ws://127.0.0.1:8888/chat/' + userId + '/'; var sock = new WebSocket(url); diff --git a/ratings/__init__.py b/ratings/__init__.py index e69de29..f9d7f74 100644 --- a/ratings/__init__.py +++ b/ratings/__init__.py @@ -0,0 +1 @@ +default_app_config = 'ratings.apps.RatingsConfig' diff --git a/specializations/templatetags/__init__.py b/ratings/management/__init__.py similarity index 100% rename from specializations/templatetags/__init__.py rename to ratings/management/__init__.py diff --git a/ratings/management/commands/__init__.py b/ratings/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ratings/management/commands/recalculation_spec.py b/ratings/management/commands/recalculation_spec.py new file mode 100644 index 0000000..ffe92db --- /dev/null +++ b/ratings/management/commands/recalculation_spec.py @@ -0,0 +1,23 @@ +from django.core.management import BaseCommand +from specializations.models import Specialization +from ratings.models import SpecializationRating +from users.models import User + + +class Command(BaseCommand): + def handle(self, *args, **options): + SpecializationRating.objects.all().delete() + contractors = User.contractor_objects.order_by('-contractor_rating') + specializations = Specialization.objects.all() + for spec in specializations: + i = 0 + for contractor in contractors: + if spec in contractor.contractor_specializations.all(): + i += 1 + spec_rating = SpecializationRating() + spec_rating.position = i + spec_rating.user = contractor + spec_rating.specialization = spec + spec_rating.save() + + print('The End') diff --git a/ratings/models.py b/ratings/models.py index 4db1001..e5dd042 100644 --- a/ratings/models.py +++ b/ratings/models.py @@ -3,6 +3,7 @@ from django.utils import timezone from users.models import User, Team from specializations.models import Specialization + class HistoryRating(models.Model): user = models.ForeignKey(User, related_name='history_ratings', null=True, blank=True) team = models.ForeignKey(Team, related_name='history_ratings', null=True, blank=True) @@ -25,12 +26,10 @@ class SpecializationRating(models.Model): position = models.PositiveIntegerField(default=0) def __str__(self): - return self.position + return '{0}'.format(self.pk) class Meta: verbose_name = 'Рейтинг специализаций' verbose_name_plural = 'Рейтинги специализаций' - - diff --git a/ratings/templates/templatetags/specializations_widget.html b/ratings/templates/templatetags/specializations_widget.html new file mode 100644 index 0000000..c8a1175 --- /dev/null +++ b/ratings/templates/templatetags/specializations_widget.html @@ -0,0 +1,9 @@ +
    +

    Специализации:

    + {% for spec in specializations %} +
    + {{ spec.specialization.name }} + {{ spec.position }}-й +
    + {% endfor %} +
    diff --git a/ratings/templatetags/__init__.py b/ratings/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/specializations/templatetags/specializtions_tags.py b/ratings/templatetags/specializtions_tags.py similarity index 69% rename from specializations/templatetags/specializtions_tags.py rename to ratings/templatetags/specializtions_tags.py index 8f067c9..b54bec1 100644 --- a/specializations/templatetags/specializtions_tags.py +++ b/ratings/templatetags/specializtions_tags.py @@ -2,18 +2,15 @@ from django import template from archilance import util from users.models import User - +from ratings.models import SpecializationRating register = template.Library() @register.inclusion_tag('templatetags/specializations_widget.html', takes_context=True) def specialization_widget(context, user_id): + user_id = int(user_id) - user = util.get_or_none(User, pk=user_id) - if user: - specializations = user.contractor_specializations.all() - else: - specializations = None + specializations = SpecializationRating.objects.select_related('specialization').filter(user_id=user_id) return { 'specializations': specializations, 'user_id': user_id, diff --git a/specializations/templates/templatetags/specializations_widget.html b/specializations/templates/templatetags/specializations_widget.html deleted file mode 100644 index 97aa3e2..0000000 --- a/specializations/templates/templatetags/specializations_widget.html +++ /dev/null @@ -1,21 +0,0 @@ -
    -

    Специализации:

    - {% for spec in specializations %} -
    - {{ spec }} - 2-й -
    - {% endfor %} -
    -{#
    #} -{#

    #} -{# Специализации:#} -{#

    #} -{#
    #} -{# Интерьеры#} -{#
    #} -{# #} -{#
    #} -{# Визуализация/3D#} -{#
    #} -{#
    #} diff --git a/users/templates/contractor_profile.html b/users/templates/contractor_profile.html index 3788420..2131095 100644 --- a/users/templates/contractor_profile.html +++ b/users/templates/contractor_profile.html @@ -28,18 +28,6 @@ -
  • - - редактировать профиль - - -
  • -
  • - - редактировать профиль - - -
  • {% endif %} {% if contractor.pk != user.id %}