From 82f7e26a00428518496bcd8f16ab9ef723b4f52f Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 17 Jul 2019 10:33:26 +1000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=20=D0=BF=D0=BE=D1=82=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=BA=D0=B0=20django2.0+,=20=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.rst | 18 +++++++++++--- fias/forms.py | 24 +++++++------------ .../backends/sphinx/management/utils.py | 9 ++++--- fias/version.py | 2 +- requirements.txt | 2 +- setup.py | 2 +- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/README.rst b/README.rst index 7a841c7..cb3f6a6 100644 --- a/README.rst +++ b/README.rst @@ -20,14 +20,14 @@ Совместимость ============= -* Django 1.7+ (*Для работы с django 1.7 необходимо доустановить django_extensions*) -* django_select2 5.3.0+ +* python 3.5+ +* Django 2.0+ +* django_select2 7.0.3+ Внешние зависимости =================== * `django_select2`_ модуль интеграции Select2 с Django. -* `dbfread `_ Маленькая библиотека для работы с DBF. Для python3.3+ пока что нужно использовать мой `форк`_ Некоторые особенности @@ -88,6 +88,18 @@ Путь к каталогу, где будут размещены временные файлы в процессе импорта. Каталог должен существовать и быть доступен для записи. +Версия 2.0.0 +========================= + +Эта версия использует python3.5+ и новые версии зависимости, НЕ СОВМЕСТИМЫЕ с django-fias версиями 1.х.х +Вся настройка аналогична версиям 1.х.х (смотрите ниже) +Если вы используете sphinx с mysql, необходимо установить pymysql и например в настройках +вашего приложения импортировать pymysql и вызвать метод install_as_MySQLdb() + +import pymysql +pymysql.install_as_MySQLdb() + + Обновление 1.1.x до 1.2.0 ========================= diff --git a/fias/forms.py b/fias/forms.py index 15f7719..6d96618 100644 --- a/fias/forms.py +++ b/fias/forms.py @@ -13,26 +13,20 @@ class AddressSelect2Widget(ModelSelect2Widget): search_fields = ['parentguid__exact'] - def build_attrs(self, base_attrs, extra_attrs=None): - attrs = super(AddressSelect2Widget, self).build_attrs(base_attrs, extra_attrs=None) + def build_attrs(self, *args, **kwargs): + attrs = super(AddressSelect2Widget, self).build_attrs(*args, **kwargs) # Вручную задаем длину поля, чтоб текст был читаем attrs.setdefault('style', 'min-width: 300px;') return attrs - # def optgroups(self, *args): - # try: - # selected_choices, = args - # except ValueError: - # choices, selected_choices = args - # - # if '' in selected_choices: - # selected_choices.pop(selected_choices.index('')) - # - # choices = ((obj.pk, obj.full_name(5, True)) for obj in self.queryset.filter(pk__in=selected_choices)) - # - # return super(AddressSelect2Widget, self).optgroups(choices, selected_choices) + def optgroups(self, name, value, attrs=None): + values = value[0].split(',') if value[0] else [] + values = [obj.full_name(5, True) for obj in self.queryset.filter(pk__in=values)] + selected = {*values} + subgroup = [self.create_option(name, v, v, selected, i) for i, v in enumerate(values)] + return [(None, subgroup, 0)] class AddressSelect2Field(ModelChoiceField): @@ -83,7 +77,7 @@ def render(self, name, value, attrs=None, renderer=None): 'id': attrs['id'], } - output = super(AreaChainedSelect, self).render(name, value, attrs=None, renderer=None) + output = super(AreaChainedSelect, self).render(name, value, attrs, renderer) output += js return mark_safe(output) diff --git a/fias/suggest/backends/sphinx/management/utils.py b/fias/suggest/backends/sphinx/management/utils.py index 820c596..fd38c98 100644 --- a/fias/suggest/backends/sphinx/management/utils.py +++ b/fias/suggest/backends/sphinx/management/utils.py @@ -4,7 +4,6 @@ from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.db import connections -from django.template import Context from django.template.loader import select_template from fias.compat import TemplateDoesNotExist @@ -60,10 +59,10 @@ def render_sphinx_source(): re_strip_el = re.compile(r'^\n', re.MULTILINE) for query_type in ['_pre', '_post', '']: query_name = 'query' + query_type - query = _get_sql_template(query_name).render(Context({})) + query = _get_sql_template(query_name).render({}) ctx['db_' + query_name] = re_nl.sub(r'\\\n', re_strip_el.sub('', query)).strip() - return _get_sphinx_template('source').render(Context(ctx)) + return _get_sphinx_template('source').render(ctx) def render_sphinx_index(path): @@ -73,7 +72,7 @@ def render_sphinx_index(path): 'index_name': SPHINX_ADDROBJ_INDEX, } - return _get_sphinx_template('index').render(Context(ctx)) + return _get_sphinx_template('index').render(ctx) def render_sphinx_searchd_config(): ctx = { @@ -81,7 +80,7 @@ def render_sphinx_searchd_config(): 'sphinx_port': SEARCHD_CONNECTION['PORT'], } - return _get_sphinx_template('sphinx').render(Context(ctx)) + return _get_sphinx_template('sphinx').render(ctx) def render_sphinx_config(path, full=True): source = render_sphinx_source() diff --git a/fias/version.py b/fias/version.py index 473ab43..3ee3a5d 100644 --- a/fias/version.py +++ b/fias/version.py @@ -3,6 +3,6 @@ # fias version info -VERSION = (1, 2, 5) +VERSION = (2, 0, 0) __version__ = '.'.join(map(str, VERSION)) diff --git a/requirements.txt b/requirements.txt index de3b4d8..2f06532 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,4 @@ unrar zeep>=0.17.0 dbfread>=2.0.0 progress<1.5 -mysqlclient!=1.3.8 +PyMySQL==0.9.3 diff --git a/setup.py b/setup.py index 82a80ac..58c8d6e 100755 --- a/setup.py +++ b/setup.py @@ -104,7 +104,7 @@ def check_tag_exists(): ], extras_require={ 'MySQL': [ - 'mysqlclient != 1.3.8', + 'PyMySQL==0.9.3', ], }, packages=find_packages(exclude=('tests', 'tests.*')),