3rd party js, template to add new quotes

This commit is contained in:
nukeop 2016-12-09 23:50:11 +00:00
parent 02adb46e58
commit 8388a1e6b6
10 changed files with 203 additions and 6 deletions

View file

@ -45,6 +45,7 @@ class Database(object):
query = "INSERT INTO {}({}) VALUES ({})".format(table, columns, values)
cur.execute(query, params)
conn.commit()
return cur
def delete(self, table, condition):

View file

@ -20,7 +20,7 @@ class Tag(Model):
tablename = "tags"
id = ("id", "INTEGER", "PRIMARY KEY AUTOINCREMENT")
name = ("name", "TEXT", "NOT NULL")
name = ("name", "TEXT", "UNIQUE NOT NULL")
class TagsToQuotes(Model):

View file

@ -0,0 +1,60 @@
/*
* bootstrap-tagsinput v0.8.0
*
*/
.bootstrap-tagsinput {
background-color: #fff;
border: 1px solid #ccc;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
display: inline-block;
padding: 4px 6px;
color: #555;
vertical-align: middle;
border-radius: 4px;
width: 100%;
line-height: 22px;
cursor: text;
}
.bootstrap-tagsinput input {
border: none;
box-shadow: none;
outline: none;
background-color: transparent;
padding: 0 6px;
margin: 0;
width: auto;
max-width: inherit;
}
.bootstrap-tagsinput.form-control input::-moz-placeholder {
color: #777;
opacity: 1;
}
.bootstrap-tagsinput.form-control input:-ms-input-placeholder {
color: #777;
}
.bootstrap-tagsinput.form-control input::-webkit-input-placeholder {
color: #777;
}
.bootstrap-tagsinput input:focus {
border: none;
box-shadow: none;
}
.bootstrap-tagsinput .tag {
margin-right: 2px;
color: white;
}
.bootstrap-tagsinput .tag [data-role="remove"] {
margin-left: 8px;
cursor: pointer;
}
.bootstrap-tagsinput .tag [data-role="remove"]:after {
content: "x";
padding: 0px 2px;
}
.bootstrap-tagsinput .tag [data-role="remove"]:hover {
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
}
.bootstrap-tagsinput .tag [data-role="remove"]:hover:active {
box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
}

View file

@ -85,7 +85,7 @@ html, body {
margin-top: 50px;
right: 0;
left: 0;
bottom: 0;
bottom: -50px;
}
.footer-copyright {
@ -126,3 +126,11 @@ html, body {
.table > tbody > tr > td{
border-top: 0;
}
.tags {
margin-bottom: 4px;
}
.badge {
background-color: #03A9F4;
}

File diff suppressed because one or more lines are too long

4
smash/static/js/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

42
smash/templates/add.html Normal file
View file

@ -0,0 +1,42 @@
{% extends "base.html" %}
{% block content %}
<center>
<form action="/add" name="add" method="post">
<table width="60%">
<tbody>
<tr>
<td>
</br>
<textarea class="form-control" rows="10" name="newquote"></textarea>
</td>
</tr>
<tr>
<td>
</br>
<label for="tags" >Tags:</label>
<input class="form-control" type="text" name="tags" id="tags" value="" data-role="tagsinput" />
</td>
</tr>
<tr>
<td>
</br>
<input type="submit" name="submit" value="Preview" class="btn btn-default"></input>
<input type="submit" name="submit" value="Submit" class="btn btn-default"></input>
</td>
</tr>
<tr>
<td>
</br>
IP and connection time are logged.
</td>
</tr>
</tbody>
</table>
</form>
</center>
{% endblock %}

View file

@ -7,6 +7,7 @@
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='font-awesome/css/font-awesome.min.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/custom.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/fonts.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bootstrap-tagsinput.css') }}" />
{% endblock %}
@ -28,9 +29,10 @@
<li> <a href="/">Home</a> </li>
<li> <a href="/latest">Latest</a> </li>
<li> <a href="/tags">Tags</a> </li>
<li> <a href="/tags">Add new</a> </li>
<li> <a href="/add">Add new</a> </li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<form action="/search" method="post" class="navbar-form navbar-left" role="search">
@ -60,6 +62,9 @@
</div>
<script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
<script src="{{ url_for('static', filename='bootstrap/js/bootstrap.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/bootstrap-tagsinput.min.js') }}"></script>
</body>
</html>

View file

@ -17,8 +17,6 @@
{% endfor %}
</div>
</br> </br>
{% endfor %}
{% endif %}

View file

@ -1,6 +1,7 @@
import datetime
import logging
from flask import render_template, Markup
import sqlite3
from flask import render_template, Markup, request, abort
from smash import app, conf, db
@ -86,3 +87,51 @@ def search():
return 'success'
else:
return 'Invalid request.'
@app.route('/add', methods=['GET', 'POST'])
def add_new():
if request.method == 'POST':
if request.form['submit'] == "Submit":
quote_body = request.form["newquote"]
quote_tags = request.form["tags"].split(',')
cur = db.insert("quotes", "rating, content", "?, ?", (0, quote_body) )
qid = cur.lastrowid
for tag in quote_tags:
tid = -1
try:
cur = db.insert(
"tags",
"name",
"?",
(tag,)
)
tid = cur.lastrowid
except sqlite3.IntegrityError:
logger.warning("Tag {} already exists".format(tag))
if tid != -1:
try:
db.insert(
"tagsToQuotes",
"tagid, quoteid",
"?, ?",
(tid, qid)
)
except sqlite3.Error:
logger.warning("Database error while inserting into tagsToQuotes")
elif request.form['submit'] == "Preview":
return str(request.form)
else:
abort(501)
elif request.method == 'GET':
return render_template(
"add.html",
appname=conf.config['APPNAME'],
appbrand=conf.config['APPBRAND'],
title="Add new"
)