Skip to content

Commit

Permalink
Merge pull request #158 from modlinltd/code-quality-fixes
Browse files Browse the repository at this point in the history
Code quality fixes
  • Loading branch information
asfaltboy authored Jan 23, 2022
2 parents 5549cdf + 61ae5eb commit db448fa
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 20 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
branch = True
omit = */test*
source = advanced_filters
parallel = true

[report]
# Regexes for lines to exclude from consideration
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ tests/db.sqlite*
.pytest_cache
/tests/local.db
/.venv
.vscode/settings.json
39 changes: 19 additions & 20 deletions advanced_filters/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ class AdminAdvancedFiltersMixin(object):

def __init__(self, *args, **kwargs):
super(AdminAdvancedFiltersMixin, self).__init__(*args, **kwargs)
if self.change_list_template:
self.original_change_list_template = self.change_list_template
else:
self.original_change_list_template = "admin/change_list.html"
self.original_change_list_template = "admin/change_list.html"
self.change_list_template = self.advanced_change_list_template
# add list filters to filters
self.list_filter = (AdvancedListFilters,) + tuple(self.list_filter)
Expand All @@ -80,30 +77,32 @@ def save_advanced_filter(self, request, form):
path=request.path, qparams="?_afilter={id}".format(
id=afilter.id))
return HttpResponseRedirect(url)
elif request.method == "POST":
else:
logger.info('Failed saving advanced filter, params: %s', form.data)

def adv_filters_handle(self, request, extra_context={}):
data = request.POST if request.POST.get(
'action') == 'advanced_filters' else None
adv_filters_form = self.advanced_filter_form(
data=data, model_admin=self, extra_form=True)
def changelist_view(self, request, extra_context=None):
"""Add advanced_filters form to changelist context"""
if extra_context is None:
extra_context = {}

data = None
if request.method == "POST":
if request.POST.get('action') == 'advanced_filters':
data = request.POST

form = self.advanced_filter_form(data=data, model_admin=self, extra_form=True)
extra_context.update({
'original_change_list_template': self.original_change_list_template,
'advanced_filters': adv_filters_form,
'advanced_filters': form,
'current_afilter': request.GET.get('_afilter'),
'app_label': self.opts.app_label,
})
return self.save_advanced_filter(request, adv_filters_form)

def changelist_view(self, request, extra_context=None):
"""Add advanced_filters form to changelist context"""
if extra_context is None:
extra_context = {}
response = self.adv_filters_handle(request,
extra_context=extra_context)
if response:
return response
if request.method == "POST":
response = self.save_advanced_filter(request, form)
if response:
return response

return super(AdminAdvancedFiltersMixin, self
).changelist_view(request, extra_context=extra_context)

Expand Down
Binary file added advanced_filters/locale/es/LC_MESSAGES/django.mo
Binary file not shown.
Binary file added advanced_filters/locale/ja/LC_MESSAGES/django.mo
Binary file not shown.
Binary file added advanced_filters/locale/lv/LC_MESSAGES/django.mo
Binary file not shown.
Binary file added advanced_filters/locale/ru/LC_MESSAGES/django.mo
Binary file not shown.
Binary file added advanced_filters/locale/tr/LC_MESSAGES/django.mo
Binary file not shown.
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ envlist =
; py39-django{22,30,31,32}
pypy3-django{111,20,21,22,30,31}
report
clean

[pycodestyle]
max-line-length = 120
Expand Down

0 comments on commit db448fa

Please sign in to comment.