Compare commits

..

13 Commits
1.0.0 ... 1.1.0

Author SHA1 Message Date
Daniel Quinn
9faf0a102e Update changelog & version bump 2018-01-21 17:39:00 +00:00
Daniel Quinn
b747dd58c3 Fix redirect bug #283 2018-01-21 17:33:04 +00:00
Daniel Quinn
09e1b505e1 Merge pull request #256 from ddddavidmartin/add_financial_year_filter
Add financial year documents filter
2018-01-21 18:23:45 +01:00
Daniel Quinn
a6babffed8 Merge pull request #285 from pzl/master
small typo in exporter thumbnail filename
2018-01-21 18:18:31 +01:00
pzl
0256e2dfbb small typo in exporter thumbnail filename 2018-01-19 14:28:46 -05:00
Daniel Quinn
7afa90b769 Fix travis reference to pycodestyle 2018-01-06 19:32:51 +00:00
Daniel Quinn
5796956235 Fix typo 2018-01-06 19:30:08 +00:00
David Martin
67b492bcb7 Determine the start of the financial only for wrapping years.
If the financial year is from Jan to Dec there we do not need to
determine the start to see which year it falls into.
2017-08-26 19:50:57 +10:00
David Martin
360d1e2802 Store whether financial year wraps instead of re-determining it.
It either wraps or it does not depending on how it is set in the config.
There is no point in determining it again for each document. Instead we
simply store it as a member variable the first time we check.
2017-08-26 19:45:39 +10:00
David Martin
1cd76634a3 Take non-wrapping financial years into account.
The German financial year for example goes from January to December. In
those cases we simply only show the year in the overview.
2017-08-25 20:27:39 +10:00
David Martin
c65c5009e4 Return no filter results if financial year dates are not set.
This is a lot cleaner than trying to hack around whether or not the
FinancialYearFilter is part of the available filters. This way it will
show up if there are result for it and the dates are set, and it will
not if any of those conditions is not set.
2017-08-25 17:36:09 +10:00
David Martin
24fb6cefb9 Add config settings to set the start and the end of the financial year.
Now we allow to filter for any financial year dates. Note that we also
only show the financial year filter if the dates are actually set.
2017-08-24 20:51:09 +10:00
David Martin
d80e272b75 Add a basic financial year filter for the document overview.
For now we simply hardcode the dates for the AU financial years. We
simply show a list of financial years and filter the documents
accordingly.
2017-08-24 20:20:00 +10:00
8 changed files with 98 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ matrix:
- python: 3.6
env: TOXENV=py36
- python: 3.6
env: TOXENV=pep8
env: TOXENV=pycodestyle
install:
- pip install --requirement requirements.txt

View File

@@ -1,9 +1,17 @@
Changelog
#########
* 1.1.0
* Fix for `#283`_, a redirect bug which broke interactions with
paperless-desktop. Thanks to `chris-aeviator`_ for reporting it.
* Addition of an optional new financial year filter, courtesy of
`David Martin`_ `#256`_
* Fixed a typo in how thumbnails were named in exports `#285`_, courtesy of
`Dan Panzarella`_
* 1.0.0
* Upgrade to Django 1.11. **You'll need to run
``pip install -r requirements.txt`` to after the usual ``git pull`` to
``pip install -r requirements.txt`` after the usual ``git pull`` to
properly update**.
* Replace the templatetag-based hack we had for document listing in favour of
a slightly less ugly solution in the form of another template tag with less
@@ -258,6 +266,8 @@ Changelog
.. _Stefan Hagen: https://github.com/xkpd3
.. _dev-rke: https://github.com/dev-rke
.. _Lukas Winkler: https://github.com/Findus23
.. _chris-aeviator: https://github.com/chris-aeviator
.. _Dan Panzarella: https://github.com/pzl
.. _#20: https://github.com/danielquinn/paperless/issues/20
.. _#44: https://github.com/danielquinn/paperless/issues/44
@@ -304,3 +314,6 @@ Changelog
.. _#272: https://github.com/danielquinn/paperless/issues/272
.. _#248: https://github.com/danielquinn/paperless/issues/248
.. _#278: https://github.com/danielquinn/paperless/issues/248
.. _#283: https://github.com/danielquinn/paperless/issues/283
.. _#256: https://github.com/danielquinn/paperless/pull/256
.. _#285: https://github.com/danielquinn/paperless/pull/285

View File

