#ARC-11 Fancy contractor specialization editing widgets

remotes/origin/setup
ArturBaybulatov 10 years ago
parent 24ad9bb14a
commit 9635e0041b
  1. 2
      archilance/mixins.py
  2. 32
      assets/index.js
  3. 16
      projects/migrations/0008_merge.py
  4. 8
      users/forms.py
  5. 21
      users/templates/user_profile_edit.html
  6. 13
      users/views.py

@ -8,7 +8,7 @@ class BaseMixin(ContextMixin):
c = super().get_context_data(**kwargs) c = super().get_context_data(**kwargs)
pk = self.kwargs.get('pk') # Current object's ID pk = self.kwargs.get('pk') # Current object's ID
next = self.kwargs.get('next') # Redirect back path next = self.kwargs.get('next') # Redirect next path
back = self.kwargs.get('back') # Redirect back path back = self.kwargs.get('back') # Redirect back path
if pk: c['pk'] = int(pk) if pk: c['pk'] = int(pk)

@ -1,4 +1,4 @@
// Common ------------------------------------------------- // Specialization select -----------------------------------
var specSelectOptions = { var specSelectOptions = {
@ -45,19 +45,6 @@ var specSelectOptions = {
} }
} }
// Specialization select -----------------------------------
var $specSelects = $('.-spec-select') var $specSelects = $('.-spec-select')
$specSelects.select2(specSelectOptions) $specSelects.select2(specSelectOptions)
@ -100,6 +87,9 @@ function updateSpecializationWidgets(specId) {
// Specialization select (simple) ------------------------------- // Specialization select (simple) -------------------------------
@ -146,6 +136,11 @@ $('#simpleSpecContainer').on('change', '.-simple-spec-select', function($evt) {
// Location select ---------------------------------------------- // Location select ----------------------------------------------
@ -241,6 +236,11 @@ function loadRealtyDetails(realtyId) {
// File uploading --------------------------------------- // File uploading ---------------------------------------
@ -292,9 +292,6 @@ $fileUploadContainer.on('click', '.existing-file-remove-btn', function($evt) {
// Helpers --------------------------------------------- // Helpers ---------------------------------------------
@ -487,6 +484,7 @@ function getLocationTree(locId) {
// Utils ----------------------------------------------- // Utils -----------------------------------------------

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-07-29 17:12
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('projects', '0007_auto_20160727_1835'),
('projects', '0005_auto_20160726_1958'),
]
operations = [
]

@ -39,14 +39,6 @@ class UserProfileEditForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request') self.request = kwargs.pop('request')
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
# user = self.request.user
#
# if user.is_contractor():
# self.fields['contractor_specializations'] = ...
# def clean_contractor_specializations(self...):
# ...
class UserFinancialInfoEditForm(forms.ModelForm): class UserFinancialInfoEditForm(forms.ModelForm):

@ -46,9 +46,9 @@
<p class="name-edit-p">Специализации</p> <p class="name-edit-p">Специализации</p>
<div id="simpleSpecContainer"> <div id="simpleSpecContainer">
<div class="polsF1 pols-edit disTab -simple-spec-widget" s--tyle="display: none"> <div class="polsF1 pols-edit disTab -simple-spec-widget" style="display: none">
<input type="text" class="-simple-spec-select" style="width: 100%"> <input type="hidden" class="-simple-spec-select" style="width: 100%">
<input type="text" class="-chosen-simple-spec-id" name="{{ form.contractor_specializations.html_name }}"> <input type="hidden" class="-chosen-simple-spec-id" name="{{ form.contractor_specializations.html_name }}">
</div> </div>
</div> </div>
@ -152,18 +152,3 @@
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
{#{% block js_block %}#}
{# <script>#}
{# $("#add-edit-spec").on('click',function() {#}
{# $("<select class='selectpicker4'><option >Видное</option></select>").insertBefore("#add-edit-spec");#}
{# #}
{# $('.selectpicker4').selectpicker({#}
{# style: 'btn-info',#}
{# size: 4,#}
{# width: '237px'#}
{# });#}
{# });#}
{# </script>#}
{#{% endblock %}#}

@ -55,11 +55,6 @@ class UserProfileEditView(BaseMixin, View):
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))
if request.user.is_contractor():
root = util.get_or_none(Specialization, name='_root')
nodes = root.get_descendants('lft')
context.update({'nodes': nodes})
form = self.form_class(request=request, instance=request.user) form = self.form_class(request=request, instance=request.user)
context.update({'form': form}) context.update({'form': form})
@ -68,11 +63,15 @@ class UserProfileEditView(BaseMixin, View):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs) context = self.get_context_data(**kwargs)
customer = request.user customer = request.user
# Мухтар, смотри, фишечка:
specs = request.POST.getlist('contractor_specializations')
request.POST.setlist('contractor_specializations', _.compact(specs)) # Ignore empty input values
form = self.form_class(request.POST, request.FILES, request=request, instance=customer) form = self.form_class(request.POST, request.FILES, request=request, instance=customer)
if form.is_valid(): if form.is_valid():
import code; code.interact(local=dict(globals(), **locals()))
form.save() form.save()
messages.info(request, 'Заказчик успешно отредактирован') messages.info(request, 'Заказчик успешно отредактирован')

Loading…
Cancel
Save