mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-06 22:05:09 +01:00
Adding/editing bookmarks
This commit is contained in:
71
digimarks.py
71
digimarks.py
@@ -1,7 +1,7 @@
|
||||
import datetime
|
||||
import hashlib
|
||||
import os
|
||||
import subprocess
|
||||
import requests
|
||||
|
||||
from utilkit import datetimeutil
|
||||
|
||||
@@ -83,6 +83,13 @@ class Bookmark(db.Model):
|
||||
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):
|
||||
result = {
|
||||
'title': self.title,
|
||||
@@ -125,49 +132,61 @@ def bookmarks(userkey):
|
||||
|
||||
|
||||
@app.route('/<userkey>/<urlhash>')
|
||||
def viewbookmark(urlhash):
|
||||
def viewbookmark(userkey, urlhash):
|
||||
""" Bookmark detail view """
|
||||
# bookmark = getbyurlhash()
|
||||
return render_template('viewbookmark.html', userkey=userkey)
|
||||
bookmark = Bookmark.select(Bookmark.url_hash == urlhash, Bookmark.userkey == userkey)
|
||||
return render_template('viewbookmark.html', userkey=userkey, bookmark=bookmark)
|
||||
|
||||
|
||||
@app.route('/<userkey>/<urlhash>/json')
|
||||
def viewbookmarkjson(urlhash):
|
||||
def viewbookmarkjson(userkey, urlhash):
|
||||
""" Serialise bookmark to json """
|
||||
# bookmark = getbyurlhash()
|
||||
return bookmark
|
||||
bookmark = Bookmark.select(Bookmark.url_hash == urlhash, Bookmark.userkey == userkey)
|
||||
return bookmark.to_dict()
|
||||
|
||||
|
||||
@app.route('/<userkey>/edit/<urlhash>')
|
||||
@app.route('/<userkey>/<urlhash>/edit')
|
||||
def editbookmark(userkey, urlhash):
|
||||
""" Bookmark edit form """
|
||||
# bookmark = getbyurlhash()
|
||||
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')
|
||||
def addbookmark(userkey):
|
||||
""" 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/')
|
||||
def adding(userkey):
|
||||
password = request.args.get('password')
|
||||
if password != PASSWORD:
|
||||
@app.route('/<userkey>/adding', methods=['GET', 'POST'])
|
||||
#@app.route('/<userkey>/adding')
|
||||
def addingbookmark(userkey):
|
||||
""" 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)
|
||||
|
||||
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)
|
||||
return redirect(url_for('add'))
|
||||
|
||||
|
||||
@app.route('/<userkey>/tags')
|
||||
@@ -197,4 +216,4 @@ if __name__ == '__main__':
|
||||
User.create_table(True)
|
||||
|
||||
# run the application
|
||||
app.run(port=9999)
|
||||
app.run(port=9999, debug=True)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
flask
|
||||
peewee
|
||||
flask-peewee
|
||||
requests
|
||||
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
|
||||
# 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'],
|
||||
|
||||
|
||||
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 }}" />
|
||||
<label>URL</label> <input type="text" name="url" value="{{ url }}" />
|
||||
<label>Tags</label> <input type="text" name="tags" value="{{ tags }}" />
|
||||
<div class="input-field col s12">
|
||||
<i class="material-icons prefix">turned_in</i>
|
||||
<input placeholder="url" type="text" id="url" value="{{ url }}" class="validate" />
|
||||
<label for="url">URL</label>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Save" />
|
||||
</form>
|
||||
<div class="input-field col s12">
|
||||
<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