diff --git a/archilance/management/commands/generate_users.py b/archilance/management/commands/generate_users.py index 5940f83..90ae119 100644 --- a/archilance/management/commands/generate_users.py +++ b/archilance/management/commands/generate_users.py @@ -86,6 +86,7 @@ class Command(BaseCommand): email='%s@example.com' % username, is_active=True, contractor_status=_.sample(User.STATUSES)[0], + cro=_.sample((True, False)), ) users = _.times(create_user, 500) diff --git a/projects/models.py b/projects/models.py index 4e3229a..dd83ce5 100644 --- a/projects/models.py +++ b/projects/models.py @@ -50,7 +50,7 @@ class Realty(models.Model): construction_type = models.ForeignKey(ConstructionType, related_name='realties') location = TreeForeignKey('common.Location', related_name='realties', null=True, blank=True) name = models.CharField(max_length=255) - user = models.ForeignKey(User, related_name='realties') + user = models.ForeignKey(User, related_name='realties') # Do we actually need this field? def __str__(self): return self.name @@ -133,7 +133,7 @@ class Answer(models.Model): author = GenericForeignKey('content_type', 'object_id') def __str__(self): - return self.text + return "{author}'s answer ({id})".format(author=type(self.author).__name__, id=self.pk) class Meta: verbose_name = 'Отклик на проект' diff --git a/projects/templates/project_detail.html b/projects/templates/project_detail.html index fa93c9d..7651f06 100644 --- a/projects/templates/project_detail.html +++ b/projects/templates/project_detail.html @@ -157,22 +157,16 @@ - - - - - - - - {% if request.user.is_contractor and request.user.contractor_answers.exists %} + {% if request.user.is_contractor %} + - {% with answer=request.user.contractor_answers.first %} + {% if answer %}
-
+
@@ -183,9 +177,15 @@ {% endif %}
+

- {{ answer.author.get_full_name }} [{{ answer.author.username }}] + {% if answer.author|class_name == 'User' %} + {{ answer.author.get_full_name }} [{{ answer.author.username }}] + {% elif answer.author|class_name == 'Team' %} + {{ answer.author.name }} + {% endif %}

+ {% if answer.author|class_name == 'User' %} @@ -207,10 +207,21 @@ -
-
-

Есть допуск СРО

-
+ {% if answer.author|class_name == 'User' %} + {% if answer.author.cro %} +
+
+

Есть допуск СРО

+
+ {% endif %} + {% elif answer.author|class_name == 'Team' %} +{# {% if any of these motherfuckers "answer.author.contractors.all" got a cro, then... %}#} +
+
+

Есть допуск СРО

+
+{# {% endif %}#} + {% endif %}

@@ -224,46 +235,31 @@

Опубликован: {{ answer.created }}

+ + + + +
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ {% for portf in answer.portfolios.all %} +
+
+
+
+
-
+ {% endfor %}
+ + + + +
@@ -285,6 +281,10 @@

+ + + +

@@ -302,120 +302,118 @@

+ + +
- {% endwith %} - - - - - - {% elif request.user.is_contractor %} - - - - -
- {% csrf_token %} - - -
-
-
-

Стоимость {{ form.budget.errors.as_text }}

- + {% else %} + + {% csrf_token %} + + +
+
+
+

Стоимость {{ form.budget.errors.as_text }}

+ +
+
+ +
+
+ {{ form.currency }} +
+
+ +
+
+

Срок {{ form.term.errors.as_text }}

+ +
+
+ +
+
+ {{ form.term_type }} +
-
-
- {{ form.currency }} +
+
+
+

Текст {{ form.text.errors.as_text }}

+ +
+
-
-
-

Срок {{ form.term.errors.as_text }}

- +
+
+

Портфолио {{ form.portfolios.errors.as_text }}

+ +
    + {% for p in request.user.portfolios.all %} +
  • + + + {{ p.name }} +
  • + {% endfor %} +
-
-
- {{ form.term_type }} +
+
+
+
+ Не более 10 файлов общим объемом до 500 Мб +
+ +
    + +
+
-
- -
-
-
-

Текст {{ form.text.errors.as_text }}

- + +
+
+ {{ form.secure_deal_only }} Работаю только по безопасной сделке
-
-
- -
-
-

Портфолио {{ form.portfolios.errors.as_text }}

- -
    - {% for p in request.user.portfolios.all %} -
  • - - - {{ p.name }} -
  • - {% endfor %} -
-
-
- -
-
-
-
- Не более 10 файлов общим объемом до 500 Мб -
- -
    - -
+ +
+
+
-
- -
-
- {{ form.secure_deal_only }} Работаю только по безопасной сделке -
-
- -
-
- -
-
- -
- + +
+ + {% endif %} {% elif request.user.is_customer %} - + + + + +

Исполнители

@@ -445,7 +443,16 @@

Новые исполнители

- + + + + + + + + + + {% for answer_p in project.answers.all %}
diff --git a/projects/urls.py b/projects/urls.py index c16f654..ad497a8 100644 --- a/projects/urls.py +++ b/projects/urls.py @@ -4,6 +4,7 @@ from django.views.generic import TemplateView from .views import ( add_candidate, contractor_portfolio_create, + ContractorPortfolioTrashView, ContractorPortfolioUpdateView, CustomerProjectCreateView, CustomerProjectDeleteView, @@ -12,9 +13,8 @@ from .views import ( CustomerProjectTrashView, OfferOrderView, ProjectComparisonView, - ProjectFilterView, ProjectDetailWithContractorAnswerView, - ContractorPortfolioTrashView, + ProjectFilterView, ) app_name = 'projects' diff --git a/projects/views.py b/projects/views.py index 7b4c5c3..b4b6758 100644 --- a/projects/views.py +++ b/projects/views.py @@ -17,10 +17,11 @@ import re from .mixins import LastAccessMixin from .models import Project, ProjectFile, Portfolio, PortfolioPhoto,Candidate, Answer, AnswerFile, Realty, Order from archilance.mixins import BaseMixin -from users.models import User +from users.models import User, Team from work_sell.models import Picture from .forms import ( + ContractorPortfolioTrashForm, ContractorProjectAnswerForm, CustomerProjectDeleteForm, CustomerProjectEditForm, @@ -31,7 +32,6 @@ from .forms import ( ProjectFilterForm, ProjectFilterRealtyForm, RealtyForm, - ContractorPortfolioTrashForm, ) @@ -46,8 +46,31 @@ class ProjectDetailWithContractorAnswerView(BaseMixin, View): context.update({'project': project}) if request.user.is_authenticated() and request.user.is_contractor(): - form = self.form_class(request=request) - context.update({'form': form}) + project_answers = project.answers.all() + got_answer = None + contractor = request.user + answer = contractor.contractor_answers.first() + + if answer and answer in project_answers: + got_answer = True + else: + team = None + answer = None + + try: team = contractor.team + except Team.DoesNotExist: pass + + if team: + answer = team.answers.first() + + if answer and answer in project_answers: + got_answer = True + + if got_answer: + context.update({'answer': answer}) + else: + form = self.form_class(request=request) + context.update({'form': form}) return render(request, self.template_name, context) diff --git a/templates/trash/contractor_project-detail.html b/templates/trash/contractor_project-detail.html index 04cd064..7946573 100644 --- a/templates/trash/contractor_project-detail.html +++ b/templates/trash/contractor_project-detail.html @@ -231,6 +231,18 @@ отказ
+ + + + + + + + + + + +
@@ -352,4 +364,4 @@ - \ No newline at end of file +