diff --git a/accounts/forms.py b/accounts/forms.py index 93161e6a..dd9bf7fb 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -70,6 +70,16 @@ class UserForm(forms.ModelForm): 'date_joined', 'date_registered', 'date_modified') + def clean_url(self): + url = self.cleaned_data.get('url') + try: + user = User.objects.get(url=translit_with_separator(url)) + if (user.url == translit_with_separator(url)): + return url + except: + return url + raise forms.ValidationError('Такой урл уже занят') + def clean_phone(self): """ phone code checking diff --git a/service/forms.py b/service/forms.py index 8569f979..90874334 100644 --- a/service/forms.py +++ b/service/forms.py @@ -64,17 +64,6 @@ class ServiceForm(forms.Form): else: service = Service.objects.get(id=id) - #flag = 0 - #for item in data['types']: - # flag = flag | getattr(Theme.types, item) - - #generates bitfield -# countries = reduce(lambda x,y: x|y, (getattr(Service.country, item) for item in data['country'])) -# service.country= countries - -# cities = reduce(lambda x,y: x|y, (getattr(Service.city, item) for item in data['city'])) -# service.city = cities - service.url = translit_with_separator(data['url']) if data['url'] else translit_with_separator(data['name_ru']) service.price = data['price']+' '+data['currency']#%s %s'%(data['price'], data['currency']) @@ -111,7 +100,7 @@ class ServiceForm(forms.Form): url = cleaned_data.get('url') try: service = Service.objects.get(url=translit_with_separator(url)) - if (url ==service.url): + if (translit_with_separator(url) == service.url): return url except: return url diff --git a/service/templates/service_add.html b/service/templates/service_add.html index 4d502336..e6edb3c9 100644 --- a/service/templates/service_add.html +++ b/service/templates/service_add.html @@ -8,6 +8,7 @@ + - + {% endblock %} @@ -75,13 +70,13 @@
- +

{{ form.europa.label }}:

{{ form.europa }} - +

{{ form.asia.label }}:

{{ form.asia }} - +

{{ form.america.label }}:

{{ form.america }} - +

{{ form.africa.label }}:

{{ form.africa }}
diff --git a/service/urls.py b/service/urls.py index ce6f4375..ba1208a2 100644 --- a/service/urls.py +++ b/service/urls.py @@ -6,6 +6,8 @@ urlpatterns = patterns('', url(r'^change/(.*)/$', 'service.views.service_change'), url(r'^all/$', 'service.views.service_all'), + url(r'^get_city/$', 'service.views.get_city'), + url(r'^review/add.*/$', 'service.views.review_add'), url(r'^review/change/(?P\d+).*/$', 'service.views.review_change'), url(r'^review/all/$', 'service.views.review_all'), diff --git a/service/views.py b/service/views.py index b1879dc8..06b28e7a 100644 --- a/service/views.py +++ b/service/views.py @@ -9,6 +9,7 @@ from django.contrib.auth.decorators import login_required from models import Service, Review from forms import ServiceForm, ReviewForm from country.models import Country +from city.models import City #custom views from functions.custom_views import objects_list @@ -42,15 +43,18 @@ def service_change(request, url): return HttpResponseRedirect('/service/all') else: data = {} - #bitfield -# data['country'] = [item for item, bool in service.country if bool==True] -# data['city'] = [item for item, bool in service.city if bool==True] - try: data['price'] = service.price.split(' ')[0] data['currency'] = service.price.split(' ')[1] except:pass - data['service_id'] = service_id + #countries sorted by this service + services_in_countries = Country.objects.filter(services=getattr(Country.services, str(service_id))) + + data['europa'] = services_in_countries + data['asia'] = services_in_countries + data['africa'] = services_in_countries + data['america'] = services_in_countries + data['url'] = service.url #data from translated fields @@ -135,4 +139,10 @@ def review_change(request, review_id): args['form'] = form args['languages'] = settings.LANGUAGES - return render_to_response('review_add.html', args) \ No newline at end of file + return render_to_response('review_add.html', args) + +def get_city(request): + if request.GET: + country_id = request.GET['id'] + City.objects.filter(country=country_id) + return HttpResponse(id) \ No newline at end of file diff --git a/static/custom_js/service.js b/static/custom_js/service.js new file mode 100644 index 00000000..4ead68c0 --- /dev/null +++ b/static/custom_js/service.js @@ -0,0 +1,15 @@ +$(document).ready(function(){ + $("input:checkbox[name='europa'] ").click(function(){ + if ($(this).is(':checked')){ + $.get( + "/service/get_city/", + {'id': $(this).val()}, + function(j){ + console.log(j); + }); + } + else{ + console.log('false'); + } + }) +});