Compare commits

...

4 commits

Author SHA1 Message Date
j
ae211e0e95 fix permissions 2019-12-20 16:59:42 +02:00
j
b711d65bea run ctl init as pandora user 2019-12-20 16:08:22 +02:00
j
2b1e33df48 try to work around filter configuration issues 2019-12-20 16:07:42 +02:00
j
246413027c fix items without sort 2019-12-19 21:14:46 +02:00
4 changed files with 50 additions and 10 deletions

24
ctl
View file

@ -9,33 +9,37 @@ fi
if [ "$action" = "init" ]; then if [ "$action" = "init" ]; then
cd "`dirname "$0"`" cd "`dirname "$0"`"
BASE=`pwd` 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` branch=`cat .git/HEAD | sed 's@/@\n@g' | tail -n1`
# Work around broken venv module in Ubuntu 16.04 / Debian 9 # Work around broken venv module in Ubuntu 16.04 / Debian 9
if [ ! -e bin/pip ]; then 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 fi
if [ ! -d static/oxjs ]; then 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 fi
mkdir -p src $SUDO mkdir -p src
if [ ! -d src/oxtimelines ]; then 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 fi
for package in oxtimelines python-ox; do for package in oxtimelines python-ox; do
cd ${BASE} cd ${BASE}
if [ ! -d src/${package} ]; then 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 fi
cd ${BASE}/src/${package} cd ${BASE}/src/${package}
${BASE}/bin/python setup.py develop $SUDO ${BASE}/bin/python setup.py develop
done done
cd ${BASE} cd ${BASE}
./bin/pip install -r requirements.txt $SUDO ./bin/pip install -r requirements.txt
if [ ! -e pandora/gunicorn_config.py ]; then 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 fi
exit 0 exit 0
fi fi

View file

@ -86,6 +86,21 @@ def load_config(init=False):
# enable default filters if needed # enable default filters if needed
default_filters = [f['id'] for f in config['user']['ui']['filters']] 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']: for key in config['itemKeys']:
if key['id'] in default_filters and not key.get('filter'): if key['id'] in default_filters and not key.get('filter'):
key['filter'] = True key['filter'] = True
@ -93,6 +108,22 @@ def load_config(init=False):
# enable default document filters if needed # enable default document filters if needed
default_filters = [f['id'] for f in config['user']['ui']['documentFilters']] 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']: for key in config['documentKeys']:
if key['id'] in default_filters and not key.get('filter'): if key['id'] in default_filters and not key.get('filter'):
key['filter'] = True key['filter'] = True

View file

@ -107,6 +107,8 @@ class Command(BaseCommand):
print(sql) print(sql)
cursor.execute(sql) cursor.execute(sql)
transaction.commit() transaction.commit()
for i in models.Item.objects.filter(sort=None):
i.save()
if rebuild: if rebuild:
print("Updating sort values...") print("Updating sort values...")
ids = [i['id'] for i in models.Item.objects.all().values('id')] ids = [i['id'] for i in models.Item.objects.all().values('id')]
@ -115,3 +117,5 @@ class Command(BaseCommand):
if options['debug']: if options['debug']:
print(i) print(i)
i.update_sort() i.update_sort()
for i in models.Item.objects.filter(sort=None):
i.save()

View file

@ -129,6 +129,7 @@ fi
git clone https://git.0x2620.org/pandora.git /srv/pandora git clone https://git.0x2620.org/pandora.git /srv/pandora
cd /srv/pandora cd /srv/pandora
git checkout $BRANCH git checkout $BRANCH
chown -R $PANDORA:$PANDORA /srv/pandora
./ctl init ./ctl init
# create config.jsonc from templates in git # create config.jsonc from templates in git