|
|
|
|
@ -11,11 +11,14 @@ from django.views.generic import ListView, DetailView, CreateView, View, UpdateV |
|
|
|
|
from django.views.generic.base import ContextMixin |
|
|
|
|
from pprint import pprint, pformat |
|
|
|
|
import json |
|
|
|
|
import pydash as _; _.map = _.map_; _.filter = _.filter_ |
|
|
|
|
import pydash as _; |
|
|
|
|
|
|
|
|
|
_.map = _.map_; |
|
|
|
|
_.filter = _.filter_ |
|
|
|
|
import re |
|
|
|
|
|
|
|
|
|
from .mixins import LastAccessMixin |
|
|
|
|
from .models import Project, ProjectFile, Portfolio, PortfolioPhoto,Candidate, Answer, AnswerFile, Realty, Order |
|
|
|
|
from .models import Project, ProjectFile, Portfolio, PortfolioPhoto, Candidate, Answer, AnswerFile, Realty, Order |
|
|
|
|
from archilance.mixins import BaseMixin |
|
|
|
|
from users.models import User, Team |
|
|
|
|
from work_sell.models import Picture |
|
|
|
|
@ -57,8 +60,10 @@ class ProjectDetailWithContractorAnswerView(BaseMixin, View): |
|
|
|
|
team = None |
|
|
|
|
answer = None |
|
|
|
|
|
|
|
|
|
try: team = contractor.team |
|
|
|
|
except Team.DoesNotExist: pass |
|
|
|
|
try: |
|
|
|
|
team = contractor.team |
|
|
|
|
except Team.DoesNotExist: |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
if team: |
|
|
|
|
answer = team.answers.first() |
|
|
|
|
@ -69,7 +74,7 @@ class ProjectDetailWithContractorAnswerView(BaseMixin, View): |
|
|
|
|
if got_answer: |
|
|
|
|
context.update({'answer': answer}) |
|
|
|
|
else: |
|
|
|
|
if request.GET.get('answer_as_team') == 'on': # TODO: Check for actual possibility to answer as a team |
|
|
|
|
if request.GET.get('answer_as_team') == 'on': # TODO: Check for actual possibility to answer as a team |
|
|
|
|
context.update({'answer_as_team': True}) |
|
|
|
|
form = self.form_class(request=request, answer_as_team=True) |
|
|
|
|
else: |
|
|
|
|
@ -84,7 +89,7 @@ class ProjectDetailWithContractorAnswerView(BaseMixin, View): |
|
|
|
|
context = self.get_context_data(**kwargs) |
|
|
|
|
answer_as_team = None |
|
|
|
|
|
|
|
|
|
if request.POST.get('answer_as_team') == 'on': # TODO: Check for actual possibility to answer as a team |
|
|
|
|
if request.POST.get('answer_as_team') == 'on': # TODO: Check for actual possibility to answer as a team |
|
|
|
|
answer_as_team = True |
|
|
|
|
|
|
|
|
|
if answer_as_team: |
|
|
|
|
@ -255,7 +260,8 @@ class CustomerProjectCreateView(BaseMixin, View): |
|
|
|
|
return render(request, self.template_name, context) |
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
form = self.form_class(request.POST, request=request) # Passing `request.FILES` seems unnecessary here. Files are added manually below |
|
|
|
|
form = self.form_class(request.POST, |
|
|
|
|
request=request) # Passing `request.FILES` seems unnecessary here. Files are added manually below |
|
|
|
|
|
|
|
|
|
form.is_valid() |
|
|
|
|
realty = form.cleaned_data.get('realty') |
|
|
|
|
@ -284,7 +290,7 @@ class CustomerProjectCreateView(BaseMixin, View): |
|
|
|
|
realty.save() |
|
|
|
|
realty_form.save_m2m() |
|
|
|
|
|
|
|
|
|
project.realty = realty # Connect a realty with a project |
|
|
|
|
project.realty = realty # Connect a realty with a project |
|
|
|
|
project.save() |
|
|
|
|
|
|
|
|
|
messages.info(request, 'Проект успешно создан') |
|
|
|
|
@ -350,7 +356,8 @@ class CustomerProjectEditView(BaseMixin, View): |
|
|
|
|
if form.is_valid() and realty_form.is_valid(): |
|
|
|
|
project = form.save(commit=False) |
|
|
|
|
project.customer = request.user |
|
|
|
|
project.files = form.cleaned_data.get('files') # TODO: Should we somehow get rid of this explicit assignment? |
|
|
|
|
project.files = form.cleaned_data.get( |
|
|
|
|
'files') # TODO: Should we somehow get rid of this explicit assignment? |
|
|
|
|
project.save() |
|
|
|
|
form.save_m2m() |
|
|
|
|
|
|
|
|
|
@ -366,7 +373,7 @@ class CustomerProjectEditView(BaseMixin, View): |
|
|
|
|
realty.save() |
|
|
|
|
realty_form.save_m2m() |
|
|
|
|
|
|
|
|
|
project.realty = realty # Connect a realty with a project |
|
|
|
|
project.realty = realty # Connect a realty with a project |
|
|
|
|
project.save() |
|
|
|
|
|
|
|
|
|
messages.info(request, 'Проект успешно отредактирован') |
|
|
|
|
@ -393,7 +400,7 @@ class CustomerProjectEditView(BaseMixin, View): |
|
|
|
|
class ContractorPortfolioTrashView(View): |
|
|
|
|
form_class = ContractorPortfolioTrashForm |
|
|
|
|
|
|
|
|
|
def post(self,request, *args, **kwargs): |
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
form = self.form_class(_.merge({}, request.POST, kwargs), request=request) |
|
|
|
|
if form.is_valid(): |
|
|
|
|
portfolio = form.cleaned_data.get('pk') |
|
|
|
|
@ -405,6 +412,7 @@ class ContractorPortfolioTrashView(View): |
|
|
|
|
redirect_to = request.POST.get('next') |
|
|
|
|
return redirect(redirect_to) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomerProjectTrashView(View): |
|
|
|
|
form_class = CustomerProjectTrashForm |
|
|
|
|
|
|
|
|
|
@ -492,7 +500,23 @@ def add_candidate(request, answer_id, project_id): |
|
|
|
|
answer = Answer.objects.get(pk=answer_id) |
|
|
|
|
project = Project.objects.get(pk=project_id) |
|
|
|
|
candidate = Candidate.objects.create(answer=answer, project=project) |
|
|
|
|
return HttpResponseRedirect(reverse('projects:detail',args=[project_id])) |
|
|
|
|
return HttpResponseRedirect(reverse('projects:detail', args=[project_id])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sort_candidates(request): |
|
|
|
|
if request.is_ajax(): |
|
|
|
|
items = request.POST.getlist('items[]') |
|
|
|
|
i = 1 |
|
|
|
|
for item in items: |
|
|
|
|
candidate = Candidate.objects.get(pk=item) |
|
|
|
|
candidate.position = i |
|
|
|
|
candidate.save() |
|
|
|
|
i += 1 |
|
|
|
|
|
|
|
|
|
data = { |
|
|
|
|
'success': 'ok', |
|
|
|
|
} |
|
|
|
|
return HttpResponse(json.dumps(data), content_type='application/json') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OfferOrderView(View): |
|
|
|
|
@ -536,9 +560,10 @@ class ContractorPortfolioUpdateView(UpdateView): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from django.views.generic import DeleteView |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PortfolioDelete(DeleteView): |
|
|
|
|
model = Portfolio |
|
|
|
|
success_url = reverse_lazy('users:contractor-profile') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# import code; code.interact(local=dict(globals(), **locals())) |
|
|
|
|
|