|
|
|
@ -43,78 +43,78 @@ from .forms import ( |
|
|
|
class ProjectDetailWithAnswerView(BaseMixin, View): |
|
|
|
class ProjectDetailWithAnswerView(BaseMixin, View): |
|
|
|
form_class = ProjectAnswerForm |
|
|
|
form_class = ProjectAnswerForm |
|
|
|
template_name = 'project_detail.html' |
|
|
|
template_name = 'project_detail.html' |
|
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
context = self.get_context_data(**_.merge({}, request.GET, kwargs)) |
|
|
|
context = self.get_context_data(**_.merge({}, request.GET, kwargs)) |
|
|
|
|
|
|
|
|
|
|
|
project = get_object_or_404(Project, pk=kwargs.get('pk')) |
|
|
|
project = get_object_or_404(Project, pk=kwargs.get('pk')) |
|
|
|
context.update({'project': project}) |
|
|
|
context.update({'project': project}) |
|
|
|
|
|
|
|
|
|
|
|
hit_count = HitCount.objects.get_for_object(project) |
|
|
|
hit_count = HitCount.objects.get_for_object(project) |
|
|
|
HitCountMixin.hit_count(request, hit_count) |
|
|
|
HitCountMixin.hit_count(request, hit_count) |
|
|
|
|
|
|
|
|
|
|
|
if request.user.is_authenticated() and request.user.is_contractor(): |
|
|
|
if request.user.is_authenticated() and request.user.is_contractor(): |
|
|
|
project_answers = project.answers.filter(rejected=False) |
|
|
|
project_answers = project.answers.filter(rejected=False) |
|
|
|
contractor = request.user |
|
|
|
contractor = request.user |
|
|
|
|
|
|
|
|
|
|
|
answer = _.first(_.filter(project_answers, lambda a: a.author == contractor)) |
|
|
|
answer = _.first(_.filter(project_answers, lambda a: a.author == contractor)) |
|
|
|
|
|
|
|
|
|
|
|
if not answer: |
|
|
|
if not answer: |
|
|
|
try: team = contractor.team |
|
|
|
try: team = contractor.team |
|
|
|
except Team.DoesNotExist: team = None |
|
|
|
except Team.DoesNotExist: team = None |
|
|
|
|
|
|
|
|
|
|
|
if team: |
|
|
|
if team: |
|
|
|
answer = _.first(_.filter(project_answers, lambda a: a.author == team)) |
|
|
|
answer = _.first(_.filter(project_answers, lambda a: a.author == team)) |
|
|
|
|
|
|
|
|
|
|
|
context.update({'answer': answer}) |
|
|
|
context.update({'answer': answer}) |
|
|
|
|
|
|
|
|
|
|
|
if not answer: |
|
|
|
if not answer: |
|
|
|
try: contractor.team; context.update({'can_answer_as_team': True}) |
|
|
|
try: contractor.team; context.update({'can_answer_as_team': True}) |
|
|
|
except Team.DoesNotExist: pass |
|
|
|
except Team.DoesNotExist: pass |
|
|
|
|
|
|
|
|
|
|
|
if request.GET.get('answer_as_team') == 'on': |
|
|
|
if request.GET.get('answer_as_team') == 'on': |
|
|
|
context.update({'answer_as_team': True}) |
|
|
|
context.update({'answer_as_team': True}) |
|
|
|
form = self.form_class(request=request, answer_as_team=True, project=project) |
|
|
|
form = self.form_class(request=request, answer_as_team=True, project=project) |
|
|
|
else: |
|
|
|
else: |
|
|
|
form = self.form_class(request=request, project=project) |
|
|
|
form = self.form_class(request=request, project=project) |
|
|
|
|
|
|
|
|
|
|
|
context.update({'form': form}) |
|
|
|
context.update({'form': form}) |
|
|
|
|
|
|
|
|
|
|
|
return render(request, self.template_name, context) |
|
|
|
return render(request, self.template_name, context) |
|
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
if request.user.is_authenticated() and request.user.is_contractor(): |
|
|
|
if request.user.is_authenticated() and request.user.is_contractor(): |
|
|
|
context = self.get_context_data(**kwargs) |
|
|
|
context = self.get_context_data(**kwargs) |
|
|
|
answer_as_team = None |
|
|
|
answer_as_team = None |
|
|
|
project = get_object_or_404(Project, pk=kwargs.get('pk')) # TODO: Does this work? |
|
|
|
project = get_object_or_404(Project, pk=kwargs.get('pk')) # TODO: Does this work? |
|
|
|
|
|
|
|
|
|
|
|
if request.POST.get('answer_as_team') == 'on': |
|
|
|
if request.POST.get('answer_as_team') == 'on': |
|
|
|
answer_as_team = True |
|
|
|
answer_as_team = True |
|
|
|
|
|
|
|
|
|
|
|
if answer_as_team: |
|
|
|
if answer_as_team: |
|
|
|
form = self.form_class(request.POST, request=request, answer_as_team=True, project=project) |
|
|
|
form = self.form_class(request.POST, request=request, answer_as_team=True, project=project) |
|
|
|
else: |
|
|
|
else: |
|
|
|
form = self.form_class(request.POST, request=request, project=project) |
|
|
|
form = self.form_class(request.POST, request=request, project=project) |
|
|
|
|
|
|
|
|
|
|
|
project = get_object_or_404(Project, pk=kwargs.get('pk')) |
|
|
|
project = get_object_or_404(Project, pk=kwargs.get('pk')) |
|
|
|
context.update({'project': project}) |
|
|
|
context.update({'project': project}) |
|
|
|
|
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
if form.is_valid(): |
|
|
|
answer = form.save(commit=False) |
|
|
|
answer = form.save(commit=False) |
|
|
|
answer.project = project |
|
|
|
answer.project = project |
|
|
|
answer.author = request.user.team if answer_as_team else request.user |
|
|
|
answer.author = request.user.team if answer_as_team else request.user |
|
|
|
answer.save() |
|
|
|
answer.save() |
|
|
|
form.save_m2m() |
|
|
|
form.save_m2m() |
|
|
|
|
|
|
|
|
|
|
|
for file in request.FILES.getlist('new_files'): |
|
|
|
for file in request.FILES.getlist('new_files'): |
|
|
|
if len(file.name) <= 255: |
|
|
|
if len(file.name) <= 255: |
|
|
|
AnswerFile.objects.create(file=file, name=file.name, answer=answer) |
|
|
|
AnswerFile.objects.create(file=file, name=file.name, answer=answer) |
|
|
|
|
|
|
|
|
|
|
|
message = AnswerMessage(text=form.cleaned_data.get('text'), is_sender_customer=False) |
|
|
|
message = AnswerMessage(text=form.cleaned_data.get('text'), is_sender_customer=False) |
|
|
|
message.answer = answer |
|
|
|
message.answer = answer |
|
|
|
message.contractor_or_team = answer.author |
|
|
|
message.contractor_or_team = answer.author |
|
|
|
message.save() |
|
|
|
message.save() |
|
|
|
|
|
|
|
|
|
|
|
messages.info(request, 'Отклик успешно размещён') |
|
|
|
messages.info(request, 'Отклик успешно размещён') |
|
|
|
redirect_to = request.POST.get('next') |
|
|
|
redirect_to = request.POST.get('next') |
|
|
|
return redirect(redirect_to) |
|
|
|
return redirect(redirect_to) |
|
|
|
@ -124,7 +124,7 @@ class ProjectDetailWithAnswerView(BaseMixin, View): |
|
|
|
'<p>Произошла ошибка (form)</p>' |
|
|
|
'<p>Произошла ошибка (form)</p>' |
|
|
|
'<pre>{form}</pre>' |
|
|
|
'<pre>{form}</pre>' |
|
|
|
).format(form=pformat(form.errors))) |
|
|
|
).format(form=pformat(form.errors))) |
|
|
|
|
|
|
|
|
|
|
|
context.update({'form': form}) |
|
|
|
context.update({'form': form}) |
|
|
|
return render(request, self.template_name, context) |
|
|
|
return render(request, self.template_name, context) |
|
|
|
else: |
|
|
|
else: |
|
|
|
@ -133,41 +133,41 @@ class ProjectDetailWithAnswerView(BaseMixin, View): |
|
|
|
|
|
|
|
|
|
|
|
class ProjectAnswerCreateMessageView(BaseMixin, View): |
|
|
|
class ProjectAnswerCreateMessageView(BaseMixin, View): |
|
|
|
form_class = ProjectAnswerMessageForm |
|
|
|
form_class = ProjectAnswerMessageForm |
|
|
|
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
if request.user.is_authenticated(): |
|
|
|
if request.user.is_authenticated(): |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
else: |
|
|
|
else: |
|
|
|
return HttpResponseForbidden('403 Forbidden') |
|
|
|
return HttpResponseForbidden('403 Forbidden') |
|
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
form = self.form_class(request.POST, request=request) |
|
|
|
form = self.form_class(request.POST, request=request) |
|
|
|
|
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
if form.is_valid(): |
|
|
|
message = form.save(commit=False) |
|
|
|
message = form.save(commit=False) |
|
|
|
|
|
|
|
|
|
|
|
if request.user.is_contractor(): |
|
|
|
if request.user.is_contractor(): |
|
|
|
answer = get_object_or_404(Answer, pk=kwargs.get('pk')) |
|
|
|
answer = get_object_or_404(Answer, pk=kwargs.get('pk')) |
|
|
|
|
|
|
|
|
|
|
|
message.answer = answer |
|
|
|
message.answer = answer |
|
|
|
message.is_sender_customer = False |
|
|
|
message.is_sender_customer = False |
|
|
|
|
|
|
|
|
|
|
|
if isinstance(answer.author, User) and answer.author == request.user: |
|
|
|
if isinstance(answer.author, User) and answer.author == request.user: |
|
|
|
message.contractor_or_team = request.user |
|
|
|
message.contractor_or_team = request.user |
|
|
|
elif isinstance(answer.author, Team): |
|
|
|
elif isinstance(answer.author, Team): |
|
|
|
try: team = request.user.team |
|
|
|
try: team = request.user.team |
|
|
|
except Team.DoesNotExist: team = None |
|
|
|
except Team.DoesNotExist: team = None |
|
|
|
|
|
|
|
|
|
|
|
if team and answer.author == team: |
|
|
|
if team and answer.author == team: |
|
|
|
message.contractor_or_team = team |
|
|
|
message.contractor_or_team = team |
|
|
|
elif request.user.is_customer(): |
|
|
|
elif request.user.is_customer(): |
|
|
|
answer = get_object_or_404(Answer, pk=kwargs.get('pk')) # TODO: Perform additional checks |
|
|
|
answer = get_object_or_404(Answer, pk=kwargs.get('pk')) # TODO: Perform additional checks |
|
|
|
message.answer = answer |
|
|
|
message.answer = answer |
|
|
|
message.is_sender_customer = True |
|
|
|
message.is_sender_customer = True |
|
|
|
|
|
|
|
|
|
|
|
message.save() |
|
|
|
message.save() |
|
|
|
form.save_m2m() |
|
|
|
form.save_m2m() |
|
|
|
|
|
|
|
|
|
|
|
messages.info(request, 'Сообщение успешно размещено') |
|
|
|
messages.info(request, 'Сообщение успешно размещено') |
|
|
|
else: |
|
|
|
else: |
|
|
|
if form.errors: |
|
|
|
if form.errors: |
|
|
|
@ -175,7 +175,7 @@ class ProjectAnswerCreateMessageView(BaseMixin, View): |
|
|
|
'<p>Произошла ошибка (form)</p>' |
|
|
|
'<p>Произошла ошибка (form)</p>' |
|
|
|
'<pre>{form}</pre>' |
|
|
|
'<pre>{form}</pre>' |
|
|
|
).format(form=pformat(form.errors))) |
|
|
|
).format(form=pformat(form.errors))) |
|
|
|
|
|
|
|
|
|
|
|
redirect_to = request.POST.get('next') |
|
|
|
redirect_to = request.POST.get('next') |
|
|
|
return redirect(redirect_to) |
|
|
|
return redirect(redirect_to) |
|
|
|
|
|
|
|
|
|
|
|
@ -186,19 +186,19 @@ class RejectProjectAnswerView(BaseMixin, View): |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
else: |
|
|
|
else: |
|
|
|
raise PermissionDenied |
|
|
|
raise PermissionDenied |
|
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
if request.user.is_contractor(): |
|
|
|
if request.user.is_contractor(): |
|
|
|
answer = get_object_or_404(request.user.contractor_answers, pk=kwargs.get('pk')) |
|
|
|
answer = get_object_or_404(request.user.contractor_answers, pk=kwargs.get('pk')) |
|
|
|
elif request.user.is_customer(): |
|
|
|
elif request.user.is_customer(): |
|
|
|
project = get_object_or_404(request.user.projects, answers__pk=kwargs.get('pk')) |
|
|
|
project = get_object_or_404(request.user.projects, answers__pk=kwargs.get('pk')) |
|
|
|
answer = get_object_or_404(project.answers, pk=kwargs.get('pk')) |
|
|
|
answer = get_object_or_404(project.answers, pk=kwargs.get('pk')) |
|
|
|
|
|
|
|
|
|
|
|
answer.rejected = True |
|
|
|
answer.rejected = True |
|
|
|
answer.save() |
|
|
|
answer.save() |
|
|
|
|
|
|
|
|
|
|
|
messages.info(request, 'Успешный отказ от проекта') |
|
|
|
messages.info(request, 'Успешный отказ от проекта') |
|
|
|
|
|
|
|
|
|
|
|
redirect_to = request.POST.get('next') |
|
|
|
redirect_to = request.POST.get('next') |
|
|
|
return redirect(redirect_to) |
|
|
|
return redirect(redirect_to) |
|
|
|
|
|
|
|
|
|
|
|
@ -207,107 +207,107 @@ class ProjectFilterView(BaseMixin, View): |
|
|
|
template_name = 'project_filter.html' |
|
|
|
template_name = 'project_filter.html' |
|
|
|
form_class = ProjectFilterForm |
|
|
|
form_class = ProjectFilterForm |
|
|
|
realty_form = ProjectFilterRealtyForm |
|
|
|
realty_form = ProjectFilterRealtyForm |
|
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
form = self.form_class(request.GET, request=request) |
|
|
|
form = self.form_class(request.GET, request=request) |
|
|
|
realty_form = self.realty_form(request.GET, request=request, prefix='realty_form') |
|
|
|
realty_form = self.realty_form(request.GET, request=request, prefix='realty_form') |
|
|
|
context = self.get_context_data(**_.merge({}, request.GET, kwargs)) |
|
|
|
context = self.get_context_data(**_.merge({}, request.GET, kwargs)) |
|
|
|
|
|
|
|
|
|
|
|
projects = Project.objects |
|
|
|
projects = Project.objects |
|
|
|
|
|
|
|
|
|
|
|
if form.is_valid() and realty_form.is_valid(): |
|
|
|
if form.is_valid() and realty_form.is_valid(): |
|
|
|
ord = None |
|
|
|
ord = None |
|
|
|
|
|
|
|
|
|
|
|
keywords = form.cleaned_data.get('keywords') |
|
|
|
keywords = form.cleaned_data.get('keywords') |
|
|
|
cro = form.cleaned_data.get('cro') |
|
|
|
cro = form.cleaned_data.get('cro') |
|
|
|
work_type = form.cleaned_data.get('work_type') |
|
|
|
work_type = form.cleaned_data.get('work_type') |
|
|
|
specialization = form.cleaned_data.get('specialization') |
|
|
|
specialization = form.cleaned_data.get('specialization') |
|
|
|
|
|
|
|
|
|
|
|
building_classification = realty_form.cleaned_data.get('building_classification') |
|
|
|
building_classification = realty_form.cleaned_data.get('building_classification') |
|
|
|
construction_type = realty_form.cleaned_data.get('construction_type') |
|
|
|
construction_type = realty_form.cleaned_data.get('construction_type') |
|
|
|
location = realty_form.cleaned_data.get('location') |
|
|
|
location = realty_form.cleaned_data.get('location') |
|
|
|
|
|
|
|
|
|
|
|
if keywords: |
|
|
|
if keywords: |
|
|
|
keywords = tuple(filter(None, re.split(r'\s|,|;', keywords))) |
|
|
|
keywords = tuple(filter(None, re.split(r'\s|,|;', keywords))) |
|
|
|
|
|
|
|
|
|
|
|
for k in keywords: |
|
|
|
for k in keywords: |
|
|
|
projects = projects.filter(Q(name__icontains=k) | Q(text__icontains=k)) |
|
|
|
projects = projects.filter(Q(name__icontains=k) | Q(text__icontains=k)) |
|
|
|
|
|
|
|
|
|
|
|
if cro: |
|
|
|
if cro: |
|
|
|
projects = projects.filter(cro=cro) |
|
|
|
projects = projects.filter(cro=cro) |
|
|
|
|
|
|
|
|
|
|
|
if work_type: |
|
|
|
if work_type: |
|
|
|
projects = projects.filter(work_type=work_type) |
|
|
|
projects = projects.filter(work_type=work_type) |
|
|
|
|
|
|
|
|
|
|
|
if specialization: |
|
|
|
if specialization: |
|
|
|
projects = projects.filter( |
|
|
|
projects = projects.filter( |
|
|
|
specialization__lft__gte=specialization.lft, |
|
|
|
specialization__lft__gte=specialization.lft, |
|
|
|
specialization__rght__lte=specialization.rght, |
|
|
|
specialization__rght__lte=specialization.rght, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if building_classification: |
|
|
|
if building_classification: |
|
|
|
projects = projects.filter(realty__building_classification=building_classification) |
|
|
|
projects = projects.filter(realty__building_classification=building_classification) |
|
|
|
|
|
|
|
|
|
|
|
if construction_type: |
|
|
|
if construction_type: |
|
|
|
projects = projects.filter(realty__construction_type=construction_type) |
|
|
|
projects = projects.filter(realty__construction_type=construction_type) |
|
|
|
|
|
|
|
|
|
|
|
if location: |
|
|
|
if location: |
|
|
|
projects = projects.filter( |
|
|
|
projects = projects.filter( |
|
|
|
realty__location__lft__gte=location.lft, |
|
|
|
realty__location__lft__gte=location.lft, |
|
|
|
realty__location__rght__lte=location.rght, |
|
|
|
realty__location__rght__lte=location.rght, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
order_by = form.cleaned_data.get('order_by') |
|
|
|
order_by = form.cleaned_data.get('order_by') |
|
|
|
last_order_by = form.cleaned_data.get('last_order_by') |
|
|
|
last_order_by = form.cleaned_data.get('last_order_by') |
|
|
|
reverse_order = form.cleaned_data.get('reverse_order') |
|
|
|
reverse_order = form.cleaned_data.get('reverse_order') |
|
|
|
|
|
|
|
|
|
|
|
if order_by: |
|
|
|
if order_by: |
|
|
|
reverse_order = not reverse_order if order_by == last_order_by else False |
|
|
|
reverse_order = not reverse_order if order_by == last_order_by else False |
|
|
|
ord = order_by |
|
|
|
ord = order_by |
|
|
|
last_order_by = ord |
|
|
|
last_order_by = ord |
|
|
|
elif last_order_by: |
|
|
|
elif last_order_by: |
|
|
|
ord = last_order_by |
|
|
|
ord = last_order_by |
|
|
|
|
|
|
|
|
|
|
|
manual_sort = None |
|
|
|
manual_sort = None |
|
|
|
|
|
|
|
|
|
|
|
if ord and ord == 'views': |
|
|
|
if ord and ord == 'views': |
|
|
|
projects = natsort.natsorted(projects.all(), key=lambda p: p.hit_count.hits, reverse=reverse_order) |
|
|
|
projects = natsort.natsorted(projects.all(), key=lambda p: p.hit_count.hits, reverse=reverse_order) |
|
|
|
manual_sort = True |
|
|
|
manual_sort = True |
|
|
|
elif ord: |
|
|
|
elif ord: |
|
|
|
projects = projects.order_by('-%s' % ord if reverse_order else ord) |
|
|
|
projects = projects.order_by('-%s' % ord if reverse_order else ord) |
|
|
|
|
|
|
|
|
|
|
|
context.update({ |
|
|
|
context.update({ |
|
|
|
'last_order_by': last_order_by, |
|
|
|
'last_order_by': last_order_by, |
|
|
|
'reverse_order': reverse_order, |
|
|
|
'reverse_order': reverse_order, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
project_count = len(projects) if manual_sort else projects.count() |
|
|
|
project_count = len(projects) if manual_sort else projects.count() |
|
|
|
display_msg = 'Найдено %s проектов' % project_count if project_count > 0 else 'Ничего не найдено' |
|
|
|
display_msg = 'Найдено %s проектов' % project_count if project_count > 0 else 'Ничего не найдено' |
|
|
|
else: |
|
|
|
else: |
|
|
|
display_msg = 'Пожалуйста, введите корректные данные' |
|
|
|
display_msg = 'Пожалуйста, введите корректные данные' |
|
|
|
|
|
|
|
|
|
|
|
if form.errors: |
|
|
|
if form.errors: |
|
|
|
messages.info(request, ( |
|
|
|
messages.info(request, ( |
|
|
|
'<p>Произошла ошибка (form)</p>' |
|
|
|
'<p>Произошла ошибка (form)</p>' |
|
|
|
'<pre>{form}</pre>' |
|
|
|
'<pre>{form}</pre>' |
|
|
|
).format(form=pformat(form.errors))) |
|
|
|
).format(form=pformat(form.errors))) |
|
|
|
|
|
|
|
|
|
|
|
if realty_form and realty_form.errors: |
|
|
|
if realty_form and realty_form.errors: |
|
|
|
messages.info(request, ( |
|
|
|
messages.info(request, ( |
|
|
|
'<p>Произошла ошибка (realty_form)</p>' |
|
|
|
'<p>Произошла ошибка (realty_form)</p>' |
|
|
|
'<pre>{realty_form}</pre>' |
|
|
|
'<pre>{realty_form}</pre>' |
|
|
|
).format(realty_form=pformat(realty_form.errors))) |
|
|
|
).format(realty_form=pformat(realty_form.errors))) |
|
|
|
|
|
|
|
|
|
|
|
paginator = Paginator(projects if manual_sort else projects.all(), settings.PAGE_SIZE) |
|
|
|
paginator = Paginator(projects if manual_sort else projects.all(), settings.PAGE_SIZE) |
|
|
|
page = request.GET.get('page') |
|
|
|
page = request.GET.get('page') |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
projects = paginator.page(page) |
|
|
|
projects = paginator.page(page) |
|
|
|
except PageNotAnInteger: |
|
|
|
except PageNotAnInteger: |
|
|
|
projects = paginator.page(1) |
|
|
|
projects = paginator.page(1) |
|
|
|
except EmptyPage: |
|
|
|
except EmptyPage: |
|
|
|
projects = paginator.page(paginator.num_pages) |
|
|
|
projects = paginator.page(paginator.num_pages) |
|
|
|
|
|
|
|
|
|
|
|
context.update({ |
|
|
|
context.update({ |
|
|
|
'form': form, |
|
|
|
'form': form, |
|
|
|
'realty_form': realty_form, |
|
|
|
'realty_form': realty_form, |
|
|
|
@ -316,7 +316,7 @@ class ProjectFilterView(BaseMixin, View): |
|
|
|
'page_obj': projects, |
|
|
|
'page_obj': projects, |
|
|
|
'display_msg': display_msg, |
|
|
|
'display_msg': display_msg, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return render(request, self.template_name, context) |
|
|
|
return render(request, self.template_name, context) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -324,44 +324,44 @@ class CustomerProjectCreateView(BaseMixin, View): |
|
|
|
form_class = CustomerProjectEditForm |
|
|
|
form_class = CustomerProjectEditForm |
|
|
|
realty_form = RealtyForm |
|
|
|
realty_form = RealtyForm |
|
|
|
template_name = 'customer_project_create.html' |
|
|
|
template_name = 'customer_project_create.html' |
|
|
|
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
if request.user.is_authenticated() and request.user.is_customer(): |
|
|
|
if request.user.is_authenticated() and request.user.is_customer(): |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
else: |
|
|
|
else: |
|
|
|
raise PermissionDenied |
|
|
|
raise PermissionDenied |
|
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
form = self.form_class(request=request) |
|
|
|
form = self.form_class(request=request) |
|
|
|
realty_form = self.realty_form(request=request, prefix='realty_form') |
|
|
|
realty_form = self.realty_form(request=request, prefix='realty_form') |
|
|
|
|
|
|
|
|
|
|
|
context = self.get_context_data(**_.merge({}, request.GET, kwargs)) |
|
|
|
context = self.get_context_data(**_.merge({}, request.GET, kwargs)) |
|
|
|
context.update({'form': form, 'realty_form': realty_form}) |
|
|
|
context.update({'form': form, 'realty_form': realty_form}) |
|
|
|
|
|
|
|
|
|
|
|
return render(request, self.template_name, context) |
|
|
|
return render(request, self.template_name, context) |
|
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
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() |
|
|
|
form.is_valid() |
|
|
|
realty = form.cleaned_data.get('realty') |
|
|
|
realty = form.cleaned_data.get('realty') |
|
|
|
|
|
|
|
|
|
|
|
if realty: |
|
|
|
if realty: |
|
|
|
realty_form = self.realty_form(request.POST, instance=realty, request=request, prefix='realty_form') |
|
|
|
realty_form = self.realty_form(request.POST, instance=realty, request=request, prefix='realty_form') |
|
|
|
else: |
|
|
|
else: |
|
|
|
realty_form = self.realty_form(request.POST, request=request, prefix='realty_form') |
|
|
|
realty_form = self.realty_form(request.POST, request=request, prefix='realty_form') |
|
|
|
|
|
|
|
|
|
|
|
if form.is_valid() and realty_form.is_valid(): |
|
|
|
if form.is_valid() and realty_form.is_valid(): |
|
|
|
project = form.save(commit=False) |
|
|
|
project = form.save(commit=False) |
|
|
|
project.customer = request.user |
|
|
|
project.customer = request.user |
|
|
|
project.save() |
|
|
|
project.save() |
|
|
|
form.save_m2m() |
|
|
|
form.save_m2m() |
|
|
|
|
|
|
|
|
|
|
|
Order.objects.create(project=project) |
|
|
|
Order.objects.create(project=project) |
|
|
|
|
|
|
|
|
|
|
|
for file in request.FILES.getlist('new_files'): |
|
|
|
for file in request.FILES.getlist('new_files'): |
|
|
|
ProjectFile.objects.create(file=file, project=project) |
|
|
|
ProjectFile.objects.create(file=file, project=project) |
|
|
|
|
|
|
|
|
|
|
|
if realty: |
|
|
|
if realty: |
|
|
|
realty_form.save() |
|
|
|
realty_form.save() |
|
|
|
else: |
|
|
|
else: |
|
|
|
@ -369,10 +369,10 @@ class CustomerProjectCreateView(BaseMixin, View): |
|
|
|
realty.user = request.user |
|
|
|
realty.user = request.user |
|
|
|
realty.save() |
|
|
|
realty.save() |
|
|
|
realty_form.save_m2m() |
|
|
|
realty_form.save_m2m() |
|
|
|
|
|
|
|
|
|
|
|
project.realty = realty # Connect a realty with a project |
|
|
|
project.realty = realty # Connect a realty with a project |
|
|
|
project.save() |
|
|
|
project.save() |
|
|
|
|
|
|
|
|
|
|
|
messages.info(request, 'Проект успешно создан') |
|
|
|
messages.info(request, 'Проект успешно создан') |
|
|
|
redirect_to = reverse('projects:detail', kwargs={'pk': project.pk}) |
|
|
|
redirect_to = reverse('projects:detail', kwargs={'pk': project.pk}) |
|
|
|
return redirect(redirect_to) |
|
|
|
return redirect(redirect_to) |
|
|
|
@ -382,13 +382,13 @@ class CustomerProjectCreateView(BaseMixin, View): |
|
|
|
'<p>Произошла ошибка (form)</p>' |
|
|
|
'<p>Произошла ошибка (form)</p>' |
|
|
|
'<pre>{form}</pre>' |
|
|
|
'<pre>{form}</pre>' |
|
|
|
).format(form=pformat(form.errors))) |
|
|
|
).format(form=pformat(form.errors))) |
|
|
|
|
|
|
|
|
|
|
|
if realty_form and realty_form.errors: |
|
|
|
if realty_form and realty_form.errors: |
|
|
|
messages.info(request, ( |
|
|
|
messages.info(request, ( |
|
|
|
'<p>Произошла ошибка (realty_form)</p>' |
|
|
|
'<p>Произошла ошибка (realty_form)</p>' |
|
|
|
'<pre>{realty_form}</pre>' |
|
|
|
'<pre>{realty_form}</pre>' |
|
|
|
).format(realty_form=pformat(realty_form.errors))) |
|
|
|
).format(realty_form=pformat(realty_form.errors))) |
|
|
|
|
|
|
|
|
|
|
|
context = self.get_context_data(**kwargs) |
|
|
|
context = self.get_context_data(**kwargs) |
|
|
|
context.update({'form': form, 'realty_form': realty_form}) |
|
|
|
context.update({'form': form, 'realty_form': realty_form}) |
|
|
|
return render(request, self.template_name, context) |
|
|
|
return render(request, self.template_name, context) |
|
|
|
@ -398,52 +398,52 @@ class CustomerProjectEditView(BaseMixin, View): |
|
|
|
form_class = CustomerProjectEditForm |
|
|
|
form_class = CustomerProjectEditForm |
|
|
|
realty_form = RealtyForm |
|
|
|
realty_form = RealtyForm |
|
|
|
template_name = 'customer_project_edit.html' |
|
|
|
template_name = 'customer_project_edit.html' |
|
|
|
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
if request.user.is_authenticated() and request.user.is_customer(): |
|
|
|
if request.user.is_authenticated() and request.user.is_customer(): |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
else: |
|
|
|
else: |
|
|
|
return HttpResponseForbidden('403 Forbidden') |
|
|
|
return HttpResponseForbidden('403 Forbidden') |
|
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
project = get_object_or_404(request.user.projects, pk=kwargs.get('pk')) |
|
|
|
project = get_object_or_404(request.user.projects, pk=kwargs.get('pk')) |
|
|
|
form = self.form_class(instance=project, request=request) |
|
|
|
form = self.form_class(instance=project, request=request) |
|
|
|
|
|
|
|
|
|
|
|
realty = project.realty |
|
|
|
realty = project.realty |
|
|
|
|
|
|
|
|
|
|
|
if realty: |
|
|
|
if realty: |
|
|
|
realty_form = self.realty_form(instance=project.realty, request=request, prefix='realty_form') |
|
|
|
realty_form = self.realty_form(instance=project.realty, request=request, prefix='realty_form') |
|
|
|
else: |
|
|
|
else: |
|
|
|
realty_form = self.realty_form(request=request, prefix='realty_form') |
|
|
|
realty_form = self.realty_form(request=request, prefix='realty_form') |
|
|
|
|
|
|
|
|
|
|
|
context = self.get_context_data(**_.merge({}, request.GET, kwargs)) |
|
|
|
context = self.get_context_data(**_.merge({}, request.GET, kwargs)) |
|
|
|
context.update({'form': form, 'realty_form': realty_form}) |
|
|
|
context.update({'form': form, 'realty_form': realty_form}) |
|
|
|
|
|
|
|
|
|
|
|
return render(request, self.template_name, context) |
|
|
|
return render(request, self.template_name, context) |
|
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
project = get_object_or_404(request.user.projects, pk=kwargs.get('pk')) |
|
|
|
project = get_object_or_404(request.user.projects, pk=kwargs.get('pk')) |
|
|
|
form = self.form_class(request.POST, request.FILES, request=request, instance=project) |
|
|
|
form = self.form_class(request.POST, request.FILES, request=request, instance=project) |
|
|
|
|
|
|
|
|
|
|
|
form.is_valid() |
|
|
|
form.is_valid() |
|
|
|
realty = form.cleaned_data.get('realty') |
|
|
|
realty = form.cleaned_data.get('realty') |
|
|
|
|
|
|
|
|
|
|
|
if realty: |
|
|
|
if realty: |
|
|
|
realty_form = self.realty_form(request.POST, instance=realty, request=request, prefix='realty_form') |
|
|
|
realty_form = self.realty_form(request.POST, instance=realty, request=request, prefix='realty_form') |
|
|
|
else: |
|
|
|
else: |
|
|
|
realty_form = self.realty_form(request.POST, request=request, prefix='realty_form') |
|
|
|
realty_form = self.realty_form(request.POST, request=request, prefix='realty_form') |
|
|
|
|
|
|
|
|
|
|
|
if form.is_valid() and realty_form.is_valid(): |
|
|
|
if form.is_valid() and realty_form.is_valid(): |
|
|
|
project = form.save(commit=False) |
|
|
|
project = form.save(commit=False) |
|
|
|
project.customer = request.user |
|
|
|
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() |
|
|
|
project.save() |
|
|
|
form.save_m2m() |
|
|
|
form.save_m2m() |
|
|
|
|
|
|
|
|
|
|
|
for file in request.FILES.getlist('new_files'): |
|
|
|
for file in request.FILES.getlist('new_files'): |
|
|
|
proj_file = ProjectFile.objects.create(file=file, project=project) |
|
|
|
proj_file = ProjectFile.objects.create(file=file, project=project) |
|
|
|
proj_file.save() |
|
|
|
proj_file.save() |
|
|
|
|
|
|
|
|
|
|
|
if realty: |
|
|
|
if realty: |
|
|
|
realty_form.save() |
|
|
|
realty_form.save() |
|
|
|
else: |
|
|
|
else: |
|
|
|
@ -451,10 +451,10 @@ class CustomerProjectEditView(BaseMixin, View): |
|
|
|
realty.user = request.user |
|
|
|
realty.user = request.user |
|
|
|
realty.save() |
|
|
|
realty.save() |
|
|
|
realty_form.save_m2m() |
|
|
|
realty_form.save_m2m() |
|
|
|
|
|
|
|
|
|
|
|
project.realty = realty # Connect a realty with a project |
|
|
|
project.realty = realty # Connect a realty with a project |
|
|
|
project.save() |
|
|
|
project.save() |
|
|
|
|
|
|
|
|
|
|
|
messages.info(request, 'Проект успешно отредактирован') |
|
|
|
messages.info(request, 'Проект успешно отредактирован') |
|
|
|
redirect_to = request.POST.get('next') |
|
|
|
redirect_to = request.POST.get('next') |
|
|
|
return redirect(redirect_to) |
|
|
|
return redirect(redirect_to) |
|
|
|
@ -464,13 +464,13 @@ class CustomerProjectEditView(BaseMixin, View): |
|
|
|
'<p>Произошла ошибка (form)</p>' |
|
|
|
'<p>Произошла ошибка (form)</p>' |
|
|
|
'<pre>{form}</pre>' |
|
|
|
'<pre>{form}</pre>' |
|
|
|
).format(form=pformat(form.errors))) |
|
|
|
).format(form=pformat(form.errors))) |
|
|
|
|
|
|
|
|
|
|
|
if realty_form and realty_form.errors: |
|
|
|
if realty_form and realty_form.errors: |
|
|
|
messages.info(request, ( |
|
|
|
messages.info(request, ( |
|
|
|
'<p>Произошла ошибка (realty_form)</p>' |
|
|
|
'<p>Произошла ошибка (realty_form)</p>' |
|
|
|
'<pre>{realty_form}</pre>' |
|
|
|
'<pre>{realty_form}</pre>' |
|
|
|
).format(realty_form=pformat(realty_form.errors))) |
|
|
|
).format(realty_form=pformat(realty_form.errors))) |
|
|
|
|
|
|
|
|
|
|
|
context = self.get_context_data(**kwargs) |
|
|
|
context = self.get_context_data(**kwargs) |
|
|
|
context.update({'form': form, 'realty_form': realty_form}) |
|
|
|
context.update({'form': form, 'realty_form': realty_form}) |
|
|
|
return render(request, self.template_name, context) |
|
|
|
return render(request, self.template_name, context) |
|
|
|
@ -506,41 +506,41 @@ class ContractorPortfolioTrashView(View): |
|
|
|
|
|
|
|
|
|
|
|
class CustomerProjectTrashView(View): |
|
|
|
class CustomerProjectTrashView(View): |
|
|
|
form_class = CustomerProjectTrashForm |
|
|
|
form_class = CustomerProjectTrashForm |
|
|
|
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
if request.user.is_authenticated() and request.user.is_customer(): |
|
|
|
if request.user.is_authenticated() and request.user.is_customer(): |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
else: |
|
|
|
else: |
|
|
|
return HttpResponseForbidden('403 Forbidden') |
|
|
|
return HttpResponseForbidden('403 Forbidden') |
|
|
|
|
|
|
|
|
|
|
|
def post(self, req, *args, **kwargs): |
|
|
|
def post(self, req, *args, **kwargs): |
|
|
|
form = self.form_class(_.merge({}, req.POST, kwargs), req=req) |
|
|
|
form = self.form_class(_.merge({}, req.POST, kwargs), req=req) |
|
|
|
|
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
if form.is_valid(): |
|
|
|
project = form.cleaned_data.get('pk') |
|
|
|
project = form.cleaned_data.get('pk') |
|
|
|
project.state = 'trashed' |
|
|
|
project.state = 'trashed' |
|
|
|
project.save() |
|
|
|
project.save() |
|
|
|
|
|
|
|
|
|
|
|
messages.info(req, 'Проект перемещён в корзину') |
|
|
|
messages.info(req, 'Проект перемещён в корзину') |
|
|
|
else: |
|
|
|
else: |
|
|
|
messages.info(req, 'Произошла ошибка: <pre>{msg}</pre>'.format(msg=pformat(form.errors))) |
|
|
|
messages.info(req, 'Произошла ошибка: <pre>{msg}</pre>'.format(msg=pformat(form.errors))) |
|
|
|
|
|
|
|
|
|
|
|
redirect_to = req.POST.get('next') |
|
|
|
redirect_to = req.POST.get('next') |
|
|
|
return redirect(redirect_to) |
|
|
|
return redirect(redirect_to) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomerProjectRestoreView(View): |
|
|
|
class CustomerProjectRestoreView(View): |
|
|
|
form_class = CustomerProjectRestoreForm |
|
|
|
form_class = CustomerProjectRestoreForm |
|
|
|
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
if request.user.is_authenticated() and request.user.is_customer(): |
|
|
|
if request.user.is_authenticated() and request.user.is_customer(): |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
else: |
|
|
|
else: |
|
|
|
return HttpResponseForbidden('403 Forbidden') |
|
|
|
return HttpResponseForbidden('403 Forbidden') |
|
|
|
|
|
|
|
|
|
|
|
def post(self, req, *args, **kwargs): |
|
|
|
def post(self, req, *args, **kwargs): |
|
|
|
form = self.form_class(_.merge({}, req.POST, kwargs), req=req) |
|
|
|
form = self.form_class(_.merge({}, req.POST, kwargs), req=req) |
|
|
|
|
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
if form.is_valid(): |
|
|
|
project = form.cleaned_data.get('pk') |
|
|
|
project = form.cleaned_data.get('pk') |
|
|
|
project.state = 'active' |
|
|
|
project.state = 'active' |
|
|
|
@ -549,23 +549,23 @@ class CustomerProjectRestoreView(View): |
|
|
|
messages.info(req, 'Проект восстановлен из корзины') |
|
|
|
messages.info(req, 'Проект восстановлен из корзины') |
|
|
|
else: |
|
|
|
else: |
|
|
|
messages.info(req, 'Произошла ошибка: <pre>{msg}</pre>'.format(msg=pformat(form.errors))) |
|
|
|
messages.info(req, 'Произошла ошибка: <pre>{msg}</pre>'.format(msg=pformat(form.errors))) |
|
|
|
|
|
|
|
|
|
|
|
redirect_to = req.POST.get('next') |
|
|
|
redirect_to = req.POST.get('next') |
|
|
|
return redirect(redirect_to) |
|
|
|
return redirect(redirect_to) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomerProjectDeleteView(View): |
|
|
|
class CustomerProjectDeleteView(View): |
|
|
|
form_class = CustomerProjectDeleteForm |
|
|
|
form_class = CustomerProjectDeleteForm |
|
|
|
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
if request.user.is_authenticated() and request.user.is_customer(): |
|
|
|
if request.user.is_authenticated() and request.user.is_customer(): |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
else: |
|
|
|
else: |
|
|
|
return HttpResponseForbidden('403 Forbidden') |
|
|
|
return HttpResponseForbidden('403 Forbidden') |
|
|
|
|
|
|
|
|
|
|
|
def post(self, req, *args, **kwargs): |
|
|
|
def post(self, req, *args, **kwargs): |
|
|
|
form = self.form_class(_.merge({}, req.POST, kwargs), req=req) |
|
|
|
form = self.form_class(_.merge({}, req.POST, kwargs), req=req) |
|
|
|
|
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
if form.is_valid(): |
|
|
|
project = form.cleaned_data.get('pk') |
|
|
|
project = form.cleaned_data.get('pk') |
|
|
|
project.state = 'deleted' |
|
|
|
project.state = 'deleted' |
|
|
|
@ -573,7 +573,7 @@ class CustomerProjectDeleteView(View): |
|
|
|
messages.info(req, 'Проект удалён навсегда') |
|
|
|
messages.info(req, 'Проект удалён навсегда') |
|
|
|
else: |
|
|
|
else: |
|
|
|
messages.info(req, 'Произошла ошибка: <pre>{msg}</pre>'.format(msg=pformat(form.errors))) |
|
|
|
messages.info(req, 'Произошла ошибка: <pre>{msg}</pre>'.format(msg=pformat(form.errors))) |
|
|
|
|
|
|
|
|
|
|
|
redirect_to = req.POST.get('next') |
|
|
|
redirect_to = req.POST.get('next') |
|
|
|
return redirect(redirect_to) |
|
|
|
return redirect(redirect_to) |
|
|
|
|
|
|
|
|
|
|
|
@ -650,7 +650,7 @@ class OfferOrderView(View): |
|
|
|
return HttpResponseRedirect(redirect_url) |
|
|
|
return HttpResponseRedirect(redirect_url) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def contractor_portfolio_create(request): |
|
|
|
def contractor_portfolio_create(request): # TODO: pekopt: shit. rewrite using generic |
|
|
|
if request.is_ajax(): |
|
|
|
if request.is_ajax(): |
|
|
|
form = PortfolioForm(data=request.POST) |
|
|
|
form = PortfolioForm(data=request.POST) |
|
|
|
# import code; code.interact(local=dict(globals(), **locals())) |
|
|
|
# import code; code.interact(local=dict(globals(), **locals())) |
|
|
|
@ -707,4 +707,11 @@ class PortfolioDelete(DeleteView): |
|
|
|
model = Portfolio |
|
|
|
model = Portfolio |
|
|
|
success_url = reverse_lazy('users:contractor-profile') |
|
|
|
success_url = reverse_lazy('users:contractor-profile') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PortfolioDetail(DetailView): |
|
|
|
|
|
|
|
model = Portfolio |
|
|
|
|
|
|
|
template_name = 'portfolio_detail.html' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# import code; code.interact(local=dict(globals(), **locals())) |
|
|
|
# import code; code.interact(local=dict(globals(), **locals())) |
|
|
|
|