Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

Commit

Permalink
Fix the correspondent filters #423
Browse files Browse the repository at this point in the history
  • Loading branch information
danielquinn committed Nov 3, 2018
1 parent 33abec0 commit eca6250
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Changelog

* Allow an infinite number of logs to be deleted. Thanks to `Ulli`_ for noting
the problem in `#433`_.
* Fix the ``RecentCorrespondentsFilter`` correspondents filter that was added
in 2.4 to play nice with the defaults. Thanks to `tsia`_ and `Sblop`_ who
pointed this out. `#423`_.


2.5.0
Expand Down Expand Up @@ -579,6 +582,8 @@ bulk of the work on this big change.
.. _Andrew Peng: https://github.com/pengc99
.. _euri10: https://github.com/euri10
.. _Ulli: https://github.com/Ulli2k
.. _tsia: https://github.com/tsia
.. _Sblop: https://github.com/Sblop

.. _#20: https://github.com/danielquinn/paperless/issues/20
.. _#44: https://github.com/danielquinn/paperless/issues/44
Expand Down Expand Up @@ -673,6 +678,7 @@ bulk of the work on this big change.
.. _#412: https://github.com/danielquinn/paperless/issues/412
.. _#413: https://github.com/danielquinn/paperless/pull/413
.. _#414: https://github.com/danielquinn/paperless/issues/414
.. _#423: https://github.com/danielquinn/paperless/issues/423
.. _#433: https://github.com/danielquinn/paperless/issues/433

.. _pipenv: https://docs.pipenv.org/
Expand Down
20 changes: 9 additions & 11 deletions src/documents/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,24 @@ def queryset(self, request, queryset):


class RecentCorrespondentFilter(admin.RelatedFieldListFilter):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.title = "correspondent (recent)"
"""
If PAPERLESS_RECENT_CORRESPONDENT_YEARS is set, we limit the available
correspondents to documents sent our way over the past ``n`` years.
"""

def field_choices(self, field, request, model_admin):

years = settings.PAPERLESS_RECENT_CORRESPONDENT_YEARS
days = 365 * years
correspondents = Correspondent.objects.all()

lookups = []
if years and years > 0:
correspondents = Correspondent.objects.filter(
self.title = "Correspondent (Recent)"
days = 365 * years
correspondents = correspondents.filter(
documents__created__gte=datetime.now() - timedelta(days=days)
).distinct()
for c in correspondents:
lookups.append((c.id, c.name))

return lookups
return [(c.id, c.name) for c in correspondents]


class CommonAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -177,7 +176,6 @@ class Media:
list_filter = (
"tags",
("correspondent", RecentCorrespondentFilter),
"correspondent",
FinancialYearFilter
)

Expand Down

0 comments on commit eca6250

Please sign in to comment.