From b659a8bd02da55e730530c0c1f5f9d7445bf358b Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Tue, 1 May 2018 17:55:44 +0800 Subject: [PATCH 1/7] new: dev: favicon for entry --- bukuserver/server.py | 2 ++ bukuserver/templates/bukuserver/base.html | 3 +++ 2 files changed, 5 insertions(+) diff --git a/bukuserver/server.py b/bukuserver/server.py index 110ca70..09fec3c 100644 --- a/bukuserver/server.py +++ b/bukuserver/server.py @@ -530,6 +530,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..52f7689 100644 --- a/bukuserver/templates/bukuserver/base.html +++ b/bukuserver/templates/bukuserver/base.html @@ -60,6 +60,9 @@ {% for item in bookmarks %}

+ {% if item.url|netloc %} + + {% endif %} {{item.title}} From eac5e81c073049f4d1b900877513d91e216dbf91 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Tue, 1 May 2018 18:08:50 +0800 Subject: [PATCH 2/7] chg: doc: bukuserver readme to rst --- bukuserver/README.md | 34 ------------------------------ bukuserver/README.rst | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 34 deletions(-) delete mode 100644 bukuserver/README.md create mode 100644 bukuserver/README.rst 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..2e83fd5 --- /dev/null +++ b/bukuserver/README.rst @@ -0,0 +1,49 @@ +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` + +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. From ebe9b3536880aa6c320e33480cc92ed3248e1b8c Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Tue, 1 May 2018 18:16:51 +0800 Subject: [PATCH 3/7] chg: dev: env config doc --- bukuserver/README.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bukuserver/README.rst b/bukuserver/README.rst index 2e83fd5..d909b6c 100644 --- a/bukuserver/README.rst +++ b/bukuserver/README.rst @@ -40,6 +40,31 @@ 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: [`10`]/(positive integer) | +| | Bookmark entry per page. | ++-----------------------+--------------------------------------------------------+ + +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 ------- From 93442a1e5fdebe5583af71e3b20e41089ce81e2d Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Tue, 1 May 2018 18:20:00 +0800 Subject: [PATCH 4/7] chg: dev: new line on description --- bukuserver/README.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bukuserver/README.rst b/bukuserver/README.rst index d909b6c..3b01a11 100644 --- a/bukuserver/README.rst +++ b/bukuserver/README.rst @@ -45,12 +45,13 @@ Webserver Env config Following are available os env config available for bukuserver. -+-----------------------+--------------------------------------------------------+ -| Name (without prefix) | Value and description | -+-----------------------+--------------------------------------------------------+ -| PER_PAGE | v: [`10`]/(positive integer) | -| | Bookmark entry per page. | -+-----------------------+--------------------------------------------------------+ ++-----------------------+------------------------------+ +| Name (without prefix) | Value and description | ++-----------------------+------------------------------+ +| PER_PAGE | v: [`10`]/(positive integer) | +| | | +| | Bookmark entry per page. | ++-----------------------+------------------------------+ Note: If any invalid input given, default value will be used From 0a0a98479abbfec96f1f139f1590258732345727 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Wed, 2 May 2018 20:31:45 +0800 Subject: [PATCH 5/7] chg: dev: per_page check --- bukuserver/server.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bukuserver/server.py b/bukuserver/server.py index 09fec3c..6b15871 100644 --- a/bukuserver/server.py +++ b/bukuserver/server.py @@ -518,8 +518,9 @@ 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) + 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 app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SERVER_SECRET_KEY') or os.urandom(24) bukudb = BukuDb() app.app_context().push() From dc455b798f3425e8af2fdf61c4babb26858cd192 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Wed, 2 May 2018 20:34:01 +0800 Subject: [PATCH 6/7] chg: dev: app secret key --- bukuserver/README.rst | 18 +++++++++++------- bukuserver/server.py | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/bukuserver/README.rst b/bukuserver/README.rst index 3b01a11..166b877 100644 --- a/bukuserver/README.rst +++ b/bukuserver/README.rst @@ -45,13 +45,17 @@ Webserver Env config Following are available os env config available for bukuserver. -+-----------------------+------------------------------+ -| Name (without prefix) | Value and description | -+-----------------------+------------------------------+ -| PER_PAGE | v: [`10`]/(positive integer) | -| | | -| | Bookmark entry per page. | -+-----------------------+------------------------------+ ++-----------------------+--------------------------------+ +| Name (without prefix) | Value and description | ++-----------------------+--------------------------------+ +| PER_PAGE | v: [`10`]/(positive integer) | +| | | +| | Bookmark entry per page. | ++-----------------------+--------------------------------+ +| SECRET_KEY | v: [(os.urandom(24))]/(string) | +| | | +| | Server secret key. | ++-----------------------+--------------------------------+ Note: If any invalid input given, default value will be used diff --git a/bukuserver/server.py b/bukuserver/server.py index 6b15871..843b80d 100644 --- a/bukuserver/server.py +++ b/bukuserver/server.py @@ -521,7 +521,7 @@ def create_app(config_filename=None): 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 - app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SERVER_SECRET_KEY') or os.urandom(24) + app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SECRET_KEY') or os.urandom(24) bukudb = BukuDb() app.app_context().push() setattr(flask.g, 'bukudb', bukudb) From dcae31e344630efcb7708b37f83807883a6af76d Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Wed, 9 May 2018 07:33:49 +0800 Subject: [PATCH 7/7] new: dev: url render mode feature --- bukuserver/README.rst | 26 +++++++++++++---------- bukuserver/server.py | 7 ++++++ bukuserver/templates/bukuserver/base.html | 3 +++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/bukuserver/README.rst b/bukuserver/README.rst index 166b877..b832db9 100644 --- a/bukuserver/README.rst +++ b/bukuserver/README.rst @@ -45,17 +45,21 @@ Webserver Env config Following are available os env config available for bukuserver. -+-----------------------+--------------------------------+ -| Name (without prefix) | Value and description | -+-----------------------+--------------------------------+ -| PER_PAGE | v: [`10`]/(positive integer) | -| | | -| | Bookmark entry per page. | -+-----------------------+--------------------------------+ -| SECRET_KEY | v: [(os.urandom(24))]/(string) | -| | | -| | Server secret key. | -+-----------------------+--------------------------------+ ++-----------------------+------------------------------------+ +| 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 diff --git a/bukuserver/server.py b/bukuserver/server.py index 843b80d..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 @@ -521,6 +524,10 @@ def create_app(config_filename=None): 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() diff --git a/bukuserver/templates/bukuserver/base.html b/bukuserver/templates/bukuserver/base.html index 52f7689..3e0851c 100644 --- a/bukuserver/templates/bukuserver/base.html +++ b/bukuserver/templates/bukuserver/base.html @@ -68,7 +68,10 @@

+ {% if url_render_mode == 'netloc' %} ({{item.url|netloc}}) {% endif %} + {% if not url_render_mode or url_render_mode == 'full' %}

{{item.url}}

+ {% endif %}

{{item.description}}

{% for tag in item.tags %}