diff --git a/projects/models.py b/projects/models.py index 25b26d7..dd83ce5 100644 --- a/projects/models.py +++ b/projects/models.py @@ -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 2ab204b..7651f06 100644 --- a/projects/templates/project_detail.html +++ b/projects/templates/project_detail.html @@ -157,22 +157,16 @@ - - - - - - - - {% if False and request.user.is_contractor and request.user.contractor_answers.exists and request.user.contractor_answers.first in project.answers.all %} + {% 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' %} @@ -208,12 +208,19 @@ {% if answer.author|class_name == 'User' %} -
-
-

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

-
- {% else %} - ... + {% 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 %}
@@ -228,46 +235,31 @@

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

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

+ + + +

@@ -306,112 +302,107 @@

+ + +
- {% endwith %} - - - - - {% elif request.user.is_contractor and not request.user.contractor_answers.exists %} - - - - -
- {% 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 %} diff --git a/projects/views.py b/projects/views.py index 2ed964c..b4b6758 100644 --- a/projects/views.py +++ b/projects/views.py @@ -17,7 +17,7 @@ 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 ( @@ -45,11 +45,32 @@ class ProjectDetailWithContractorAnswerView(BaseMixin, View): project = get_object_or_404(Project, pk=kwargs.get('pk')) context.update({'project': project}) - # context.update({'tmp_answer': ...}) # Tmp - 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 +