From 00cbebac06aa4b2065422a73a856f5bf16eabffd Mon Sep 17 00:00:00 2001 From: Mukhtar Date: Thu, 22 Sep 2016 21:08:02 +0300 Subject: [PATCH] fixes count and review errors --- assets/js/chat.js | 2 +- projects/forms.py | 5 +++-- reviews/serializers.py | 5 +++++ .../partials/customer_profile_info_block.html | 3 ++- users/templatetags/user_tags.py | 10 ++++++++++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/assets/js/chat.js b/assets/js/chat.js index 66235c7..0be9e0f 100644 --- a/assets/js/chat.js +++ b/assets/js/chat.js @@ -781,7 +781,7 @@ function dialog (message, yesCallback, notCallback) { console.log(json); $("#review-add").modal('hide'); $("#leaveReview").hide(); - var currOrder = json.project; + var currOrder = json.order; var currRecipent = json.target_user; socket.send_stages_approve({ diff --git a/projects/forms.py b/projects/forms.py index 7beb824..b53ba53 100644 --- a/projects/forms.py +++ b/projects/forms.py @@ -83,6 +83,7 @@ class ProjectFilterRealtyForm(forms.ModelForm): self.fields['construction_type'].required = False self.fields['location'].queryset = Location.objects.root_nodes()[0].get_descendants() + self.fields['building_classification'].queryset = BuildingClassfication.objects.root_nodes()[0].get_descendants() # self.fields['location'].queryset = Location.objects # Migrate with this enabled @@ -150,8 +151,8 @@ class CustomerProjectEditForm(forms.ModelForm): class RealtyForm(forms.ModelForm): building_classification = TreeNodeChoiceField( - BuildingClassfication.objects.all(), - label="", initial='', + BuildingClassfication.objects.exclude(name='_root'), + label="ll", initial='', widget=forms.Select(attrs={ 'class': 'selectpicker', 'id': 'realtyBuildingClassificationId' diff --git a/reviews/serializers.py b/reviews/serializers.py index e985c86..99dadee 100644 --- a/reviews/serializers.py +++ b/reviews/serializers.py @@ -7,6 +7,7 @@ from users.serializers import UserSerializer, TeamSerializer class ReviewSerializer(ModelSerializer): target_user = serializers.SerializerMethodField(read_only=True) + order = serializers.SerializerMethodField(read_only=True) class Meta: model = Review @@ -24,8 +25,12 @@ class ReviewSerializer(ModelSerializer): 'target_contractor', 'target_team', 'target_user', + 'order', ) + def get_order(self, obj): + return obj.project.order.pk + def get_target_user(self, obj): if obj.target_customer: return obj.target_customer.pk diff --git a/users/templates/partials/customer_profile_info_block.html b/users/templates/partials/customer_profile_info_block.html index 9438eb7..6599542 100644 --- a/users/templates/partials/customer_profile_info_block.html +++ b/users/templates/partials/customer_profile_info_block.html @@ -1,5 +1,6 @@ {% load specializtions_tags %} {% load thumbnail %} +{% load user_tags %}
@@ -68,7 +69,7 @@ Отзывы
-
0
+
{% get_reviews_count request.user %}
diff --git a/users/templatetags/user_tags.py b/users/templatetags/user_tags.py index 4130f67..c055723 100644 --- a/users/templatetags/user_tags.py +++ b/users/templatetags/user_tags.py @@ -1,6 +1,7 @@ import math from django import template from chat.models import NewMessage +from reviews.models import Review register = template.Library() @@ -84,3 +85,12 @@ def get_new_count_for_team(current_user, team_id, order_id=None): return count +@register.simple_tag +def get_reviews_count(user): + if user.is_customer(): + count = Review.objects.filter(target_customer=user).count() + else: + count = Review.objects.filter(target_contractor=user).count() + return count + +