Fixes #ARC-13 #ARC-47

remotes/origin/PR-39
ArturBaybulatov 10 years ago
parent 80cfcc653b
commit 96f8bd7e95
  1. 20
      archilance/util.py
  2. 8
      assets/js/main.js
  3. 32
      projects/forms.py
  4. 8
      projects/templates/customer_project_create.html
  5. 32
      projects/templates/customer_project_edit.html
  6. 2
      projects/views.py
  7. 44
      users/templates/contractor_filter.html

@ -1,9 +1,11 @@
from django.core import validators
from django.shortcuts import _get_queryset from django.shortcuts import _get_queryset
from django.utils import timezone from django.utils import timezone
from pprint import pprint, pformat from pprint import pprint, pformat
import natsort import natsort
import pydash as _; _.map = _.map_; _.filter = _.filter_ import pydash as _; _.map = _.map_; _.filter = _.filter_
import random import random
import string
def take(coll, n): def take(coll, n):
@ -89,3 +91,21 @@ def decap(s):
raise TypeError('String expected') raise TypeError('String expected')
return s[0].lower() + s[1:] if len(s) > 0 else s return s[0].lower() + s[1:] if len(s) > 0 else s
def random_ident(length=8):
return ''.join(
[random.choice(string.ascii_lowercase)] +
_.times(lambda x_: random.choice(string.ascii_letters + string.digits), length-1)
)
def validate_phone(text):
text = text.replace(' ', '').replace('-', '')
validate = validators.RegexValidator(
regex=r'^((\+7|8)(\(\d{3}\)|(\d{3}))\d{7})$',
message='Неверный номер телефона. Формат: +71112223344',
)
validate(text)

