diff --git a/bukuserver/README.md b/bukuserver/README.md deleted file mode 100644 index d31db65..0000000 --- a/bukuserver/README.md +++ /dev/null @@ -1,34 +0,0 @@ -#### Install server - -You need to have some packages before you install `bukuserver` on your server. So be sure to have `python3`, `python3-pip` , `python3-dev`, `libffi-dev` packages from your distribution. - -##### Installing PIP, virtualenv and dependencies - -``` -$ python3 -m pip install --user --upgrade pip -$ python3 -m pip install --user virtualenv -$ python3 -m virtualenv env -$ source env/bin/activate -$ git clone https://github.com/jarun/Buku -$ cd Buku -$ pip3 install .[server] -``` - -#### Installing buku and bukuserver from PIP - -``` -$ pip3 install buku[server] -``` - -#### Webserver options - -To run the server on host 127.0.0.1, port 5001, run following command: - - $ bukuserver run --host 127.0.0.1 --port 5001 -Visit `127.0.0.1:5001` in your browser to access your bookmarks. - -See more option on `bukuserver run --help` and `bukuserver --help` - -#### CAUTION - -This snapshot of web APIs is indicative. The program APIs are bound to change and if you need these, you may have to adapt the APIs to the current signature/return type etc. We are NOT actively updating these whenever an API changes in the main program. diff --git a/bukuserver/README.rst b/bukuserver/README.rst new file mode 100644 index 0000000..b832db9 --- /dev/null +++ b/bukuserver/README.rst @@ -0,0 +1,83 @@ +Bukuserver +========== + +Install server +-------------- + +You need to have some packages before you install `bukuserver` on your server. +So be sure to have `python3`, `python3-pip` , `python3-dev`, `libffi-dev` packages from your distribution. + +Installing PIP, virtualenv and dependencies +------------------------------------------- + +.. code:: shell + + $ python3 -m pip install --user --upgrade pip + $ python3 -m pip install --user virtualenv + $ python3 -m virtualenv env + $ source env/bin/activate + $ git clone https://github.com/jarun/Buku + $ cd Buku + $ pip3 install .[server] + +Installing buku and bukuserver from PIP +--------------------------------------- + +.. code:: shell + + $ pip3 install buku[server] + +Webserver options +----------------- + +To run the server on host 127.0.0.1, port 5001, run following command: + +.. code:: shell + + $ bukuserver run --host 127.0.0.1 --port 5001 + +Visit `127.0.0.1:5001` in your browser to access your bookmarks. + +See more option on `bukuserver run --help` and `bukuserver --help` + +Webserver Env config +-------------------- + +Following are available os env config available for bukuserver. + ++-----------------------+------------------------------------+ +| Name (without prefix) | Value and description | ++-----------------------+------------------------------------+ +| PER_PAGE | v: [:code:`10`]/(positive integer) | +| | | +| | Bookmark entry per page. | ++-----------------------+------------------------------------+ +| SECRET_KEY | v: [(os.urandom(24))]/(string) | +| | | +| | Server secret key. | ++-----------------------+------------------------------------+ +| URL_RENDER_MODE | v: [:code:`full`]/:code:`netloc` | +| | | +| | Url render mode. | ++-----------------------+------------------------------------+ + +Note: If any invalid input given, default value will be used + +Note: to use it add `BUKUSERVER_` as prefix. + +ie to set bukuserver to show 100 item per page run the following command + +.. code:: + + $ # on linux + $ export BUKUSERVER_PER_PAGE=100 + $ # on windows + $ SET BUKUSERVER_PER_PAGE=100 + +CAUTION +------- + +This snapshot of web APIs is indicative. +The program APIs are bound to change and if you need these, +you may have to adapt the APIs to the current signature/return type etc. +We are NOT actively updating these whenever an API changes in the main program. diff --git a/bukuserver/server.py b/bukuserver/server.py index 110ca70..c7ded26 100644 --- a/bukuserver/server.py +++ b/bukuserver/server.py @@ -33,6 +33,7 @@ except ImportError: DEFAULT_PER_PAGE = 10 +DEFAULT_URL_RENDER_MODE = 'full' STATISTIC_DATA = None @@ -86,6 +87,7 @@ def bookmarks(): default=int( current_app.config.get('BUKUSERVER_PER_PAGE', DEFAULT_PER_PAGE)) ) + url_render_mode = current_app.config['BUKUSERVER_URL_RENDER_MODE'] create_bookmarks_form = forms.CreateBookmarksForm() if request.method == 'GET': all_bookmarks = bukudb.get_rec_all() @@ -131,6 +133,7 @@ def bookmarks(): pagination=pagination, search_bookmarks_form=forms.SearchBookmarksForm(), create_bookmarks_form=create_bookmarks_form, + url_render_mode=url_render_mode, ) elif request.method == 'POST': url_data = create_bookmarks_form.url.data @@ -518,9 +521,14 @@ def view_statistic(): def create_app(config_filename=None): """create app.""" app = Flask(__name__) - app.config['BUKUSERVER_PER_PAGE'] = os.getenv( - 'BUKUSERVER_PER_PAGE', DEFAULT_PER_PAGE) - app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SERVER_SECRET_KEY') or os.urandom(24) + per_page = int(os.getenv('BUKUSERVER_PER_PAGE', DEFAULT_PER_PAGE)) + per_page = per_page if per_page > 0 else DEFAULT_PER_PAGE + app.config['BUKUSERVER_PER_PAGE'] = per_page + url_render_mode = os.getenv('BUKUSERVER_URL_RENDER_MODE', DEFAULT_URL_RENDER_MODE) + if url_render_mode not in ('full', 'netloc'): + url_render_mode = DEFAULT_URL_RENDER_MODE + app.config['BUKUSERVER_URL_RENDER_MODE'] = url_render_mode + app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SECRET_KEY') or os.urandom(24) bukudb = BukuDb() app.app_context().push() setattr(flask.g, 'bukudb', bukudb) @@ -530,6 +538,8 @@ def create_app(config_filename=None): """Shell context definition.""" return {'app': app, 'bukudb': bukudb} + app.jinja_env.filters['netloc'] = lambda x: urlparse(x).netloc # pylint: disable=no-member + Bootstrap(app) # routing app.add_url_rule('/api/tags', 'get_tags', get_tags, methods=['GET']) diff --git a/bukuserver/templates/bukuserver/base.html b/bukuserver/templates/bukuserver/base.html index 5d470cb..3e0851c 100644 --- a/bukuserver/templates/bukuserver/base.html +++ b/bukuserver/templates/bukuserver/base.html @@ -60,12 +60,18 @@ {% for item in bookmarks %}
{{item.description}}
{% for tag in item.tags %}