Skip to content

Commit

Permalink
Initialize web things.
Browse files Browse the repository at this point in the history
  • Loading branch information
markpbaggett committed Aug 11, 2020
1 parent 0d0de33 commit 0e43b69
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WTF_CSRF_ENABLED = True
SECRET_KEY = 'scrambled-eggs'
8 changes: 8 additions & 0 deletions flaskr/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask import Flask
from flask_bootstrap import Bootstrap

app = Flask(__name__)
app.config.from_object('config')
bootstrap = Bootstrap(app)

from flaskr import views
Binary file added flaskr/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added flaskr/__pycache__/forms.cpython-38.pyc
Binary file not shown.
Binary file added flaskr/__pycache__/views.cpython-38.pyc
Binary file not shown.
18 changes: 18 additions & 0 deletions flaskr/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from flask_wtf import FlaskForm
from wtforms import StringField, SelectField
from wtforms.validators import DataRequired, URL


class MyInputBox(FlaskForm):
uri = StringField("uri", validators=[URL()])
subject = StringField("subject")
language = SelectField(
u"Choose language",
choices=[
("ttl", "ttl"),
("xml", "rdf/xml"),
("json-ld", "json-ld"),
("nt", "ntriples"),
],
validators=[DataRequired()],
)
44 changes: 44 additions & 0 deletions flaskr/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{# ``base.html`` is the template all our other templates derive from. While
Flask-Bootstrap ships with its own base, it is good form to create a custom
one for our app, as it allows customizing some aspects.

Deriving from bootstap/base.html gives us a basic page scaffoling.

You can find additional information about template inheritance at

http://jinja.pocoo.org/docs/templates/#template-inheritance
#}
{%- extends "bootstrap/base.html" %}

{# We also set a default title, usually because we might forget to set one.
In our sample app, we will most likely just opt not to change it #}
{% block title %}Sample App for Flask-Bootstrap{% endblock %}

{# While we are at it, we also enable fixes for legacy browsers. First we
import the necessary macros: #}
{% import "bootstrap/fixes.html" as fixes %}

{# Then, inside the head block, we apply these. To not replace the header,
``super()`` is used: #}
{% block head %}
{{super()}}

{#- Docs: http://pythonhosted.org/Flask-Bootstrap/macros.html#fixes
The sample application already contains the required static files. #}
{{fixes.ie8()}}
{%- endblock %}

{# Adding our own CSS files is also done here. Check the documentation at
http://pythonhosted.org/Flask-Bootstrap/basic-usage.html#available-blocks
for an overview. #}
{% block styles -%}
{{super()}} {# do not forget to call super or Bootstrap's own stylesheets
will disappear! #}
<link rel="stylesheet" type="text/css"
href="{{url_for('static', filename='sample-app.css')}}">
{% endblock %}

{# Finally, round things out with navigation #}
{% block navbar %}
{{nav.frontend_top.render()}}
{% endblock %}
25 changes: 25 additions & 0 deletions flaskr/templates/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends "bootstrap/base.html" %}
{% block title %}This is an example page{% endblock %}

{% block navbar %}
<div class="navbar navbar-fixed-top">
<!-- ... -->
</div>
{% endblock %}

{% block content %}
<div class="formwrapper">
<h1>RDF Inquisitor</h1>
<form action="/" method="post" name="search" class="navbar-form navbar-left">
<div class="form-group">
{{ form.uri(class="form-control", size=50, placeholder="Specify URI") }}
{{ form.language()}}
</div>
{{ form.submit }}
<input type="submit" value="Go">
</form>
</div>
{% if results %}
{{results}}
{% endif %}
{% endblock %}
21 changes: 21 additions & 0 deletions flaskr/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from flaskr import app
from flask import render_template, request, Markup
from inquisitor.question import RDFInquisitor
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers.rdf import TurtleLexer
from .forms import MyInputBox


@app.route('/', methods=['GET', 'POST'])
@app.route('/index', methods=['GET', 'POST'])
def index():
form = MyInputBox(request.form)
if request.method == 'POST':
#print(form.language.data)
print(form.subject.data)
code = RDFInquisitor(form.uri.data).flaskerize_rdf(form.language.data)
results = highlight(code, TurtleLexer(), HtmlFormatter(linenos=True, style="colorful", full=True))
return render_template('test.html', results=Markup(results), form=form)
else:
return render_template("test.html", form=form)
7 changes: 7 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from flaskr import app
import os

port = int(os.getenv('PORT', 8080))
host = os.getenv('IP', '0.0.0.0')
app.run(host=host, port=port, debug=True)

0 comments on commit 0e43b69

Please sign in to comment.