API improved

master
Your Name 6 years ago
parent ffbf011e67
commit 1c6ba6eb4b

Binary file not shown.

Binary file not shown.

@ -7,3 +7,4 @@ from wtforms.validators import DataRequired, Length, Email
class UploadForm(FlaskForm):
title = TextField('title', validators=[ DataRequired()])
writingfield = TextAreaField('writingfield', validators = [DataRequired()])
category = TextField('category', validators=[ DataRequired()])

@ -7,11 +7,13 @@ db = SQLAlchemy(app)
class Posts(db.Model):
pid = db.Column(db.Integer, primary_key=True, autoincrement=True)
title = db.Column(db.String(100))
writingfield = db.Column(db.String(1000))
writingfield = db.Column(db.String(10000))
category = db.Column(db.String(100))
def __init__(self, title, writingfield):
def __init__(self, title, writingfield, category):
self.title = title
self.writingfield = writingfield
self.category = category
db.create_all()

@ -57,9 +57,17 @@ h2{
font-family: 'suisse_works'!important;
font-weight: normal;
font-size: 40px!important;
margin:0;
margin:10px;
padding:0;
}
.post h2{
margin:0px;
}
.imgsub{
font-size: 14px;
font-style: italic;
}
h3{
font-weight: normal;
font-family: 'suisseintl';
@ -196,6 +204,21 @@ cursor:pointer;
border-bottom: none;
}
#buttons{
display: none;
position: fixed;
right: 10px;
bottom: 10px;
}
.category{
font-size: 10px!important;
font-family: monospace!important;
padding: 0px;
margin: 0px;
line-height: 12px!important;
}
#title{
background: #eeeeee;
padding: 0px;

@ -0,0 +1,2 @@
#main{font-family: monospace;}
.mono{}

@ -35,6 +35,11 @@ ______ ______ ______ ______ __ ______
{% block css %} {% endblock%}
</head>
<body>
<div id="buttons">
<label><input type="checkbox" name="getlost" value="getlost">Get Lost Mode!</label><br>
<label><input type="checkbox" name="links" value="links">Links</label>
</div>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul class=flashes>
@ -45,7 +50,7 @@ ______ ______ ______ ______ __ ______
{% endif %}
{% endwith %}
<main>
<a href={{ url_for('index') }} class="title" ><h1>Read only, write a bit and make me run!</h1></a>
<a href={{ url_for('index') }} class="title" ><h1>Poetic Software</h1></a>
<div class="container">
{% block main %}{% endblock %}

@ -0,0 +1,99 @@
<!--
______ ______ ______ ______ __ ______
/\ == \ /\ __ \ /\ ___\ /\__ _\ /\ \ /\ ___\
\ \ _-/ \ \ \/\ \ \ \ __\ \/_/\ \/ \ \ \ \ \ \____
\ \_\ \ \_____\ \ \_____\ \ \_\ \ \_\ \ \_____\
\/_/ \/_____/ \/_____/ \/_/ \/_/ \/_____/
______ ______ ______ ______ __ __ ______ ______ ______
/\ ___\ /\ __ \ /\ ___\ /\__ _\ /\ \ _ \ \ /\ __ \ /\ == \ /\ ___\
\ \___ \ \ \ \/\ \ \ \ __\ \/_/\ \/ \ \ \/ ".\ \ \ \ __ \ \ \ __< \ \ __\
\/\_____\ \ \_____\ \ \_\ \ \_\ \ \__/".~\_\ \ \_\ \_\ \ \_\ \_\ \ \_____\
\/_____/ \/_____/ \/_/ \/_/ \/_/ \/_/ \/_/\/_/ \/_/ /_/ \/_____/
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Poetic Software</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="index.js"></script>
<script src="/static/notify.js"></script>
<link rel="stylesheet"
href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.15.6/build/styles/default.min.css">
<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.15.6/build/highlight.min.js"></script>
<link rel="stylesheet" href="/static/css/style_pub.css">
</head>
<body>
<!--div id="buttons">
<label><input type="checkbox" name="getlost" value="getlost">Get Lost Mode!</label><br>
<label><input type="checkbox" name="links" value="links">Links</label>
</div-->
<div id="main">
<p class="mono">
POETIC SOFTWARE <br>
--------------- <br>
<br>
INTRODUCTION
{% for post in posts %}
{% if "introduction"|string() == post.category|string() %}
<div class="post">
<p>{{ post.writingfield|safe }}<p></div>
{% endif %}
{% else %}
<em>The Software is lacking a introduction, ask your system administrator about it.</em>
{% endfor %}
<br>
THESES ON SOFTWARE
{% set count = [0] %}
{% for post in posts %}
{% if "thesis"|string() == post.category|string() %}
<div class="post">
<a href="min/{{ post.pid }}"><p>{{count|length}}. {{ post.title|safe }}<p></a></div>
{% set __ = count.append(1) %}
{% endif %}
{% else %}
<em>The Software is lacking a introduction, ask your system administrator about it.</em>
{% endfor %}
<br>
EXERCISES IN POETIC SOFTWARE
{% set count = [0] %}
{% for post in posts %}
{% if "exercise"|string() == post.category|string() %}
<div class="post">
<a href="min/{{ post.pid }}"><p>{{count|length}}. {{ post.title|safe }}<p></a></div>
{% set __ = count.append(1) %}
{% endif %}
{% else %}
<em>The Software is lacking exercises, ask your system administrator about it.</em>
{% endfor %}
<br>
TERMS AND CONCEPTS
{% for post in posts %}
{% if "concept"|string() == post.category|string() %}
<div class="post">
<a href="min/{{ post.pid }}"><p>{{ post.title|safe }}<p></a></div>
{% endif %}
{% else %}
<em>The Software is lacking a introduction, ask your system administrator about it.</em>
{% endfor %}
</p>
</div>
</body>
</html>