@@ -167,6 +167,12 @@ PAPERLESS_PASSPHRASE="secret"
#PAPERLESS_TIME_ZONE=UTC
# If set, Paperless will show document filters per financial year.
# The dates must be in the format "mm-dd", for example "07-15" for July 15.
#PAPERLESS_FINANCIAL_YEAR_START="mm-dd"
#PAPERLESS_FINANCIAL_YEAR_END="mm-dd"
# The number of items on each page in the web UI. This value must be a
# positive integer, but if you don't define one in paperless.conf, a default of
# 100 will be used.

View File

@@ -1,3 +1,5 @@
from datetime import datetime
from django.conf import settings
from django.contrib import admin
from django.contrib.auth.models import User, Group
@@ -32,6 +34,71 @@ class MonthListFilter(admin.SimpleListFilter):
return queryset.filter(created__year=year, created__month=month)
class FinancialYearFilter(admin.SimpleListFilter):
title = "Financial Year"
parameter_name = "fy"
_fy_wraps = None
def _fy_start(self, year):
"""Return date of the start of financial year for the given year."""
fy_start = "{}-{}".format(str(year), settings.FY_START)
return datetime.strptime(fy_start, "%Y-%m-%d").date()
def _fy_end(self, year):
"""Return date of the end of financial year for the given year."""
fy_end = "{}-{}".format(str(year), settings.FY_END)
return datetime.strptime(fy_end, "%Y-%m-%d").date()
def _fy_does_wrap(self):
"""Return whether the financial year spans across two years."""
if self._fy_wraps is None:
start = "{}".format(settings.FY_START)
start = datetime.strptime(start, "%m-%d").date()
end = "{}".format(settings.FY_END)
end = datetime.strptime(end, "%m-%d").date()
self._fy_wraps = end < start
return self._fy_wraps
def _determine_fy(self, date):
"""Return a (query, display) financial year tuple of the given date."""
if self._fy_does_wrap():
fy_start = self._fy_start(date.year)
if date.date() >= fy_start:
query = "{}-{}".format(date.year, date.year + 1)
else:
query = "{}-{}".format(date.year - 1, date.year)
# To keep it simple we use the same string for both
# query parameter and the display.
return (query, query)
else:
query = "{0}-{0}".format(date.year)
display = "{}".format(date.year)
return (query, display)
def lookups(self, request, model_admin):
if not settings.FY_START or not settings.FY_END:
return None
r = []
for document in Document.objects.all():
r.append(self._determine_fy(document.created))
return sorted(set(r), key=lambda x: x[0], reverse=True)
def queryset(self, request, queryset):
if not self.value() or not settings.FY_START or not settings.FY_END:
return None
start, end = self.value().split("-")
return queryset.filter(created__gte=self._fy_start(start),
created__lte=self._fy_end(end))
class CommonAdmin(admin.ModelAdmin):
list_per_page = settings.PAPERLESS_LIST_PER_PAGE
@@ -59,7 +126,9 @@ class DocumentAdmin(CommonAdmin):
search_fields = ("correspondent__name", "title", "content")
list_display = ("title", "created", "thumbnail", "correspondent", "tags_")
list_filter = ("tags", "correspondent", MonthListFilter)
list_filter = ("tags", "correspondent", FinancialYearFilter,
MonthListFilter)
ordering = ["-created", "correspondent"]
def has_add_permission(self, request):

View File

@@ -64,7 +64,7 @@ class Command(Renderable, BaseCommand):
file_target = os.path.join(self.target, document.file_name)
thumbnail_name = document.file_name + "-tumbnail.png"
thumbnail_name = document.file_name + "-thumbnail.png"
thumbnail_target = os.path.join(self.target, thumbnail_name)
document_dict[EXPORTER_FILE_NAME] = document.file_name

View File

@@ -255,3 +255,6 @@ POST_CONSUME_SCRIPT = os.getenv("PAPERLESS_POST_CONSUME_SCRIPT")
# positive integer, but if you don't define one in paperless.conf, a default of
# 100 will be used.
PAPERLESS_LIST_PER_PAGE = int(os.getenv("PAPERLESS_LIST_PER_PAGE", 100))
FY_START = os.getenv("PAPERLESS_FINANCIAL_YEAR_START")
FY_END = os.getenv("PAPERLESS_FINANCIAL_YEAR_END")

View File

@@ -44,8 +44,8 @@ urlpatterns = [
# The Django admin
url(r"admin/", admin.site.urls),
# Catch all redirect back to /admin
url(r"", RedirectView.as_view(permanent=True, url="/admin/")),
# Redirect / to /admin
url(r"^$", RedirectView.as_view(permanent=True, url="/admin/")),
] + static.static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@@ -1 +1 @@
__version__ = (1, 0, 0)
__version__ = (1, 1, 0)