mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-06 23:05:10 +01:00
Adding/editing bookmarks
This commit is contained in:
71
digimarks.py
71
digimarks.py
@@ -1,7 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import requests
|
||||||
|
|
||||||
from utilkit import datetimeutil
|
from utilkit import datetimeutil
|
||||||
|
|
||||||
@@ -83,6 +83,13 @@ class Bookmark(db.Model):
|
|||||||
self.url_hash = hashlib.md5(self.url).hexdigest()
|
self.url_hash = hashlib.md5(self.url).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def get_title_from_source(self):
|
||||||
|
""" Request the title by requesting the source url """
|
||||||
|
result = requests.get(self.url)
|
||||||
|
title = ''
|
||||||
|
return title
|
||||||
|
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
result = {
|
result = {
|
||||||
'title': self.title,
|
'title': self.title,
|
||||||
@@ -125,49 +132,61 @@ def bookmarks(userkey):
|
|||||||
|
|
||||||
|
|
||||||
@app.route('/<userkey>/<urlhash>')
|
@app.route('/<userkey>/<urlhash>')
|
||||||
def viewbookmark(urlhash):
|
def viewbookmark(userkey, urlhash):
|
||||||
""" Bookmark detail view """
|
""" Bookmark detail view """
|
||||||
# bookmark = getbyurlhash()
|
bookmark = Bookmark.select(Bookmark.url_hash == urlhash, Bookmark.userkey == userkey)
|
||||||
return render_template('viewbookmark.html', userkey=userkey)
|
return render_template('viewbookmark.html', userkey=userkey, bookmark=bookmark)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/<userkey>/<urlhash>/json')
|
@app.route('/<userkey>/<urlhash>/json')
|
||||||
def viewbookmarkjson(urlhash):
|
def viewbookmarkjson(userkey, urlhash):
|
||||||
""" Serialise bookmark to json """
|
""" Serialise bookmark to json """
|
||||||
# bookmark = getbyurlhash()
|
bookmark = Bookmark.select(Bookmark.url_hash == urlhash, Bookmark.userkey == userkey)
|
||||||
return bookmark
|
return bookmark.to_dict()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/<userkey>/edit/<urlhash>')
|
@app.route('/<userkey>/<urlhash>/edit')
|
||||||
def editbookmark(userkey, urlhash):
|
def editbookmark(userkey, urlhash):
|
||||||
""" Bookmark edit form """
|
""" Bookmark edit form """
|
||||||
# bookmark = getbyurlhash()
|
# bookmark = getbyurlhash()
|
||||||
bookmark = Bookmark(Bookmark.url_hash==urlhash)
|
bookmark = Bookmark(Bookmark.url_hash==urlhash)
|
||||||
return render_template('edit.html', userkey=userkey)
|
return render_template('edit.html', action='Edit bookmark', userkey=userkey, bookmark=bookmark)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/<userkey>/add')
|
@app.route('/<userkey>/add')
|
||||||
def addbookmark(userkey):
|
def addbookmark(userkey):
|
||||||
""" Bookmark add form """
|
""" Bookmark add form """
|
||||||
return render_template('edit.html', userkey=userkey)
|
bookmark = Bookmark()
|
||||||
|
return render_template('edit.html', action='Add bookmark', userkey=userkey, bookmark=bookmark)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/<userkey>/add/')
|
@app.route('/<userkey>/adding', methods=['GET', 'POST'])
|
||||||
def adding(userkey):
|
#@app.route('/<userkey>/adding')
|
||||||
password = request.args.get('password')
|
def addingbookmark(userkey):
|
||||||
if password != PASSWORD:
|
""" Add the bookmark from form submit by /add """
|
||||||
|
#password = request.args.get('password')
|
||||||
|
#if password != PASSWORD:
|
||||||
|
# abort(404)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
print request
|
||||||
|
print request.form
|
||||||
|
title = request.form['title']
|
||||||
|
print title
|
||||||
|
url = request.form['url']
|
||||||
|
tags = request.form['tags']
|
||||||
|
print url
|
||||||
|
if url:
|
||||||
|
bookmark = Bookmark(url=url, title=title, tags=tags, userkey=userkey)
|
||||||
|
bookmark.sethash()
|
||||||
|
#bookmark.fetch_image()
|
||||||
|
if not title:
|
||||||
|
# Title was empty, automatically fetch it from the url
|
||||||
|
bookmark.get_title_from_source()
|
||||||
|
bookmark.save()
|
||||||
|
return redirect(url)
|
||||||
abort(404)
|
abort(404)
|
||||||
|
return redirect(url_for('add'))
|
||||||
url = request.args.get('url')
|
|
||||||
title = 'Temp'
|
|
||||||
tags = ''
|
|
||||||
if url:
|
|
||||||
bookmark = Bookmark(url=url, title=title, tags=tags)
|
|
||||||
bookmark.sethash()
|
|
||||||
#bookmark.fetch_image()
|
|
||||||
bookmark.save()
|
|
||||||
return redirect(url)
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/<userkey>/tags')
|
@app.route('/<userkey>/tags')
|
||||||
@@ -197,4 +216,4 @@ if __name__ == '__main__':
|
|||||||
User.create_table(True)
|
User.create_table(True)
|
||||||
|
|
||||||
# run the application
|
# run the application
|
||||||
app.run(port=9999)
|
app.run(port=9999, debug=True)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
flask
|
flask
|
||||||
peewee
|
peewee
|
||||||
flask-peewee
|
flask-peewee
|
||||||
|
requests
|
||||||
utilkit
|
utilkit
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -35,7 +35,7 @@ setup(
|
|||||||
|
|
||||||
# as a practice no need to hard code version unless you know program wont
|
# as a practice no need to hard code version unless you know program wont
|
||||||
# work unless the specific versions are used
|
# work unless the specific versions are used
|
||||||
install_requires=['Flask', 'Peewee', 'Flask-Peewee', 'utilkit'],
|
install_requires=['Flask', 'Peewee', 'Flask-Peewee', 'requests', 'utilkit'],
|
||||||
|
|
||||||
py_modules=['digimarks'],
|
py_modules=['digimarks'],
|
||||||
|
|
||||||
|
|||||||
28
static/css/digimarks.css
Normal file
28
static/css/digimarks.css
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
/* label color */
|
||||||
|
.input-field label {
|
||||||
|
color: #FFF;
|
||||||
|
}
|
||||||
|
/* label focus color */
|
||||||
|
.input-field input[type=text]:focus + label {
|
||||||
|
color: #FFF;
|
||||||
|
}
|
||||||
|
/* label underline focus color */
|
||||||
|
.input-field input[type=text]:focus {
|
||||||
|
border-bottom: 1px solid #FFF;
|
||||||
|
box-shadow: 0 1px 0 0 #FFF;
|
||||||
|
}
|
||||||
|
/* valid color */
|
||||||
|
.input-field input[type=text].valid {
|
||||||
|
border-bottom: 1px solid #FFF;
|
||||||
|
box-shadow: 0 1px 0 0 #FFF;
|
||||||
|
}
|
||||||
|
/* invalid color */
|
||||||
|
.input-field input[type=text].invalid {
|
||||||
|
border-bottom: 1px solid #FFF;
|
||||||
|
box-shadow: 0 1px 0 0 #FFF;
|
||||||
|
}
|
||||||
|
/* icon prefix focus color */
|
||||||
|
.input-field .prefix.active {
|
||||||
|
color: #FFF;
|
||||||
|
}
|
||||||
@@ -1,11 +1,45 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}{{ action }}{% endblock %}
|
||||||
|
{% block pageheader %}{{ action }}{% endblock %}
|
||||||
|
{% block pagecontent %}
|
||||||
|
|
||||||
<h1>Edit/add bookmark</h1>
|
<div class="row">
|
||||||
|
<form class="col s12" action="{{ url_for('addingbookmark', userkey=userkey) }}" method="POST">
|
||||||
|
|
||||||
<form action="{{ SERVERURI }}/{{ FORMACTION }}">
|
<div class="input-field col s12">
|
||||||
|
<i class="material-icons prefix">description</i>
|
||||||
|
<input placeholder="title" type="text" id="title" value="{{ title }}" class="validate" />
|
||||||
|
<label for="title">Title</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<label>Title</label> <input type="text" name="title" value="{{ title }}" />
|
<div class="input-field col s12">
|
||||||
<label>URL</label> <input type="text" name="url" value="{{ url }}" />
|
<i class="material-icons prefix">turned_in</i>
|
||||||
<label>Tags</label> <input type="text" name="tags" value="{{ tags }}" />
|
<input placeholder="url" type="text" id="url" value="{{ url }}" class="validate" />
|
||||||
|
<label for="url">URL</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<input type="submit" value="Save" />
|
<div class="input-field col s12">
|
||||||
</form>
|
<i class="material-icons prefix">label</i>
|
||||||
|
<input placeholder="tags, supported by comma's" type="text" id="tags" value="{{ tags }}" class="validate" />
|
||||||
|
<label for="tags">Tags</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-field col s12">
|
||||||
|
{#<i class="material-icons prefix">star</i>#}
|
||||||
|
<div class="switch">
|
||||||
|
<label>
|
||||||
|
Normal
|
||||||
|
<input type="checkbox" id="starred">
|
||||||
|
<span class="lever"></span>
|
||||||
|
Starred
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-field col m12">
|
||||||
|
<p class="left-align"><button class="btn btn-large waves-effect waves-light" type="submit" name="action">Save</button></p>
|
||||||
|
</div>
|
||||||
|
{# <input type="submit" value="Save" /> #}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user