@ -3,7 +3,7 @@
{% block main %}
{% for post in posts %}
{% if "Introduction"|string() == post.title|string() %}
{% if "introduction"|string() == post.category|string() %}
<div class="post"><!--<a href="{{ post.pid }}"><h2>{{ post.title }}</h2></a>-->
<p>{{ post.writingfield|safe }}<p></div>
{% endif %}

@ -1,8 +1,11 @@
{% extends 'base.html' %}
{% block main %}
<div class="post"><h2>{{ post.title }}</h2>
<p>{{ post.writingfield|safe }}<p></div>
<div class="post">
<p class="category">{{ post.category }}<p>
<h2>{{ post.title }}</h2>
<p class="post_text">{{ post.writingfield|safe }}<p>
</div>

@ -0,0 +1,48 @@
<!--
______ ______ ______ ______ __ ______
/\ == \ /\ __ \ /\ ___\ /\__ _\ /\ \ /\ ___\
\ \ _-/ \ \ \/\ \ \ \ __\ \/_/\ \/ \ \ \ \ \ \____
\ \_\ \ \_____\ \ \_____\ \ \_\ \ \_\ \ \_____\
\/_/ \/_____/ \/_____/ \/_/ \/_/ \/_____/
______ ______ ______ ______ __ __ ______ ______ ______
/\ ___\ /\ __ \ /\ ___\ /\__ _\ /\ \ _ \ \ /\ __ \ /\ == \ /\ ___\
\ \___ \ \ \ \/\ \ \ \ __\ \/_/\ \/ \ \ \/ ".\ \ \ \ __ \ \ \ __< \ \ __\
\/\_____\ \ \_____\ \ \_\ \ \_\ \ \__/".~\_\ \ \_\ \_\ \ \_\ \_\ \ \_____\
\/_____/ \/_____/ \/_/ \/_/ \/_/ \/_/ \/_/\/_/ \/_/ /_/ \/_____/
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Poetic Software</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="index.js"></script>
<script src="/static/notify.js"></script>
<link rel="stylesheet"
href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.15.6/build/styles/default.min.css">
<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.15.6/build/highlight.min.js"></script>
<link rel="stylesheet" href="/static/css/style_pub.css">
</head>
<body>
<!--div id="buttons">
<label><input type="checkbox" name="getlost" value="getlost">Get Lost Mode!</label><br>
<label><input type="checkbox" name="links" value="links">Links</label>
</div-->
<div id="main">
<p class="mono">
{{ post.category }}<br><br>
<u>{{ post.title }}</u><br>
<br>
{{ post.writingfield|safe }}
</p></div>
</body>
</html>

