mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-06 22:05:09 +01:00
Split fetching of bookmarks into generic and view-specific functions
This commit is contained in:
36
digimarks.py
36
digimarks.py
@@ -429,10 +429,7 @@ def index():
|
||||
return render_template('index.html', theme=theme)
|
||||
|
||||
|
||||
@app.route('/<userkey>', methods=['GET', 'POST'])
|
||||
@app.route('/<userkey>/filter/<filtermethod>', methods=['GET', 'POST'])
|
||||
@app.route('/<userkey>/sort/<sortmethod>', methods=['GET', 'POST'])
|
||||
def bookmarks(userkey, filtermethod = None, sortmethod = None):
|
||||
def get_bookmarks(userkey, filtermethod=None, sortmethod=None):
|
||||
""" User homepage, list their bookmarks, optionally filtered and/or sorted """
|
||||
#return object_list('bookmarks.html', Bookmark.select())
|
||||
#user = User.select(key=userkey)
|
||||
@@ -442,7 +439,7 @@ def bookmarks(userkey, filtermethod = None, sortmethod = None):
|
||||
#else:
|
||||
# abort(404)
|
||||
message = request.args.get('message')
|
||||
tags = get_cached_tags(userkey)
|
||||
bookmarktags = get_cached_tags(userkey)
|
||||
|
||||
filter_text = ''
|
||||
if request.form:
|
||||
@@ -475,11 +472,19 @@ def bookmarks(userkey, filtermethod = None, sortmethod = None):
|
||||
else:
|
||||
bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.status == Bookmark.VISIBLE).order_by(Bookmark.created_date.desc())
|
||||
|
||||
return bookmarks, bookmarktags, filter_text, message
|
||||
|
||||
|
||||
@app.route('/<userkey>', methods=['GET', 'POST'])
|
||||
@app.route('/<userkey>/filter/<filtermethod>', methods=['GET', 'POST'])
|
||||
@app.route('/<userkey>/sort/<sortmethod>', methods=['GET', 'POST'])
|
||||
def bookmarks_page(userkey, filtermethod=None, sortmethod=None):
|
||||
bookmarks, bookmarktags, filter_text, message = get_bookmarks(userkey, filtermethod, sortmethod)
|
||||
theme = get_theme(userkey)
|
||||
return render_template('bookmarks.html',
|
||||
bookmarks=bookmarks,
|
||||
userkey=userkey,
|
||||
tags=tags,
|
||||
tags=bookmarktags,
|
||||
filter_text=filter_text,
|
||||
message=message,
|
||||
theme=theme,
|
||||
@@ -488,6 +493,25 @@ def bookmarks(userkey, filtermethod = None, sortmethod = None):
|
||||
)
|
||||
|
||||
|
||||
@app.route('/api/v1/<userkey>', methods=['GET', 'POST'])
|
||||
@app.route('/api/v1/<userkey>/filter/<filtermethod>', methods=['GET', 'POST'])
|
||||
@app.route('/api/v1/<userkey>/sort/<sortmethod>', methods=['GET', 'POST'])
|
||||
def bookmarks_json(userkey, filtermethod=None, sortmethod=None):
|
||||
bookmarks, bookmarktags, filter_text, message = get_bookmarks(userkey, filtermethod, sortmethod)
|
||||
|
||||
bookmarkslist = []
|
||||
|
||||
for bookmark in bookmarks:
|
||||
bookmarkslist.append(bookmark)
|
||||
|
||||
the_data = {
|
||||
'bookmarks': bookmarks,
|
||||
'tags': bookmarktags,
|
||||
'filter_text': filter_text,
|
||||
'message': message,
|
||||
'userkey': userkey,
|
||||
}
|
||||
return jsonify(the_data)
|
||||
|
||||
#@app.route('/<userkey>/<urlhash>')
|
||||
#def viewbookmark(userkey, urlhash):
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
</head>
|
||||
<body class="{{ theme.BODY }} {{ theme.TEXT }}">
|
||||
<nav class="{{ theme.NAV }}" role="navigation">
|
||||
<div class="nav-wrapper container"><a id="logo-container" href="{% if userkey %}{{ url_for('bookmarks', userkey=userkey) }}{% else %}{{ url_for('index') }}{% endif %}" class="brand-logo">digimarks</a>
|
||||
<div class="nav-wrapper container"><a id="logo-container" href="{% if userkey %}{{ url_for('bookmarks_page', userkey=userkey) }}{% else %}{{ url_for('index') }}{% endif %}" class="brand-logo">digimarks</a>
|
||||
<ul class="right hide-on-med-and-down">
|
||||
{% if userkey %}
|
||||
<li><a href="{{ url_for('tags', userkey=userkey) }}">Tags</a></li>
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
{% if userkey %}
|
||||
<ul id="nav-mobile" class="sidenav">
|
||||
<li><a class="waves-effect" href="{{ url_for('bookmarks', userkey=userkey) }}"><i class="material-icons">turned_in</i>Home</a></li>
|
||||
<li><a class="waves-effect" href="{{ url_for('bookmarks_page', userkey=userkey) }}"><i class="material-icons">turned_in</i>Home</a></li>
|
||||
<li><a class="waves-effect" href="{{ url_for('tags', userkey=userkey) }}"><i class="material-icons">label</i>Tags</a></li>
|
||||
<li><a class="waves-effect" href="{{ url_for('addbookmark', userkey=userkey) }}"><i class="material-icons">add</i>Add bookmark</a></li>
|
||||
</ul>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
<form action="{{ url_for('bookmarks', userkey=userkey) }}" method="POST">
|
||||
<form action="{{ url_for('bookmarks_page', userkey=userkey) }}" method="POST">
|
||||
<div class="input-field col l10 m10 s8">
|
||||
<input placeholder="search text" type="text" name="filter_text" id="filter_text" value="{{ filter_text }}" />
|
||||
</div>
|
||||
@@ -52,13 +52,13 @@
|
||||
<div class="collapsible-header"><i class="material-icons">label</i>Filter on star/problem/comment/tag</div>
|
||||
<div class="collapsible-body" style="padding: 10px;">
|
||||
<div class="chip">
|
||||
<a href="{{ url_for('bookmarks', userkey=userkey, filtermethod='starred') }}"><i class="tiny material-icons {{ theme.STAR }}">star</i></a>
|
||||
<a href="{{ url_for('bookmarks_page', userkey=userkey, filtermethod='starred') }}"><i class="tiny material-icons {{ theme.STAR }}">star</i></a>
|
||||
</div>
|
||||
<div class="chip">
|
||||
<a href="{{ url_for('bookmarks', userkey=userkey, filtermethod='broken') }}"><i class="tiny material-icons {{ theme.PROBLEM }}">report_problem</i></a>
|
||||
<a href="{{ url_for('bookmarks_page', userkey=userkey, filtermethod='broken') }}"><i class="tiny material-icons {{ theme.PROBLEM }}">report_problem</i></a>
|
||||
</div>
|
||||
<div class="chip">
|
||||
<a href="{{ url_for('bookmarks', userkey=userkey, filtermethod='note') }}"><i class="tiny material-icons {{ theme.COMMENT }}">comment</i></a>
|
||||
<a href="{{ url_for('bookmarks_page', userkey=userkey, filtermethod='note') }}"><i class="tiny material-icons {{ theme.COMMENT }}">comment</i></a>
|
||||
</div>
|
||||
{% for tag in tags %}
|
||||
<div class="chip">
|
||||
|
||||
Reference in New Issue
Block a user