diff --git a/ctl b/ctl index da1dcd63..1b93c214 100755 --- a/ctl +++ b/ctl @@ -9,33 +9,37 @@ fi if [ "$action" = "init" ]; then cd "`dirname "$0"`" BASE=`pwd` - python3 -m venv --system-site-packages . - + SUDO="" + PANDORA_USER=`ls -l update.py | cut -f3 -d" "` + if [ `whoami` != $PANDORA_USER ]; then + SUDO="sudo -H -u $PANDORA_USER" + fi + $SUDO python3 -m venv --system-site-packages . branch=`cat .git/HEAD | sed 's@/@\n@g' | tail -n1` # Work around broken venv module in Ubuntu 16.04 / Debian 9 if [ ! -e bin/pip ]; then - bin/python3 -m pip install -U --ignore-installed "pip<9" + $SUDO bin/python3 -m pip install -U --ignore-installed "pip<9" fi if [ ! -d static/oxjs ]; then - git clone --depth 1 -b $branch https://git.0x2620.org/oxjs.git static/oxjs + $SUDO git clone --depth 1 -b $branch https://git.0x2620.org/oxjs.git static/oxjs fi - mkdir -p src + $SUDO mkdir -p src if [ ! -d src/oxtimelines ]; then - git clone --depth 1 -b $branch https://git.0x2620.org/oxtimelines.git src/oxtimelines + $SUDO git clone --depth 1 -b $branch https://git.0x2620.org/oxtimelines.git src/oxtimelines fi for package in oxtimelines python-ox; do cd ${BASE} if [ ! -d src/${package} ]; then - git clone --depth 1 -b $branch https://git.0x2620.org/${package}.git src/${package} + $SUDO git clone --depth 1 -b $branch https://git.0x2620.org/${package}.git src/${package} fi cd ${BASE}/src/${package} - ${BASE}/bin/python setup.py develop + $SUDO ${BASE}/bin/python setup.py develop done cd ${BASE} - ./bin/pip install -r requirements.txt + $SUDO ./bin/pip install -r requirements.txt if [ ! -e pandora/gunicorn_config.py ]; then - cp pandora/gunicorn_config.py.in pandora/gunicorn_config.py + $SUDO cp pandora/gunicorn_config.py.in pandora/gunicorn_config.py fi exit 0 fi diff --git a/pandora/app/config.py b/pandora/app/config.py index b20686c3..8b5b98f7 100644 --- a/pandora/app/config.py +++ b/pandora/app/config.py @@ -86,6 +86,21 @@ def load_config(init=False): # enable default filters if needed default_filters = [f['id'] for f in config['user']['ui']['filters']] + available_filters = [key['id'] for key in config['itemKeys'] if key.get('filter')] + unknown_ids = set(default_filters) - set(available_filters) + if unknown_ids: + sys.stderr.write('WARNING: unknown item keys in default filters: %s.\n' % list(unknown_ids)) + unused_filters = [key for key in available_filters if key not in default_filters] + if len(unused_filters) < len(unknown_ids): + sys.stderr.write('you need at least 5 item filters') + else: + auto_filters = unused_filters[:len(unknown_ids)] + default_filters += auto_filters + for key in auto_filters: + config['user']['ui']['filters'].append({ + "id": key, "sort": [{"key": "items", "operator": "-"}] + }) + sys.stderr.write(' using the following document filters instead: %s.\n' % auto_filters) for key in config['itemKeys']: if key['id'] in default_filters and not key.get('filter'): key['filter'] = True @@ -93,6 +108,22 @@ def load_config(init=False): # enable default document filters if needed default_filters = [f['id'] for f in config['user']['ui']['documentFilters']] + available_filters = [key['id'] for key in config['documentKeys'] if key.get('filter')] + unknown_ids = set(default_filters) - set(available_filters) + if unknown_ids: + sys.stderr.write('WARNING: unknown document keys in default filters: %s.\n' % list(unknown_ids)) + unused_filters = [key for key in available_filters if key not in default_filters] + if len(unused_filters) < len(unknown_ids): + sys.stderr.write('you need at least 5 item filters') + else: + auto_filters = unused_filters[:len(unknown_ids)] + default_filters += auto_filters + for key in auto_filters: + config['user']['ui']['documentFilters'].append({ + "id": key, "sort": [{"key": "items", "operator": "-"}] + }) + sys.stderr.write(' using the following document filters instead: %s.\n' % auto_filters) + for key in config['documentKeys']: if key['id'] in default_filters and not key.get('filter'): key['filter'] = True diff --git a/pandora/item/management/commands/sync_itemsort.py b/pandora/item/management/commands/sync_itemsort.py index d70889ac..8af5e14a 100644 --- a/pandora/item/management/commands/sync_itemsort.py +++ b/pandora/item/management/commands/sync_itemsort.py @@ -107,6 +107,8 @@ class Command(BaseCommand): print(sql) cursor.execute(sql) transaction.commit() + for i in models.Item.objects.filter(sort=None): + i.save() if rebuild: print("Updating sort values...") ids = [i['id'] for i in models.Item.objects.all().values('id')] @@ -115,3 +117,5 @@ class Command(BaseCommand): if options['debug']: print(i) i.update_sort() + for i in models.Item.objects.filter(sort=None): + i.save() diff --git a/vm/pandora_install.sh b/vm/pandora_install.sh index 1c635773..5f957bb2 100755 --- a/vm/pandora_install.sh +++ b/vm/pandora_install.sh @@ -129,6 +129,7 @@ fi git clone https://git.0x2620.org/pandora.git /srv/pandora cd /srv/pandora git checkout $BRANCH +chown -R $PANDORA:$PANDORA /srv/pandora ./ctl init # create config.jsonc from templates in git