Compare commits
No commits in common. "f9c202f2caabf2530d1352eeb4afff5d93f3f6ef" and "dee48093be542db6930d4025fac228d5bdeffcbd" have entirely different histories.
f9c202f2ca
...
dee48093be
@ -1,6 +1,4 @@
|
|||||||
from datetime import datetime
|
|
||||||
from django.urls.base import reverse
|
from django.urls.base import reverse
|
||||||
import zoneinfo
|
|
||||||
|
|
||||||
|
|
||||||
def url_page(request, rel_path, **kwargs):
|
def url_page(request, rel_path, **kwargs):
|
||||||
@ -20,16 +18,3 @@ def url_edit(request, rel_path):
|
|||||||
|
|
||||||
def get_search_query(request):
|
def get_search_query(request):
|
||||||
return request.GET.get('q')
|
return request.GET.get('q')
|
||||||
|
|
||||||
|
|
||||||
def timestamp_to_datetime(request, tm):
|
|
||||||
from users.models import get_userprofile
|
|
||||||
#
|
|
||||||
try:
|
|
||||||
up = get_userprofile(request.user)
|
|
||||||
except AttributeError:
|
|
||||||
return datetime.fromtimestamp(tm)
|
|
||||||
else:
|
|
||||||
tz = zoneinfo.ZoneInfo(up.timezone)
|
|
||||||
#
|
|
||||||
return datetime.fromtimestamp(tm, tz)
|
|
||||||
|
@ -34,47 +34,8 @@ ACCESS = mycreole.render_simple(_("""
|
|||||||
= TBD
|
= TBD
|
||||||
"""))
|
"""))
|
||||||
|
|
||||||
SEARCH = mycreole.render_simple(_(
|
SEARCH = mycreole.render_simple(_("""
|
||||||
"""
|
= TBD
|
||||||
= Search
|
|
||||||
The search looks up full words in //title (page basename)// and //page_src (the creole source)// without giving \
|
|
||||||
special search commands in the search string.
|
|
||||||
|
|
||||||
=== Search fields
|
|
||||||
* title (TEXT)
|
|
||||||
* page_src (TEXT)
|
|
||||||
* creation_time (DATETIME)
|
|
||||||
* modified_time (DATETIME)
|
|
||||||
* modified_user (TEXT)
|
|
||||||
|
|
||||||
== Search syntax (Whoosh)
|
|
||||||
=== Logic operators
|
|
||||||
* AND
|
|
||||||
** **Example:** "foo AND bar" - Search will find all items with foo and bar.
|
|
||||||
* OR
|
|
||||||
** **Example:** "foo OR bar" - Search will find all items with foo, bar or with foo and bar.
|
|
||||||
* NOT
|
|
||||||
** **Example:** "foo NOT bar" - Search will find all items with foo and no bar.
|
|
||||||
=== Search in specific fields
|
|
||||||
A search pattern like //foo:bar// does look for //bar// in the field named //foo//.
|
|
||||||
|
|
||||||
This search pattern can also be combined with other search text via logical operators.
|
|
||||||
=== Search for specific content
|
|
||||||
* **Wildcards:**
|
|
||||||
* **Range:**
|
|
||||||
** From To:
|
|
||||||
** Above:
|
|
||||||
** Below:
|
|
||||||
* **Named constants:**
|
|
||||||
** //now//: Current date
|
|
||||||
** //-[num]y//: Current date minus [num] years
|
|
||||||
** //+[num]mo//: Current date plus [num] months
|
|
||||||
** //-[num]d//: Current date minus [num] days
|
|
||||||
** ...
|
|
||||||
|
|
||||||
== Examples
|
|
||||||
* [[/search/?q=modified_user:system-page|modified_user:system-page]] results in a list of all system pages.
|
|
||||||
* [[/search/?q=modified_time%3A%5B-5d+to+now%5D| modified_time:[-5d to now] ]] results in a list of all pages which have been modified within the last 5 days.
|
|
||||||
"""))
|
"""))
|
||||||
|
|
||||||
help_pages = {
|
help_pages = {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from datetime import datetime
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
import fstools
|
import fstools
|
||||||
@ -8,7 +9,8 @@ import mycreole
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
from . import timestamp_to_datetime
|
from users.models import get_userprofile
|
||||||
|
import zoneinfo
|
||||||
|
|
||||||
logger = logging.getLogger(settings.ROOT_LOGGER_NAME).getChild(__name__)
|
logger = logging.getLogger(settings.ROOT_LOGGER_NAME).getChild(__name__)
|
||||||
|
|
||||||
@ -165,8 +167,14 @@ class creole_page(base_page):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
def render_meta(self):
|
def render_meta(self):
|
||||||
ctime = timestamp_to_datetime(self._request, self._meta_data.get(self._meta_data.KEY_CREATION_TIME)).strftime('%Y-%m-%d %H:%M')
|
def str_date(tm):
|
||||||
mtime = timestamp_to_datetime(self._request, self._meta_data.get(self._meta_data.KEY_MODIFIED_TIME)).strftime('%Y-%m-%d %H:%M')
|
up = get_userprofile(self._request.user)
|
||||||
|
tz = zoneinfo.ZoneInfo(up.timezone)
|
||||||
|
#
|
||||||
|
return datetime.fromtimestamp(tm, tz).strftime('%Y-%m-%d %H:%M')
|
||||||
|
#
|
||||||
|
ctime = str_date(self._meta_data.get(self._meta_data.KEY_CREATION_TIME))
|
||||||
|
mtime = str_date(self._meta_data.get(self._meta_data.KEY_MODIFIED_TIME))
|
||||||
user = self._meta_data.get(self._meta_data.KEY_MODIFIED_USER)
|
user = self._meta_data.get(self._meta_data.KEY_MODIFIED_USER)
|
||||||
#
|
#
|
||||||
meta = f'|{_("Created")}:|{ctime}|\n'
|
meta = f'|{_("Created")}:|{ctime}|\n'
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
from datetime import datetime
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
import fstools
|
import fstools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from whoosh.fields import Schema, ID, TEXT, DATETIME
|
from whoosh.fields import Schema, ID, TEXT
|
||||||
from whoosh.qparser.dateparse import DateParserPlugin
|
from whoosh.qparser.dateparse import DateParserPlugin
|
||||||
from whoosh import index, qparser
|
from whoosh import index, qparser
|
||||||
|
|
||||||
@ -17,11 +16,7 @@ SCHEMA = Schema(
|
|||||||
id=ID(unique=True, stored=True),
|
id=ID(unique=True, stored=True),
|
||||||
# Page
|
# Page
|
||||||
title=TEXT,
|
title=TEXT,
|
||||||
page_src=TEXT,
|
page_src=TEXT
|
||||||
# metadata
|
|
||||||
creation_time=DATETIME,
|
|
||||||
modified_time=DATETIME,
|
|
||||||
modified_user=TEXT
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -60,13 +55,8 @@ def add_item(ix, bp: base_page):
|
|||||||
#
|
#
|
||||||
data = dict(
|
data = dict(
|
||||||
id=bp.rel_path,
|
id=bp.rel_path,
|
||||||
#
|
|
||||||
title=bp.title,
|
title=bp.title,
|
||||||
page_src=bp.raw_page_src,
|
page_src=bp.raw_page_src
|
||||||
#
|
|
||||||
creation_time=datetime.fromtimestamp(bp._meta_data.get(bp._meta_data.KEY_CREATION_TIME)),
|
|
||||||
modified_time=datetime.fromtimestamp(bp._meta_data.get(bp._meta_data.KEY_MODIFIED_TIME)),
|
|
||||||
modified_user=bp._meta_data.get(bp._meta_data.KEY_MODIFIED_USER)
|
|
||||||
)
|
)
|
||||||
with ix.writer() as w:
|
with ix.writer() as w:
|
||||||
logger.info('Adding document with id=%s to the search index.', data.get('id'))
|
logger.info('Adding document with id=%s to the search index.', data.get('id'))
|
||||||
@ -103,3 +93,4 @@ def update_item(bp: base_page):
|
|||||||
ix = load_index()
|
ix = load_index()
|
||||||
delete_item(ix, bp)
|
delete_item(ix, bp)
|
||||||
add_item(ix, bp)
|
add_item(ix, bp)
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import messages as django_messages
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse, HttpResponseRedirect
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
@ -108,7 +107,7 @@ def search(request):
|
|||||||
|
|
||||||
sr = whoosh_search(search_txt)
|
sr = whoosh_search(search_txt)
|
||||||
if sr is None:
|
if sr is None:
|
||||||
django_messages.error(request, _('Invalid search pattern: %s') % repr(search_txt))
|
messages.error(request, _('Invalid search pattern: %s') % repr(search_txt))
|
||||||
sr = []
|
sr = []
|
||||||
page_content = "= Searchresults\n"
|
page_content = "= Searchresults\n"
|
||||||
for rel_path in sr:
|
for rel_path in sr:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user