Skip to content

Commit

Permalink
[jarun#564] added hyperlinks to create & edit success messages
Browse files Browse the repository at this point in the history
  • Loading branch information
LeXofLeviafan committed Dec 6, 2022
1 parent ed1db30 commit ffcf053
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions bukuserver/static/bukuserver/js/flash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$(document).ready(function () {
SAVED && $(`.alert-success`).first().html((_, s) =>
s.replace(/(<\/button>)([^]*)$/, `$1<a href="details?id=${SAVED}">$2</a>`));
});
5 changes: 5 additions & 0 deletions bukuserver/templates/bukuserver/bookmark_create.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{% extends 'admin/model/create.html' %}

{% block head %}
{{ super() }}
<script>const SAVED = '{{ session.pop('saved', '') }}'</script>
{% endblock %}

{% block tail %}
{{ super() }}
<script src="{{ url_for('static', filename='bukuserver/js/bookmark.js') }}"></script>
Expand Down
6 changes: 6 additions & 0 deletions bukuserver/templates/bukuserver/bookmark_details.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends 'admin/model/details.html' %}

{% block head %}
{{ super() }}
<script>const SAVED = '{{ session.pop('saved', '') }}'</script>
{% endblock %}
5 changes: 5 additions & 0 deletions bukuserver/templates/bukuserver/bookmark_edit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{% extends 'admin/model/edit.html' %}

{% block head %}
{{ super() }}
<script>const SAVED = '{{ session.pop('saved', '') }}'</script>
{% endblock %}

{% block tail %}
{{ super() }}
<script src="{{ url_for('static', filename='bukuserver/js/bookmark.js') }}"></script>
Expand Down
6 changes: 6 additions & 0 deletions bukuserver/templates/bukuserver/bookmarks_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends 'admin/model/list.html' %}

{% block head %}
{{ super() }}
<script>const SAVED = '{{ session.pop('saved', '') }}'</script>
{% endblock %}
11 changes: 8 additions & 3 deletions bukuserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import arrow
import wtforms
from flask import current_app, flash, redirect, request, url_for
from flask import current_app, flash, redirect, request, session, url_for
from flask_admin.babel import gettext
from flask_admin.base import AdminIndexView, BaseView, expose
from flask_admin.model import BaseModelView
Expand Down Expand Up @@ -153,6 +153,8 @@ def _list_entry(self, context: Any, model: Namespace, name: str) -> Markup:
"Entry": _list_entry,
}
column_list = ["Entry"]
list_template = 'bukuserver/bookmarks_list.html'
details_template = 'bukuserver/bookmark_details.html'
create_modal = True
create_modal_template = "bukuserver/bookmark_create_modal.html"
create_template = "bukuserver/bookmark_create.html"
Expand All @@ -162,7 +164,7 @@ def _list_entry(self, context: Any, model: Namespace, name: str) -> Markup:
edit_template = "bukuserver/bookmark_edit.html"
named_filter_urls = True
extra_css = ['/static/bukuserver/css/bookmark.css']
extra_js = ['/static/bukuserver/js/' + it for it in ('page_size.js', 'last_page.js')]
extra_js = ['/static/bukuserver/js/' + it for it in ('page_size.js', 'last_page.js', 'flash.js')]
last_page = expose('/last-page')(last_page)

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -202,7 +204,7 @@ def create_model(self, form):
for key, item in (("title_in", model.title), ("desc", model.description)):
if item.strip():
kwargs[key] = item
vars(model)['id'] = self.model.bukudb.add_rec(**kwargs)
session['saved'] = vars(model)['id'] = self.model.bukudb.add_rec(**kwargs)
except Exception as ex:
if not self.handle_view_exception(ex):
msg = "Failed to create record."
Expand Down Expand Up @@ -272,6 +274,7 @@ def get_one(self, id):
bookmark = self.model.bukudb.get_rec_by_id(id)
bm_sns = types.SimpleNamespace(id=None, url=None, title=None, tags=None, description=None)
for field in list(BookmarkField):
print(field)
if field == BookmarkField.TAGS and bookmark[field.value].startswith(","):
value = bookmark[field.value]
if value.startswith(","):
Expand Down Expand Up @@ -409,6 +412,8 @@ def update_model(self, form: forms.BookmarkForm, model: Namespace):
tags_in=buku.parse_tags([model.tags]),
desc=model.description,
)
print(model.id)
session['saved'] = model.id
except Exception as ex:
if not self.handle_view_exception(ex):
msg = "Failed to update record."
Expand Down

0 comments on commit ffcf053

Please sign in to comment.