|
|
|
|
@ -364,24 +364,42 @@ class ContractorOfficeView(DetailView): |
|
|
|
|
context_object_name = 'contractor' |
|
|
|
|
form_class = TeamForm |
|
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
|
if request.user.is_authenticated() and request.user.is_contractor() and request.user.pk == int(kwargs.get('pk')): |
|
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
|
else: |
|
|
|
|
raise PermissionDenied |
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
|
context = super().get_context_data(**kwargs) |
|
|
|
|
context['form_team'] = self.form_class |
|
|
|
|
|
|
|
|
|
if self.object.is_owner_team(): |
|
|
|
|
participants = self.object.team.contractors.all() |
|
|
|
|
context['participants'] = participants |
|
|
|
|
context['participants_count'] = len(participants) |
|
|
|
|
contractor = self.object |
|
|
|
|
|
|
|
|
|
contractors = tuple(itertools.chain(participants, (self.object,))) |
|
|
|
|
if util.get_related_or_none(contractor, 'team'): |
|
|
|
|
members = contractor.team.contractors.all() |
|
|
|
|
context['team_members'] = members |
|
|
|
|
context['team_member_count'] = len(members) |
|
|
|
|
|
|
|
|
|
portfolios = Portfolio.objects.filter(user__in=contractors) |
|
|
|
|
context['portfolios'] = portfolios |
|
|
|
|
compl_proj = [] |
|
|
|
|
portfolios = [] |
|
|
|
|
work_sells = [] |
|
|
|
|
|
|
|
|
|
compl_proj.extend(tuple(o.project for o in contractor.orders.filter(status='completed'))) |
|
|
|
|
portfolios.extend(contractor.portfolios.all()) |
|
|
|
|
work_sells.extend(contractor.work_sell.all()) |
|
|
|
|
|
|
|
|
|
for c in members: |
|
|
|
|
compl_proj.extend(tuple(o.project for o in c.orders.filter(status='completed'))) |
|
|
|
|
portfolios.extend(c.portfolios.all()) |
|
|
|
|
work_sells.extend(c.work_sell.all()) |
|
|
|
|
|
|
|
|
|
work_sells = WorkSell.objects.filter(contractor__in=contractors) |
|
|
|
|
context['completed_project_count'] = len(compl_proj) |
|
|
|
|
context['portfolios'] = portfolios |
|
|
|
|
context['work_sells'] = work_sells |
|
|
|
|
|
|
|
|
|
context['reviews'] = Review.objects.filter(target_contractor__in=contractors) |
|
|
|
|
context['reviews'] = Review.objects.filter(target_contractor__in=itertools.chain((contractor,), members)) |
|
|
|
|
|
|
|
|
|
context['form_team'] = self.form_class |
|
|
|
|
|
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|