@ -6,11 +6,11 @@ $(document).ready(function(){
if ($.cookie('slideResVisible')) { if ($.cookie('slideResVisible')) {
$('.slideRes').slideDown(300); $('.slideRes').slideDown(300);
$('.resButtonF1').css('transform','rotate(0deg)'); $('.resButtonF1').css('transform','rotate(0deg)');
//$('#extraFields').val('') $('#extraFields').val('on')
} else { } else {
$('.slideRes').slideUp(300); $('.slideRes').slideUp(300);
$('.resButtonF1').css('transform','rotate(180deg)'); $('.resButtonF1').css('transform','rotate(180deg)');
//$('#extraFields').val('on') $('#extraFields').val('')
} }
$('.resButtonF1').click(function(e){ $('.resButtonF1').click(function(e){
@ -20,12 +20,12 @@ $(document).ready(function(){
$('.slideRes').slideUp(300); $('.slideRes').slideUp(300);
$(this).css('transform','rotate(180deg)'); $(this).css('transform','rotate(180deg)');
$.cookie('slideResVisible', '', {expires: new Date(new Date().getTime() + 300000)}) // 5 minutes $.cookie('slideResVisible', '', {expires: new Date(new Date().getTime() + 300000)}) // 5 minutes
//$('#extraFields').val('') $('#extraFields').val('')
} else { } else {
$('.slideRes').slideDown(300); $('.slideRes').slideDown(300);
$(this).css('transform','rotate(0deg)'); $(this).css('transform','rotate(0deg)');
$.cookie('slideResVisible', 'on', {expires: new Date(new Date().getTime() + 300000)}) $.cookie('slideResVisible', 'on', {expires: new Date(new Date().getTime() + 300000)})
//$('#extraFields').val('on') $('#extraFields').val('on')
} }
}); });

@ -6,6 +6,7 @@ from pprint import pprint, pformat
import itertools import itertools
from .models import Project, ProjectFile, Portfolio, Answer, AnswerMessage, Realty, PortfolioPhoto, Stage from .models import Project, ProjectFile, Portfolio, Answer, AnswerMessage, Realty, PortfolioPhoto, Stage
from archilance import util
from common.models import Location from common.models import Location
from specializations.models import Specialization from specializations.models import Specialization
from users.models import User, Team from users.models import User, Team
@ -117,6 +118,11 @@ class CustomerProjectEditForm(forms.ModelForm):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.fields['realty'].empty_label = 'Создать новый' self.fields['realty'].empty_label = 'Создать новый'
self.fields['realty'].queryset = self.request.user.realties.all()
self.fields['budget'].required = False
self.fields['currency'].required = False
self.fields['term_type'].required = False
self.fields['specialization'].queryset = Specialization.objects.root_nodes()[0].get_descendants() self.fields['specialization'].queryset = Specialization.objects.root_nodes()[0].get_descendants()
# self.fields['specialization'].queryset = Specialization.objects # Migrate with this enabled # self.fields['specialization'].queryset = Specialization.objects # Migrate with this enabled
@ -124,6 +130,16 @@ class CustomerProjectEditForm(forms.ModelForm):
if self.instance.pk: if self.instance.pk:
self.fields['files'].queryset = self.instance.files self.fields['files'].queryset = self.instance.files
def clean(self):
cleaned_data = super().clean()
if not cleaned_data.get('budget_by_agreement'):
if not cleaned_data.get('budget'): raise forms.ValidationError({'budget': 'Это поле обязательно'})
if not cleaned_data.get('currency'): raise forms.ValidationError({'currency': 'Это поле обязательно'})
if not cleaned_data.get('term_type'): raise forms.ValidationError({'term_type': 'Это поле обязательно'})
return cleaned_data
class RealtyForm(forms.ModelForm): class RealtyForm(forms.ModelForm):
class Meta: class Meta:
@ -145,9 +161,25 @@ class RealtyForm(forms.ModelForm):
self.request = kwargs.pop('request') self.request = kwargs.pop('request')
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.fields['name'].required = False
self.fields['location'].queryset = Location.objects.root_nodes()[0].get_descendants() self.fields['location'].queryset = Location.objects.root_nodes()[0].get_descendants()
# self.fields['location'].queryset = Location.objects # Migrate with this enabled # self.fields['location'].queryset = Location.objects # Migrate with this enabled
def clean_name(self):
name = self.cleaned_data.get('name')
if not name:
if self.data.get('extra_fields'):
raise forms.ValidationError('Это поле обязательно')
else:
if not self.instance.pk:
name = self.instance.name
else:
name = 'Новый объект %s' % util.random_ident(length=20)
return name
class PortfolioForm(forms.ModelForm): class PortfolioForm(forms.ModelForm):
duplicate = forms.BooleanField(required=False,label='Some label here') duplicate = forms.BooleanField(required=False,label='Some label here')

@ -14,6 +14,8 @@
<form action="{% url 'projects:customer-project-create' %}" method="POST" enctype="multipart/form-data" novalidate> <form action="{% url 'projects:customer-project-create' %}" method="POST" enctype="multipart/form-data" novalidate>
{% csrf_token %} {% csrf_token %}
<input type="hidden" id="extraFields" name="extra_fields" value="">
<div class="chatBlock new-rass new-rass2 disTab"> <div class="chatBlock new-rass new-rass2 disTab">
<div class="col-lg-9"> <div class="col-lg-9">
<p class="new-pp new-pp3">Формирование заказа</p> <p class="new-pp new-pp3">Формирование заказа</p>
@ -52,7 +54,7 @@
<p class="type-work">Тип работы <span style="color: red">{{ form.work_type.errors.as_text }}</span></p> <p class="type-work">Тип работы <span style="color: red">{{ form.work_type.errors.as_text }}</span></p>
<div class="mail-block type-work-inset"> <div class="mail-block type-work-inset">
{% for id, name in form.work_type.field.choices %} {% for id, text in form.work_type.field.choices %}
<div class="inset-mb"> <div class="inset-mb">
<label> <label>
<input <input
@ -64,7 +66,7 @@
<span></span> <span></span>
</label> </label>
<p>{{ name }}</p> <p>{{ text }}</p>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
@ -187,8 +189,6 @@
<!--<p><input type="text" id="extraFields" name="extra_fields" value=""></p>-->
<div class="resSearchF1"> <div class="resSearchF1">
<div class="col-lg-3"> <div class="col-lg-3">
<p class="titleResF1">Расширенный поиск</p> <p class="titleResF1">Расширенный поиск</p>

@ -13,7 +13,9 @@
<form action="{% url 'projects:customer-project-edit' pk=pk %}" method="POST" enctype="multipart/form-data" novalidate> <form action="{% url 'projects:customer-project-edit' pk=pk %}" method="POST" enctype="multipart/form-data" novalidate>
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="next" value="{% url 'projects:detail' pk=pk %}"> <input type="hidden" name="next" value="{% url 'projects:detail' pk=pk %}">
<input type="hidden" id="extraFields" name="extra_fields" value="">
<div class="chatBlock new-rass new-rass2 disTab"> <div class="chatBlock new-rass new-rass2 disTab">
<div class="col-lg-9"> <div class="col-lg-9">
@ -92,22 +94,22 @@
</div> </div>
<div class="polsF1 disTab -spec-select-container"> <div class="polsF1 disTab -spec-select-container">
<div class="col-lg-3"> <div class="col-lg-3">
<input type='hidden' class="-spec-select -spec-select-level-1" style="width: 100%"> <input type="hidden" class="-spec-select -spec-select-level-1" style="width: 100%">
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<input type='hidden' class="-spec-select -spec-select-level-2" style="width: 100%"> <input type="hidden" class="-spec-select -spec-select-level-2" style="width: 100%">
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<input type='hidden' class="-spec-select -spec-select-level-3" style="width: 100%"> <input type="hidden" class="-spec-select -spec-select-level-3" style="width: 100%">
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<input type='hidden' class="-spec-select -spec-select-level-4" style="width: 100%"> <input type="hidden" class="-spec-select -spec-select-level-4" style="width: 100%">
</div> </div>
<input type="hidden" class="-chosen-spec-id" name="{{ form.specialization.html_name }}" value="{{ form.specialization.value }}"> <input type="hidden" name="{{ form.specialization.html_name }}" value="{{ form.specialization.value }}" class="-chosen-spec-id">
</div> </div>
<div class="titleF1 titleF2 disTab"> <div class="titleF1 titleF2 disTab">
<div class="col-lg-12">Бюджет <span style="color: red">{{ form.budget.errors.as_text }}</span></div> <div class="col-lg-12">Бюджет <span style="color: red">{{ form.budget.errors.as_text }}</span></div>
@ -258,19 +260,19 @@
</div> </div>
</div> </div>
<div class="titleF1 disTab"> <div class="titleF1 disTab">
<div class="col-lg-12">Местоположение:</div> <div class="col-lg-12">Местоположение <span style="color: red">{{ realty_form.location.errors.as_text }}</span></div>
</div> </div>
<div class="polsF1 polsF2 disTab"> <div class="polsF1 polsF2 disTab">
<div class="col-lg-3"> <div class="col-lg-3">
<input type='hidden' class="-location-select -location-select-country" style="width: 100%"> <input type="hidden" class="-location-select -location-select-country" style="width: 100%">
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<input type='hidden' class="-location-select -location-select-region" style="width: 100%"> <input type="hidden" class="-location-select -location-select-region" style="width: 100%">
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
<input type='hidden' class="-location-select -location-select-city" style="width: 100%"> <input type="hidden" class="-location-select -location-select-city" style="width: 100%">
</div> </div>
<input type="hidden" id="chosenLocationId" name="{{ realty_form.location.html_name }}" value="{{ realty_form.location.value }}"> <input type="hidden" id="chosenLocationId" name="{{ realty_form.location.html_name }}" value="{{ realty_form.location.value }}">
@ -288,17 +290,11 @@
<p>Требуется допуск СРО</p> <p>Требуется допуск СРО</p>
</div> </div>
</div> </div>
<div class="searchF1 polsF1 polsFF links-filter">
<input class="btn-submit-link" type="submit" value="Сохранить">
</div>
</div> </div>
<div class="searchF1 polsF1 polsFF links-filter">
<input class="btn-submit-link" type="submit" value="Сохранить">
</div>
</div> </div>
</div> </div>
</form> </form>

@ -403,7 +403,7 @@ class CustomerProjectEditView(BaseMixin, View):
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') raise PermissionDenied
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'))

@ -42,30 +42,7 @@
</div> </div>
<div class="titleF1 titleF2 disTab">
<div class="col-lg-3">Местоположение</div>
</div>
<div class="searchF1 polsF1 polsFF polsF3"> <div class="searchF1 polsF1 polsFF polsF3">
<div class="col-lg-3">
<input type="hidden" class="-location-select -location-select-country" style="width: 100%">
</div>
<div class="col-lg-3">
<input type="hidden" class="-location-select -location-select-region" style="width: 100%">
</div>
<div class="col-lg-3">
<input type="hidden" class="-location-select -location-select-city" style="width: 100%">
</div>
<input type="hidden" id="chosenLocationId" name="{{ form.location.html_name }}" value="{{ form.location.value }}">
<div class="col-lg-3"> <div class="col-lg-3">
<a href="#" class="findReal" onclick="$(this).closest('form').submit(); return false"> <a href="#" class="findReal" onclick="$(this).closest('form').submit(); return false">
найти исполнителя найти исполнителя
@ -103,6 +80,27 @@
<div class="slideRes disTab activeSlide"> <div class="slideRes disTab activeSlide">
<div class="titleF1 disTab">
<div class="col-lg-12">Местоположение</div>
</div>
<div class="polsF1 disTab">
<div class="col-lg-3">
<input type="hidden" class="-location-select -location-select-country" style="width: 100%">
</div>
<div class="col-lg-3">
<input type="hidden" class="-location-select -location-select-region" style="width: 100%">
</div>
<div class="col-lg-3">
<input type="hidden" class="-location-select -location-select-city" style="width: 100%">
</div>
<input type="hidden" id="chosenLocationId" name="{{ form.location.html_name }}" value="{{ form.location.value }}">
</div>
<div class="titleF1 disTab"> <div class="titleF1 disTab">
<div class="col-lg-3">Классификация здания</div> <div class="col-lg-3">Классификация здания</div>
<div class="col-lg-3">Тип работы</div> <div class="col-lg-3">Тип работы</div>

Loading…
Cancel
Save