@ -8,6 +8,7 @@
<form method="post">
{{ form.csrf_token }}
{{ form.title }}
{{ form.category }}
{{ form.writingfield }}
<input value="submit" id="submit" type="submit"> <h1 style="display:inline-block;"> PARA .DOX</h1>
</form>
@ -36,6 +37,7 @@
<a href="#" data-command='unlink'><i class='fa fa-unlink'></i></a>
<a href="#" data-command='insertimage'><i class='fa fa-image'></i></a>
<a href="#" data-command='p'>P</a>
<a href="#" data-command='imgsub'>img sub</a>
<a href="#" data-command='subscript'><i class='fa fa-subscript'></i></a>
<a href="#" data-command='superscript'><i class='fa fa-superscript'></i></a>
@ -142,7 +144,7 @@ number_selected=-1;
}
caret_pos=getCaretPosition(document.getElementById("writing-field"));
console.log(caret_pos);
current_word = getWordAt(writing_field.text(),getCaretPosition(document.getElementById("writing-field")))
current_word = getWordAt(writing_field.text(),getCaretPosition(document.getElementById("writing-field"))-1)
console.log(current_word)
//typeinfo at the bottom
$("#type_log").append(e.key );
@ -237,7 +239,7 @@ function pasteHtmlAtCaret(html) {
}
function getWordAt (str, pos) {
function getWordAt(str, pos) {
// Perform type conversions.
str = String(str);
@ -284,7 +286,6 @@ var output = $('#output');
writing_field.on('input', function() {
var n = new Date()
var time = (last - n);
console.log(time + ' ms');
last = n;
});
@ -312,9 +313,7 @@ function update() {
if(event.keyCode != 40 && event.keyCode != 38){
// Set `debug` to true in order to see the mirror div. Default false.
console.log(getSelectionCoords());
var coordinates = getSelectionCoords();
console.log("SCROOOLLL"+document.scrollingElement.scrollTop)
//console.log('(top, left, height) = (%s, %s, %s)', coordinates.top, coordinates.left, coordinates.height);
rect.style.top =
+ document.scrollingElement.scrollTop
@ -539,6 +538,12 @@ $('#toolbar a').click(function(e) {
}
if (command == 'forecolor' || command == 'backcolor') {
document.execCommand($(this).data('command'), false, $(this).data('value'));
}
if(command == "imgsub")
{
selection = window.getSelection().toString();
wrappedselection = '<span class="imgsub">' + selection + '</span>';
document.execCommand('insertHTML', false, wrappedselection);
}
if (command == 'createlink' || command == 'insertimage') {
url = prompt('Enter the link here: ','http:\/\/'); document.execCommand($(this).data('command'), false, url);

@ -35,6 +35,12 @@ def index():
posts = db.session.query(Posts).all()
return render_template('index.html', posts=posts)
@app.route('/overview')
@cross_origin(origin='*')
def overview():
posts = db.session.query(Posts).all()
return render_template('home.html', posts=posts)
@app.route('/index')
def all():
posts = db.session.query(Posts).all()
@ -46,35 +52,51 @@ def post(pid):
post = Posts.query.filter_by(pid=pid).first()
return render_template('singlepost.html', post=post)
@app.route('/min/<int:pid>')
@cross_origin(origin='*')
def post_min(pid):
post = Posts.query.filter_by(pid=pid).first()
return render_template('singlepost_minimal.html', post=post)
@app.route('/<int:pid>/edit', methods=['GET', 'POST'])
@cross_origin(origin='*')
def edit_post(pid):
post = Posts.query.filter_by(pid=pid).first()
user_form = UploadForm(title = post.title, writingfield=post.writingfield)
user_form = UploadForm(title = post.title, writingfield=post.writingfield, category=post.category)
if request.method == 'POST':
if user_form.validate_on_submit():
# on submit, check fields
post.title = user_form.title.data
post.writingfield = user_form.writingfield.data
post.category = user_form.category.data
db.session.commit()
return redirect(url_for('post', pid=pid))
return render_template('writer.html', form=user_form, post=post)
@app.route('/<int:pid>/delete', methods=['GET', 'POST'])
@cross_origin(origin='*')
def delete_post(pid):
post = Posts.query.filter_by(pid=pid).first()
db.session.delete(post)
db.session.commit()
return redirect(url_for('index'))
@app.route('/writer', methods=['GET', 'POST'])
@cross_origin(origin='*')
def writer():
post = Posts("unknown", "")
post = Posts("unknown", "", "")
user_form = UploadForm()
if request.method == 'POST':
if user_form.validate_on_submit():
# on submit, check fields
title = user_form.title.data
writingfield = user_form.writingfield.data
post = Posts(title, writingfield)
category = user_form.category.data
post = Posts(title, writingfield, category)
db.session.add(post)
db.session.commit()
return redirect(url_for('post', pid=post.pid))
@ -214,5 +236,41 @@ def replace_with(link, n, pid):
return redirect(url_for('post', pid=pid))
@app.route('/api/getcontent', methods=['GET'])
def get_text():
posts = Posts.query.all()
data = {}
for post in posts:
content = post.writingfield
soup = BeautifulSoup(content)
removedLinks = []
removedImg = []
imgsub = []
for a in soup.find_all("a", {'class':'linkTo'}):
removedLinks.append(a.extract().get_text())
for img in soup.find_all("img"):
removedImg.append(img['src'])
for subtitle in soup.find_all("span", {'class':'imgsub'}):
imgsub.append(subtitle.extract().get_text())
content = str(soup)
soup = BeautifulSoup(content)
content = str(soup.get_text(separator='\n'))
content = re.sub(' +', ' ', content).strip()
#content=re.sub("\s\s+" , " ", content)
#content = str(soup)
images = []
for i,img in enumerate(removedImg):
if i < len(imgsub):
images.append({"url":img, "sub":imgsub[i]})
else:
images.append({"url":img, "sub":""})
data[post.pid] = {"title":post.title, "category":post.category, "content":content, "removedLinks":removedLinks, "images":images}
#print(errors)
return jsonify(data)
if __name__ == '__main__':
app.run()

Loading…
Cancel
Save