buku/bukuserver/server.py

621 lines
23 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2018-03-30 07:25:28 -05:00
# pylint: disable=wrong-import-order, ungrouped-imports
2018-03-27 21:16:54 -05:00
"""Server module."""
2018-03-26 07:06:12 -05:00
import os
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
import sys
from urllib.parse import urlparse
2018-03-26 07:06:12 -05:00
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
from buku import BukuDb, __version__, network_handler
from flask.cli import FlaskGroup
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
from flask_admin import Admin
from flask_api import exceptions, FlaskAPI, status
from flask_bootstrap import Bootstrap
2018-03-26 07:06:12 -05:00
from flask_paginate import Pagination, get_page_parameter, get_per_page_parameter
2018-03-30 07:25:28 -05:00
from markupsafe import Markup
import click
import flask
2019-04-27 19:13:56 -05:00
from flask import ( # type: ignore
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
__version__ as flask_version,
2018-03-31 23:41:23 -05:00
abort,
2018-03-30 07:25:28 -05:00
current_app,
flash,
jsonify,
redirect,
render_template,
request,
url_for,
)
2017-03-28 13:28:23 -05:00
2018-03-23 19:21:45 -05:00
try:
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
from . import response, forms, views
2018-03-23 19:21:45 -05:00
except ImportError:
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
from bukuserver import response, forms, views
2017-03-28 13:28:23 -05:00
2018-03-26 07:06:12 -05:00
STATISTIC_DATA = None
def get_bukudb():
"""get bukudb instance"""
db_file = current_app.config.get('BUKUSERVER_DB_FILE', None)
return BukuDb(dbfile=db_file)
2018-03-26 07:06:12 -05:00
2017-03-28 13:28:23 -05:00
def get_tags():
"""get tags."""
tags = getattr(flask.g, 'bukudb', get_bukudb()).get_tag_all()
2017-03-28 13:28:23 -05:00
result = {
'tags': tags[0]
}
if request.path.startswith('/api/'):
res = jsonify(result)
else:
res = render_template('bukuserver/tags.html', result=result)
return res
2017-03-28 13:28:23 -05:00
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
def network_handle_detail():
failed_resp = response.response_template['failure'], status.HTTP_400_BAD_REQUEST
url = request.data.get('url', None)
if not url:
return failed_resp
try:
res = network_handler(url)
return {'title': res[0], 'recognized mime': res[1], 'bad url': res[2]}
except Exception as e:
current_app.logger.debug(str(e))
return failed_resp
def tag_list():
tags = get_bukudb().get_tag_all()
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
result = {'tags': tags[0]}
return result
def tag_detail(tag):
bukudb = get_bukudb()
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
if request.method == 'GET':
tags = bukudb.get_tag_all()
if tag not in tags[1]:
raise exceptions.NotFound()
res = dict(name=tag, usage_count=tags[1][tag])
elif request.method == 'PUT':
res = None
try:
new_tags = request.data.get('tags').split(',')
except AttributeError as e:
raise exceptions.ParseError(detail=str(e))
result_flag = bukudb.replace_tag(tag, new_tags)
if result_flag:
res = response.response_template['success'], status.HTTP_200_OK
else:
res = response.response_template['failure'], status.HTTP_400_BAD_REQUEST
return res
2017-03-28 13:28:23 -05:00
def update_tag(tag):
2018-03-26 07:30:40 -05:00
res = None
2018-03-31 23:41:23 -05:00
if request.method in ('PUT', 'POST'):
new_tags = request.form.getlist('tags')
result_flag = getattr(flask.g, 'bukudb', get_bukudb()).replace_tag(tag, new_tags)
2018-03-31 23:41:23 -05:00
op_text = 'replace tag [{}] with [{}]'.format(tag, ', '.join(new_tags))
if request.method == 'PUT' and result_flag and request.path.startswith('/api/'):
res = (jsonify(response.response_template['success']),
status.HTTP_200_OK,
{'ContentType': 'application/json'})
2018-03-31 23:41:23 -05:00
elif request.method == 'PUT' and request.path.startswith('/api/'):
res = (jsonify(response.response_template['failure']),
status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'})
2018-03-31 23:41:23 -05:00
elif request.method == 'POST' and result_flag:
flash(Markup('Success {}'.format(op_text)), 'success')
res = redirect(url_for('get_tags-html'))
elif request.method == 'POST':
flash(Markup('Failed {}'.format(op_text)), 'danger')
res = redirect(url_for('get_tags-html'))
else:
abort(400, description="Unknown Condition")
2018-03-26 07:30:40 -05:00
return res
2017-03-28 13:28:23 -05:00
def bookmarks():
"""Bookmarks."""
res = None
bukudb = getattr(flask.g, 'bukudb', get_bukudb())
2018-03-26 07:06:12 -05:00
page = request.args.get(get_page_parameter(), type=int, default=1)
per_page = request.args.get(
get_per_page_parameter(),
type=int,
default=int(
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
current_app.config.get('BUKUSERVER_PER_PAGE', views.DEFAULT_PER_PAGE))
2018-03-26 07:06:12 -05:00
)
2018-05-08 18:33:49 -05:00
url_render_mode = current_app.config['BUKUSERVER_URL_RENDER_MODE']
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
create_bookmarks_form = forms.BookmarkForm()
2017-03-28 13:28:23 -05:00
if request.method == 'GET':
2018-03-23 07:42:28 -05:00
all_bookmarks = bukudb.get_rec_all()
2017-03-28 13:28:23 -05:00
result = {
'bookmarks': []
}
for bookmark in all_bookmarks:
result_bookmark = {
'url': bookmark[1],
'title': bookmark[2],
'tags': list([_f for _f in bookmark[3].split(',') if _f]),
2017-03-28 13:28:23 -05:00
'description': bookmark[4]
}
2018-04-03 05:01:03 -05:00
if not request.path.startswith('/api/'):
2018-04-03 05:13:22 -05:00
result_bookmark['id'] = bookmark[0]
2017-03-28 13:28:23 -05:00
result['bookmarks'].append(result_bookmark)
if request.path.startswith('/api/'):
res = jsonify(result)
else:
if request.args.getlist('tag'):
tags = request.args.getlist('tag')
result['bookmarks'] = [
x for x in result['bookmarks']
if set(tags).issubset(set(x['tags']))
]
2018-03-26 07:30:40 -05:00
current_app.logger.debug('total bookmarks:{}'.format(len(result['bookmarks'])))
current_app.logger.debug('per page:{}'.format(per_page))
2018-03-26 07:06:12 -05:00
pagination_total = len(result['bookmarks'])
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
bms = list(views.chunks(result['bookmarks'], per_page))
2018-03-28 15:40:00 -05:00
try:
result['bookmarks'] = bms[page-1]
except IndexError as err:
current_app.logger.debug('{}:{}, result bookmarks:{}, page:{}'.format(
type(err), err, len(result['bookmarks']), page
))
2018-03-26 07:06:12 -05:00
pagination = Pagination(
page=page, total=pagination_total, per_page=per_page,
search=False, record_name='bookmarks', bs_version=3
)
res = render_template(
2018-03-26 07:06:12 -05:00
'bukuserver/bookmarks.html',
result=result,
2018-03-27 21:16:54 -05:00
pagination=pagination,
search_bookmarks_form=forms.SearchBookmarksForm(),
2018-03-30 07:25:28 -05:00
create_bookmarks_form=create_bookmarks_form,
2018-05-08 18:33:49 -05:00
url_render_mode=url_render_mode,
2018-03-26 07:06:12 -05:00
)
2017-03-28 13:28:23 -05:00
elif request.method == 'POST':
2018-03-30 07:25:28 -05:00
url_data = create_bookmarks_form.url.data
2018-03-23 07:42:28 -05:00
result_flag = bukudb.add_rec(
2018-03-30 07:25:28 -05:00
url_data,
create_bookmarks_form.title.data,
create_bookmarks_form.tags.data,
create_bookmarks_form.description.data
)
if request.path.startswith('/api/'):
res = [
jsonify(response.response_template['success']), status.HTTP_200_OK,
{'ContentType': 'application/json'}
] if result_flag != -1 else [
jsonify(response.response_template['failure']), status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'}
]
else:
bm_text = '[<a href="{0}">{0}</a>]'.format(url_data)
if result_flag != -1:
flash(Markup('Success creating bookmark {}.'.format(bm_text)), 'success')
else:
flash(Markup('Failed creating bookmark {}.'.format(bm_text)), 'danger')
return redirect(url_for('bookmarks-html'))
2017-03-28 13:28:23 -05:00
elif request.method == 'DELETE':
2018-03-23 07:42:28 -05:00
result_flag = bukudb.cleardb()
res = [
jsonify(response.response_template['success']), status.HTTP_200_OK,
{'ContentType': 'application/json'}
] if result_flag else [
jsonify(response.response_template['failure']), status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'}
]
return res
2017-03-28 13:28:23 -05:00
def refresh_bookmarks():
2018-03-26 07:30:40 -05:00
res = None
2017-03-28 13:28:23 -05:00
if request.method == 'POST':
print(request.form['index'])
print(request.form['threads'])
result_flag = getattr(
flask.g,
'bukudb',
get_bukudb()).refreshdb(request.form['index'], request.form['threads'])
2017-03-28 13:28:23 -05:00
if result_flag:
res = (jsonify(response.response_template['success']),
status.HTTP_200_OK,
{'ContentType': 'application/json'})
2017-03-28 13:28:23 -05:00
else:
res = (jsonify(response.response_template['failure']),
status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'})
2018-03-26 07:30:40 -05:00
return res
2017-03-28 13:28:23 -05:00
def bookmark_api(id):
2018-03-26 07:30:40 -05:00
res = None
2017-03-28 13:28:23 -05:00
try:
id = int(id)
except ValueError:
return jsonify(response.response_template['failure']), status.HTTP_400_BAD_REQUEST, \
{'ContentType': 'application/json'}
bukudb = getattr(flask.g, 'bukudb', get_bukudb())
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
bookmark_form = forms.BookmarkForm()
2018-04-03 05:01:03 -05:00
is_html_post_request = request.method == 'POST' and not request.path.startswith('/api/')
2017-03-28 13:28:23 -05:00
if request.method == 'GET':
2018-03-23 07:42:28 -05:00
bookmark = bukudb.get_rec_by_id(id)
2017-03-28 13:28:23 -05:00
if bookmark is not None:
result = {
'url': bookmark[1],
'title': bookmark[2],
'tags': list([_f for _f in bookmark[3].split(',') if _f]),
2017-03-28 13:28:23 -05:00
'description': bookmark[4]
}
2018-04-03 05:01:03 -05:00
if request.path.startswith('/api/'):
res = jsonify(result)
else:
bookmark_form.url.data = result['url']
bookmark_form.title.data = result['title']
bookmark_form.tags.data = bookmark[3]
bookmark_form.description.data = result['description']
res = render_template(
'bukuserver/bookmark_edit.html',
result=result,
bookmark_form=bookmark_form,
bookmark_id=bookmark[0]
)
2017-03-28 13:28:23 -05:00
else:
2018-04-03 05:01:03 -05:00
res = jsonify(response.response_template['failure']), status.HTTP_400_BAD_REQUEST, \
2017-03-28 13:28:23 -05:00
{'ContentType': 'application/json'}
2018-04-03 05:01:03 -05:00
elif request.method == 'PUT' or is_html_post_request:
if request.method == 'PUT':
result_flag = bukudb.update_rec(
id,
request.form['url'],
request.form.get('title'),
request.form['tags'],
request.form['description'])
2018-04-03 05:01:03 -05:00
if result_flag and not is_html_post_request:
res = (jsonify(response.response_template['success']),
status.HTTP_200_OK,
{'ContentType': 'application/json'})
2018-04-03 05:01:03 -05:00
elif not result_flag and not is_html_post_request:
res = (jsonify(response.response_template['failure']),
status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'})
2018-04-03 05:01:03 -05:00
elif is_html_post_request:
result_flag = bukudb.update_rec(
id,
bookmark_form.url.data,
bookmark_form.title.data,
bookmark_form.tags.data,
bookmark_form.description.data)
2018-04-03 05:01:03 -05:00
if result_flag:
flash(Markup('Success edit bookmark, id:{}'.format(id)), 'success')
else:
flash(Markup('Failed edit bookmark, id:{}'.format(id)), 'danger')
res = redirect(url_for('bookmarks-html'))
2017-03-28 13:28:23 -05:00
else:
2018-04-03 05:01:03 -05:00
abort(400, description="Unknown Condition")
2017-03-28 13:28:23 -05:00
else:
2018-03-23 07:42:28 -05:00
result_flag = bukudb.delete_rec(id)
2017-03-28 13:28:23 -05:00
if result_flag:
res = (jsonify(response.response_template['success']),
status.HTTP_200_OK,
{'ContentType': 'application/json'})
2017-03-28 13:28:23 -05:00
else:
res = (jsonify(response.response_template['failure']),
status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'})
2018-03-26 07:30:40 -05:00
return res
2017-03-28 13:28:23 -05:00
def refresh_bookmark(id):
try:
id = int(id)
except ValueError:
return jsonify(response.response_template['failure']), status.HTTP_400_BAD_REQUEST, \
{'ContentType': 'application/json'}
2018-03-26 07:30:40 -05:00
res = None
2017-03-28 13:28:23 -05:00
if request.method == 'POST':
result_flag = getattr(flask.g, 'bukudb',
get_bukudb()).refreshdb(id, request.form['threads'])
2017-03-28 13:28:23 -05:00
if result_flag:
res = (jsonify(response.response_template['success']),
status.HTTP_200_OK,
{'ContentType': 'application/json'})
2017-03-28 13:28:23 -05:00
else:
res = (jsonify(response.response_template['failure']),
status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'})
2018-03-26 07:30:40 -05:00
return res
2017-03-28 13:28:23 -05:00
def get_tiny_url(id):
try:
id = int(id)
except ValueError:
return jsonify(response.response_template['failure']), status.HTTP_400_BAD_REQUEST, \
{'ContentType': 'application/json'}
2018-03-26 07:30:40 -05:00
res = None
2017-03-28 13:28:23 -05:00
if request.method == 'GET':
shortened_url = getattr(flask.g, 'bukudb', get_bukudb()).tnyfy_url(id)
2017-03-28 13:28:23 -05:00
if shortened_url is not None:
result = {
'url': shortened_url
}
2018-03-26 07:30:40 -05:00
res = jsonify(result)
2017-03-28 13:28:23 -05:00
else:
res = (jsonify(response.response_template['failure']),
status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'})
2018-03-26 07:30:40 -05:00
return res
2017-03-28 13:28:23 -05:00
def get_long_url(id):
try:
id = int(id)
except ValueError:
return jsonify(response.response_template['failure']), status.HTTP_400_BAD_REQUEST, \
{'ContentType': 'application/json'}
2018-03-26 07:30:40 -05:00
res = None
2017-03-28 13:28:23 -05:00
if request.method == 'GET':
bookmark = getattr(flask.g, 'bukudb', get_bukudb()).get_rec_by_id(id)
2017-03-28 13:28:23 -05:00
if bookmark is not None:
result = {
'url': bookmark[1],
}
2018-03-26 07:30:40 -05:00
res = jsonify(result)
2017-03-28 13:28:23 -05:00
else:
res = (jsonify(response.response_template['failure']),
status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'})
2018-03-26 07:30:40 -05:00
return res
2017-03-28 13:28:23 -05:00
def bookmark_range_operations(starting_id, ending_id):
try:
starting_id = int(starting_id)
ending_id = int(ending_id)
except ValueError:
return jsonify(response.response_template['failure']), status.HTTP_400_BAD_REQUEST, \
{'ContentType': 'application/json'}
2018-03-26 07:30:40 -05:00
res = None
bukudb = getattr(flask.g, 'bukudb', get_bukudb())
2018-03-23 07:42:28 -05:00
max_id = bukudb.get_max_id()
2017-03-28 13:28:23 -05:00
if starting_id > max_id or ending_id > max_id:
return jsonify(response.response_template['failure']), status.HTTP_400_BAD_REQUEST, \
{'ContentType': 'application/json'}
if request.method == 'GET':
result = {
'bookmarks': {}
}
for i in range(starting_id, ending_id + 1, 1):
2018-03-23 07:42:28 -05:00
bookmark = bukudb.get_rec_by_id(i)
result['bookmarks'][i] = {
2017-03-28 13:28:23 -05:00
'url': bookmark[1],
'title': bookmark[2],
'tags': list([_f for _f in bookmark[3].split(',') if _f]),
2017-03-28 13:28:23 -05:00
'description': bookmark[4]
}
2018-03-26 07:30:40 -05:00
res = jsonify(result)
2017-03-28 13:28:23 -05:00
elif request.method == 'DELETE':
for i in range(starting_id, ending_id + 1, 1):
2018-03-23 07:42:28 -05:00
result_flag = bukudb.delete_rec(i)
2017-03-28 13:28:23 -05:00
if result_flag is False:
return (jsonify(response.response_template['failure']),
status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'})
res = (jsonify(response.response_template['success']),
status.HTTP_200_OK,
{'ContentType': 'application/json'})
2017-03-28 13:28:23 -05:00
elif request.method == 'PUT':
for i in range(starting_id, ending_id + 1, 1):
updated_bookmark = request.form[str(i)]
2018-03-23 07:42:28 -05:00
result_flag = bukudb.update_rec(
i,
updated_bookmark['url'],
updated_bookmark['title'],
updated_bookmark['tags'],
updated_bookmark['description'])
2017-03-28 13:28:23 -05:00
if result_flag is False:
return (jsonify(response.response_template['failure']),
status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'})
2018-03-26 07:30:40 -05:00
res = jsonify(response.response_template['success']), status.HTTP_200_OK, \
2017-03-28 13:28:23 -05:00
{'ContentType': 'application/json'}
2018-03-26 07:30:40 -05:00
return res
2017-03-28 13:28:23 -05:00
def search_bookmarks():
2018-03-26 20:08:58 -05:00
arg_obj = request.form if request.method == 'DELETE' else request.args
2018-03-27 21:16:54 -05:00
search_bookmarks_form = forms.SearchBookmarksForm(request.args)
2018-03-26 20:08:58 -05:00
is_api_request_path = request.path.startswith('/api/')
if is_api_request_path:
2018-03-27 21:16:54 -05:00
keywords = arg_obj.getlist('keywords')
all_keywords = arg_obj.get('all_keywords')
deep = arg_obj.get('deep')
regex = arg_obj.get('regex')
# api request is more strict
2018-03-26 20:08:58 -05:00
all_keywords = False if all_keywords is None else all_keywords
deep = False if deep is None else deep
regex = False if regex is None else regex
all_keywords = (
all_keywords if isinstance(all_keywords, bool) else
all_keywords.lower() == 'true'
)
deep = deep if isinstance(deep, bool) else deep.lower() == 'true'
regex = regex if isinstance(regex, bool) else regex.lower() == 'true'
2018-03-27 21:16:54 -05:00
else:
keywords = search_bookmarks_form.keywords.data
all_keywords = search_bookmarks_form.all_keywords.data
deep = search_bookmarks_form.deep.data
regex = search_bookmarks_form.regex.data
2017-03-28 13:28:23 -05:00
result = {'bookmarks': []}
bukudb = getattr(flask.g, 'bukudb', get_bukudb())
2018-03-23 07:42:28 -05:00
found_bookmarks = bukudb.searchdb(keywords, all_keywords, deep, regex)
2018-03-26 20:08:58 -05:00
found_bookmarks = [] if found_bookmarks is None else found_bookmarks
page = request.args.get(get_page_parameter(), type=int, default=1)
per_page = request.args.get(
get_per_page_parameter(),
type=int,
default=int(
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
current_app.config.get('BUKUSERVER_PER_PAGE', views.DEFAULT_PER_PAGE))
2018-03-26 20:08:58 -05:00
)
2017-03-28 13:28:23 -05:00
2018-03-26 07:30:40 -05:00
res = None
2017-03-28 13:28:23 -05:00
if request.method == 'GET':
if bookmarks is not None:
for bookmark in found_bookmarks:
result_bookmark = {
'id': bookmark[0],
'url': bookmark[1],
'title': bookmark[2],
'tags': list([_f for _f in bookmark[3].split(',') if _f]),
2017-03-28 13:28:23 -05:00
'description': bookmark[4]
}
result['bookmarks'].append(result_bookmark)
current_app.logger.debug('total bookmarks:{}'.format(len(result['bookmarks'])))
2018-03-26 20:08:58 -05:00
if is_api_request_path:
res = jsonify(result)
2018-03-26 20:08:58 -05:00
else:
pagination_total = len(result['bookmarks'])
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
bms = list(views.chunks(result['bookmarks'], per_page))
2018-03-28 15:49:02 -05:00
try:
result['bookmarks'] = bms[page-1]
except IndexError as err:
current_app.logger.debug('{}:{}, result bookmarks:{}, page:{}'.format(
type(err), err, len(result['bookmarks']), page
))
2018-03-26 20:08:58 -05:00
pagination = Pagination(
page=page, total=pagination_total, per_page=per_page,
search=False, record_name='bookmarks', bs_version=3
)
2018-03-27 21:16:54 -05:00
res = render_template(
'bukuserver/bookmarks.html',
result=result, pagination=pagination,
2018-03-31 03:43:38 -05:00
search_bookmarks_form=search_bookmarks_form,
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
create_bookmarks_form=forms.BookmarkForm(),
2018-03-31 03:43:38 -05:00
)
2017-03-28 13:28:23 -05:00
elif request.method == 'DELETE':
if found_bookmarks is not None:
for bookmark in found_bookmarks:
2018-03-23 07:42:28 -05:00
result_flag = bukudb.delete_rec(bookmark[0])
2017-03-28 13:28:23 -05:00
if result_flag is False:
res = (jsonify(response.response_template['failure']),
status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'})
2018-03-26 07:30:40 -05:00
if res is None:
res = (jsonify(response.response_template['success']),
status.HTTP_200_OK,
{'ContentType': 'application/json'})
2018-03-26 07:30:40 -05:00
return res
2017-03-28 13:28:23 -05:00
def create_app(config_filename=None):
"""create app."""
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
app = FlaskAPI(__name__)
2018-07-18 15:57:15 -05:00
per_page = int(os.getenv('BUKUSERVER_PER_PAGE', str(views.DEFAULT_PER_PAGE)))
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
per_page = per_page if per_page > 0 else views.DEFAULT_PER_PAGE
2018-05-02 07:31:45 -05:00
app.config['BUKUSERVER_PER_PAGE'] = per_page
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
url_render_mode = os.getenv('BUKUSERVER_URL_RENDER_MODE', views.DEFAULT_URL_RENDER_MODE)
2018-05-08 18:33:49 -05:00
if url_render_mode not in ('full', 'netloc'):
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
url_render_mode = views.DEFAULT_URL_RENDER_MODE
2018-05-08 18:33:49 -05:00
app.config['BUKUSERVER_URL_RENDER_MODE'] = url_render_mode
2018-05-02 07:34:01 -05:00
app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SECRET_KEY') or os.urandom(24)
app.config['BUKUSERVER_DB_FILE'] = os.getenv('BUKUSERVER_DB_FILE')
bukudb = BukuDb(dbfile=app.config['BUKUSERVER_DB_FILE'])
app.app_context().push()
setattr(flask.g, 'bukudb', bukudb)
@app.shell_context_processor
def shell_context():
"""Shell context definition."""
return {'app': app, 'bukudb': bukudb}
2018-05-01 04:55:44 -05:00
app.jinja_env.filters['netloc'] = lambda x: urlparse(x).netloc # pylint: disable=no-member
Bootstrap(app)
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
admin = Admin(
app, name='Buku Server', template_mode='bootstrap3',
index_view=views.CustomAdminIndexView(
template='bukuserver/home.html', url='/'
)
)
# routing
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
# api
app.add_url_rule('/api/tags', 'get_tags', tag_list, methods=['GET'])
app.add_url_rule('/api/tags/<tag>', 'update_tag', tag_detail, methods=['GET', 'PUT'])
app.add_url_rule(
'/api/network_handle',
'networkk_handle',
network_handle_detail,
methods=['POST'])
app.add_url_rule('/api/bookmarks', 'bookmarks', bookmarks, methods=['GET', 'POST', 'DELETE'])
app.add_url_rule(
'/api/bookmarks/refresh',
'refresh_bookmarks',
refresh_bookmarks,
methods=['POST'])
app.add_url_rule(
'/api/bookmarks/<id>',
'bookmark_api',
bookmark_api,
methods=['GET', 'PUT', 'DELETE'])
app.add_url_rule(
'/api/bookmarks/<id>/refresh',
'refresh_bookmark',
refresh_bookmark,
methods=['POST'])
app.add_url_rule('/api/bookmarks/<id>/tiny', 'get_tiny_url', get_tiny_url, methods=['GET'])
app.add_url_rule('/api/bookmarks/<id>/long', 'get_long_url', get_long_url, methods=['GET'])
app.add_url_rule(
'/api/bookmarks/<starting_id>/<ending_id>',
'bookmark_range_operations', bookmark_range_operations, methods=['GET', 'PUT', 'DELETE'])
app.add_url_rule(
'/api/bookmarks/search',
'search_bookmarks',
search_bookmarks,
methods=['GET', 'DELETE'])
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
# non api
admin.add_view(views.BookmarkModelView(
bukudb, 'Bookmarks', page_size=per_page, url_render_mode=url_render_mode))
admin.add_view(views.TagModelView(
bukudb, 'Tags', page_size=per_page))
admin.add_view(views.StatisticView(
bukudb, 'Statistic', endpoint='statistic'))
return app
Feature/server (#289) * new: dev: version flag fix: dev: pylint error * chg: dev: sort route !cosmetic * new: dev: custom BaseModelView for buku bookmark * new: dev: formatted entry * new: dev: url render mode * new: dev: bookmark edit !wip * chg: dev: use existing form for bookmark * chg: dev: form name !refactor * new: dev: enable details views * new: dev: views module * new: dev: tag model view * chg: dev: only split page_size defined * chg: dev: use SelectMultipleField * fix: dev: Bookmark tags choices * chg dev: configure tags * chg: dev: tag edit form !wip * chg: dev: update bookmark model * chg: dev: remove unused function * new: dev: add flask wtf and admin * chg: dev: use SimpleNamespace instead namedtuple * new: dev: delete tags feature * new: dev: chatty parameter for delete_tag_at_index * fix: dev: skip confirmation when deleting tag * fix: dev: when update bookmark model * new: dev: update tag * chg: dev: use parse_tags method * new: dev: select2 field for tagsfield * chg: dev: remove unused code * fix: dev: syntax * fix: dev: update bookmark model * chg: dev: change api based on flask-api * fix: dev: new tags on tag_detail PUT * chg: dev: raise error when parsing failed * chg: dev: move server required package * new: dev: create_model * chg: dev: override abstract method model view class * chg: dev: delete model for bookmark * fix: dev: pylint ignore !cosmetic * new: dev: filter for tag * chg: dev: more filter for TagModel * new: dev: new filter for tag model * chg: dev: deduplicate filter * fix: dev: pylint !cosmetic * chg: dev: generalize tag, bookmark filter * chg: dev: add filters for bookmark * fix: dev: not equal filter * new: dev: url basic filter * chg: dev: configure bookmark model view * chg: dev: reorder bookmark view method * new: dev: tags number filter * chg: dev: bookmark url with unknown scheme * new: dev: network handle api * new: dev: modal edit/create for bookmark * chg: dev: link tag bookmark tag search * fix: dev: empty tag contain search * chg: dev: buku search option * new: dev: buku search to filter * chg: dev: front page search * chg: dev: move Statistic page to views module * fix: dev: bookmark search * new: dev: title filter * fix: dev: statistic label * fix: dev: link on statistic page * chg: dev: strip search value * fix: dev: bookmark entry fix * fix: dev: netloc modal on * fix: dev: pylint !cosmetic * chg: dev: remove duplicate package * chg: dev: move admin to root * fix: dev: link on statistic page * chg: dev: pin pyyaml package
2018-06-28 09:04:35 -05:00
class CustomFlaskGroup(FlaskGroup): # pylint: disable=too-few-public-methods
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.params[0].help = 'Show the program version'
self.params[0].callback = get_custom_version
def get_custom_version(ctx, param, value):
if not value or ctx.resilient_parsing:
return
message = '%(app_name)s %(app_version)s\nFlask %(version)s\nPython %(python_version)s'
click.echo(message % {
'app_name': 'Buku',
'app_version': __version__,
'version': flask_version,
'python_version': sys.version,
}, color=ctx.color)
ctx.exit()
@click.group(cls=CustomFlaskGroup, create_app=create_app)
def cli():
"""This is a management script for the wiki application."""
if __name__ == '__main__':
cli()