Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Added setting to enable webdav (default: disabled), cleaned up the code somewhat.

Jonas Winklerf2c32d840edd
diff --git a/paperless.conf.example b/paperless.conf.example
old mode 100644
new mode 100755
index 3d90b2915..53dc33362
--- a/paperless.conf.example
+++ b/paperless.conf.example
@@ -193,3 +193,7 @@ PAPERLESS_EMAIL_SECRET=""
# positive integer, but if you don't define one in paperless.conf, a default of
# 100 will be used.
#PAPERLESS_LIST_PER_PAGE=100
+
+
+# Enable WebDAV support for Paperless. Default is false.
+#PAPERLESS_ENABLE_WEBDAV="true"
diff --git a/src/paperless/dav.py b/src/paperless/dav.py
index f0bd15592..3a082a75c 100755
--- a/src/paperless/dav.py
+++ b/src/paperless/dav.py
@@ -103,7 +103,6 @@ class PaperlessDavResource(MetaEtagMixIn, BaseDavResource):
def __init__(self, path, **kwargs):
super(PaperlessDavResource, self).__init__(path)
if 'document' in kwargs:
- print("using document from kwargs")
# this greatly reduces the amount of database requests.
self.document = kwargs.pop('document')
else:
@@ -147,7 +146,7 @@ class PaperlessDavResource(MetaEtagMixIn, BaseDavResource):
yield self.clone(url_join(*(self.path + [child])))
for doc in self.documents:
- yield self.clone(url_join(*(self.path + [doc.title])), document=doc)
+ yield self.clone(url_join(*(self.path + [doc.file_name])), document=doc)
def write(self, content, temp_file=None):
raise NotImplementedError()
@@ -174,8 +173,8 @@ def parse_path(path):
2. provide a database filter that returns a set of documents to be displayed, applying filters if necessary.
3. provide a set of "folders" that act as filters to narrow down the list of documents.
- This is achieved by implementing a state machine. This machine processes the path segment by segment and switched
- states as the path is processed. Depending on the state, only certain path segments are allowed.
+ This is achieved by implementing a state machine. This machine processes the path segment by segment and switches
+ states as the path is processed. Depending on the state, only certain path segments are allowed
:param path:
:return:
"""
@@ -184,10 +183,12 @@ def parse_path(path):
year_selected = False
month_selected = False
day_selected = False
- show_documents = True
+ show_documents = False
- def get_filter_children():
+ def get_filter_children(is_root=False):
filters = []
+ if is_root:
+ filters.append("show_all_documents")
if not year_selected:
filters.append('year')
elif not month_selected:
@@ -203,72 +204,72 @@ def parse_path(path):
path_queue = [x for x in path.split('/') if x]
filter = Document.objects.all()
- children = get_filter_children()
+ children = get_filter_children(True)
document = None
exists = True
- current_rule = 'select_filter'
+ current_state = 'select_filter'
while len(path_queue) > 0:
path_segment = path_queue.pop(0)
-
- if current_rule == 'select_filter':
- show_documents = False
- if path_segment == 'year':
- next_rule = 'select_year'
- children = [str(d.year) for d in filter.dates('created', 'year')]
- elif path_segment == 'month':
- next_rule = 'select_month'
- children = [str(d.month) for d in filter.dates('created', 'month')]
- elif path_segment == 'day':
- next_rule = 'select_day'
- children = [str(d.day) for d in filter.dates('created', 'day')]
- elif path_segment == 'correspondent':
- next_rule = 'select_correspondent'
- children = [c.name for c in Correspondent.objects.filter(documents__in=filter)]
- elif path_segment == 'tag':
- next_rule = 'select_tag'
- children = [t.name for t in Tag.objects.filter(documents__in=filter) if t.name not in used_tags]
- else:
- next_rule = 'document'
- children = []
- try:
- document = Document.objects.get(title=path_segment)
- except:
- exists = False
- elif current_rule == 'select_tag':
- next_rule = 'select_filter'
+ show_documents = False
+ children = []
+ next_state = ''
+
+ if current_state == 'select_filter' and path_segment == 'year':
+ next_state = 'select_year'
+ children = [str(d.year) for d in filter.dates('created', 'year')]
+ elif current_state == 'select_filter' and path_segment == 'month':
+ next_state = 'select_month'
+ children = [str(d.month) for d in filter.dates('created', 'month')]
+ elif current_state == 'select_filter' and path_segment == 'day':
+ next_state = 'select_day'
+ children = [str(d.day) for d in filter.dates('created', 'day')]
+ elif current_state == 'select_filter' and path_segment == 'correspondent':
+ next_state = 'select_correspondent'
+ children = [c.name for c in Correspondent.objects.filter(documents__in=filter).distinct()]
+ elif current_state == 'select_filter' and path_segment == 'tag':
+ next_state = 'select_tag'
+ children = [t.name for t in Tag.objects.filter(documents__in=filter).distinct() if t.name not in used_tags]
+ elif current_state == 'select_filter' and path_segment == 'show_all_documents':
+ show_documents = True
+ elif current_state == 'select_tag':
+ next_state = 'select_filter'
filter = filter.filter(tags__name=path_segment)
used_tags.append(path_segment)
children = get_filter_children()
show_documents = True
- elif current_rule == 'select_correspondent':
- next_rule = 'select_filter'
+ elif current_state == 'select_correspondent':
+ next_state = 'select_filter'
filter = filter.filter(correspondent__name=path_segment)
correspondent_selected = True
children = get_filter_children()
show_documents = True
- elif current_rule == 'select_year':
- next_rule = 'select_filter'
+ elif current_state == 'select_year':
+ next_state = 'select_filter'
filter = filter.filter(created__year=path_segment)
year_selected = True
children = get_filter_children()
show_documents = True
- elif current_rule == 'select_month':
- next_rule = 'select_filter'
+ elif current_state == 'select_month':
+ next_state = 'select_filter'
filter = filter.filter(created__month=path_segment)
month_selected = True
children = get_filter_children()
show_documents = True
- elif current_rule == 'select_day':
- next_rule = 'select_filter'
+ elif current_state == 'select_day':
+ next_state = 'select_filter'
filter = filter.filter(created__day=path_segment)
day_selected = True
children = get_filter_children()
show_documents = True
else:
- raise ValueError()
+ try:
+ #TODO: this is pretty slow and sketchy.
+ document = [d for d in Document.objects.all() if d.file_name == path_segment][0]
+ except IndexError:
+ exists = False
- current_rule = next_rule
+ current_state = next_state
return exists, filter if show_documents else [], document, children
\ No newline at end of file
diff --git a/src/paperless/settings.py b/src/paperless/settings.py
index 736c23d1a..fd8c63f76 100755
--- a/src/paperless/settings.py
+++ b/src/paperless/settings.py
@@ -280,3 +280,5 @@ FY_END = os.getenv("PAPERLESS_FINANCIAL_YEAR_END")
# Specify the default date order (for autodetected dates)
DATE_ORDER = os.getenv("PAPERLESS_DATE_ORDER", "DMY")
+
+ENABLE_WEBDAV = bool(os.getenv("PAPERLESS_ENABLE_WEBDAV", "NO").lower() in ("yes", "y", "1", "t", "true"))
diff --git a/src/paperless/urls.py b/src/paperless/urls.py
index 9ea81394a..0b821d0bd 100755
--- a/src/paperless/urls.py
+++ b/src/paperless/urls.py
@@ -50,14 +50,15 @@ urlpatterns = [
# The Django admin
url(r"admin/", admin.site.urls),
- url(r'^dav(?P<path>.*)$', SecuredDavView.as_view(resource_class=PaperlessDavResource, lock_class=DummyLock, acl_class=FullAcl)),
-
# Redirect / to /admin
url(r"^$", RedirectView.as_view(
permanent=True, url=reverse_lazy("admin:index"))),
] + static.static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
+if settings.ENABLE_WEBDAV:
+ urlpatterns.append(url(r'^dav(?P<path>.*)$', SecuredDavView.as_view(resource_class=PaperlessDavResource, lock_class=DummyLock, acl_class=FullAcl)))
+
# Text in each page's <h1> (and above login form).
admin.site.site_header = 'Paperless'
# Text at the end of each page's <title>.