1
0
mirror of https://github.com/aquatix/digimarks.git synced 2025-12-06 23:05:10 +01:00

Comments on what functions actually do

This commit is contained in:
2016-07-17 14:08:01 +02:00
parent 4c32e23ead
commit cfbb266056

View File

@@ -24,9 +24,9 @@ DATABASE = {
'name': os.path.join(APP_ROOT, 'bookmarks.db'), 'name': os.path.join(APP_ROOT, 'bookmarks.db'),
'engine': 'peewee.SqliteDatabase', 'engine': 'peewee.SqliteDatabase',
} }
PASSWORD = 'shh' #PASSWORD = 'shh'
PHANTOM = '/usr/local/bin/phantomjs' #PHANTOM = '/usr/local/bin/phantomjs'
SCRIPT = os.path.join(APP_ROOT, 'screenshot.js') #SCRIPT = os.path.join(APP_ROOT, 'screenshot.js')
# create our flask app and a database wrapper # create our flask app and a database wrapper
app = Flask(__name__) app = Flask(__name__)
@@ -39,12 +39,14 @@ def getkey():
class User(db.Model): class User(db.Model):
""" User account """
username = CharField() username = CharField()
key = CharField() key = CharField()
created_date = DateTimeField(default=datetime.datetime.now) created_date = DateTimeField(default=datetime.datetime.now)
class Bookmark(db.Model): class Bookmark(db.Model):
""" Bookmark instance, connected to User """
# Foreign key to User # Foreign key to User
userkey = CharField() userkey = CharField()
@@ -71,6 +73,7 @@ class Bookmark(db.Model):
# self.image = os.path.join(MEDIA_URL, filename) # self.image = os.path.join(MEDIA_URL, filename)
def sethash(self): def sethash(self):
""" Generate hash """
self.url_hash = hashlib.md5(self.url).hexdigest() self.url_hash = hashlib.md5(self.url).hexdigest()
@@ -87,34 +90,40 @@ class Bookmark(db.Model):
@app.route('/') @app.route('/')
def index(): def index():
""" Homepage, point visitors to project page """
return object_list('index.html', Bookmark.select()) return object_list('index.html', Bookmark.select())
@app.route('/<userkey>/') @app.route('/<userkey>/')
def bookmarks(userkey): def bookmarks(userkey):
""" User homepage, list their (unfiltered) bookmarks """
return object_list('bookmarks.html', Bookmark.select()) return object_list('bookmarks.html', Bookmark.select())
@app.route('/<userkey>/<urlhash>') @app.route('/<userkey>/<urlhash>')
def viewbookmark(urlhash): def viewbookmark(urlhash):
""" Bookmark detail view """
# bookmark = getbyurlhash() # bookmark = getbyurlhash()
return render_template('viewbookmark.html') return render_template('viewbookmark.html')
@app.route('/<userkey>/<urlhash>/json') @app.route('/<userkey>/<urlhash>/json')
def viewbookmarkjson(urlhash): def viewbookmarkjson(urlhash):
""" Serialise bookmark to json """
# bookmark = getbyurlhash() # bookmark = getbyurlhash()
return bookmark return bookmark
@app.route('/<userkey>/edit/<urlhash>') @app.route('/<userkey>/edit/<urlhash>')
def editbookmark(urlhash): def editbookmark(urlhash):
""" Bookmark edit form """
# bookmark = getbyurlhash() # bookmark = getbyurlhash()
return render_template('edit.html') return render_template('edit.html')
@app.route('/<userkey>/add') @app.route('/<userkey>/add')
def addbookmark(): def addbookmark():
""" Bookmark add form """
bookmark = Bookmark() bookmark = Bookmark()
return render_template('edit.html') return render_template('edit.html')
@@ -136,8 +145,10 @@ def adding(userkey):
return redirect(url) return redirect(url)
abort(404) abort(404)
@app.route('/<systemkey>/adduser/') @app.route('/<systemkey>/adduser/')
def adduser(systemkey): def adduser(systemkey):
""" Add user endpoint, convenience """
if systemkey == settings.SYSTEMKEY: if systemkey == settings.SYSTEMKEY:
newuser = User() newuser = User()
newuser.key = getkey() newuser.key = getkey()