From f43bb85af436888c90a8e8fa56c86c7c15f70ce3 Mon Sep 17 00:00:00 2001 From: ArturBaybulatov Date: Fri, 2 Sep 2016 18:03:08 +0300 Subject: [PATCH 1/2] #ARC-55 --- .../commands/generate_work_sells.py | 8 +- users/models.py | 8 +- users/templates/contractor_office.html | 13 +- users/templates/contractor_profile.html | 6 +- users/templates/team_profile.html | 517 ++++++++++++++++++ users/urls.py | 7 +- users/views.py | 46 +- work_sell/filters.py | 1 + work_sell/migrations/0010_worksell_team.py | 22 + work_sell/models.py | 1 + work_sell/serializers.py | 4 +- 11 files changed, 600 insertions(+), 33 deletions(-) create mode 100644 users/templates/team_profile.html create mode 100644 work_sell/migrations/0010_worksell_team.py diff --git a/archilance/management/commands/generate_work_sells.py b/archilance/management/commands/generate_work_sells.py index 9992356..2b565b5 100644 --- a/archilance/management/commands/generate_work_sells.py +++ b/archilance/management/commands/generate_work_sells.py @@ -9,7 +9,7 @@ from archilance import util from common.models import Location from projects.models import TERM_TYPES, CURRENCIES, BuildingClassfication, ConstructionType from specializations.models import Specialization -from users.models import User +from users.models import User, Team from work_sell.models import WorkSell, WorkSellPhoto @@ -32,7 +32,11 @@ class Command(BaseCommand): ws.save() - ws.user = User.contractor_objects.order_by('?').first() + if _.sample((True, False)): + ws.contractor = User.contractor_objects.order_by('?').first() + else: + ws.team = Team.objects.order_by('?').first() + ws.building_classification = BuildingClassfication.objects.order_by('?').first() ws.construction_type = ConstructionType.objects.order_by('?').first() ws.location = Location.objects.root_nodes()[0].get_descendants().order_by('?').first() diff --git a/users/models.py b/users/models.py index ef4187d..4f7c5c2 100644 --- a/users/models.py +++ b/users/models.py @@ -220,12 +220,16 @@ class User(AbstractBaseUser, PermissionsMixin): def get_popular_specialization(self): from ratings.models import SpecializationRating - return SpecializationRating.objects.filter(user=self).order_by('position').first().specialization.name + + rating = SpecializationRating.objects.filter(user=self).order_by('position').first() + + if rating: + return rating.specialization.name class Team(models.Model): answers = GenericRelation('projects.Answer', related_query_name='teams') - avatar = models.ImageField(upload_to='teams/avatars/', blank=True) + avatar = models.ImageField(upload_to='teams/avatars/', blank=True) # TODO: Unused field? created = models.DateTimeField(default=timezone.now) name = models.CharField(max_length=255) owner = models.OneToOneField(User, related_name='team', blank=True, null=True) diff --git a/users/templates/contractor_office.html b/users/templates/contractor_office.html index 32e4f32..ade5edf 100644 --- a/users/templates/contractor_office.html +++ b/users/templates/contractor_office.html @@ -82,7 +82,7 @@

Состав группы

- {% for c in team_members %} + {% for c in contractor.team.contractors.all %}
{% if c.avatar %} @@ -114,7 +114,7 @@