Skip to content

Commit

Permalink
Доработана потдержка django2.0+, дополнен readme
Browse files Browse the repository at this point in the history
  • Loading branch information
admin committed Jul 17, 2019
1 parent 6b55096 commit 82f7e26
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 26 deletions.
18 changes: 15 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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<https://github.com/applegrew/django-select2>`_ модуль интеграции Select2 с Django.
* `dbfread <https://github.com/olemb/dbfread>`_ Маленькая библиотека для работы с DBF. Для python3.3+ пока что нужно использовать мой `форк<https://github.com/Yuego/dbfread>`_


Некоторые особенности
Expand Down Expand Up @@ -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
=========================

Expand Down
24 changes: 9 additions & 15 deletions fias/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
9 changes: 4 additions & 5 deletions fias/suggest/backends/sphinx/management/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -73,15 +72,15 @@ 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 = {
'sphinx_host': SEARCHD_CONNECTION['HOST'],
'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()
Expand Down
2 changes: 1 addition & 1 deletion fias/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

# fias version info

VERSION = (1, 2, 5)
VERSION = (2, 0, 0)

__version__ = '.'.join(map(str, VERSION))
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ unrar
zeep>=0.17.0
dbfread>=2.0.0
progress<1.5
mysqlclient!=1.3.8
PyMySQL==0.9.3
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.*')),
Expand Down

0 comments on commit 82f7e26

Please sign in to comment.