This commit is contained in:
Marijn Jansen
2019-03-19 10:24:48 +01:00
parent 83f3ee2cb4
commit acbf413107
18 changed files with 248 additions and 59 deletions

22
.idea/watcherTasks.xml generated
View File

@@ -1,6 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectTasksOptions">
<TaskOptions isEnabled="true">
<option name="arguments" value="$FileName$:$FileNameWithoutExtension$.min.css --style compressed" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="scss" />
<option name="immediateSync" value="true" />
<option name="name" value="SCSS bootstrap" />
<option name="output" value="$FileNameWithoutExtension$.min.css:$FileNameWithoutExtension$.min.css.map" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="sass" />
<option name="runOnExternalChanges" value="true" />
<option name="scopeName" value="bootstrap" />
<option name="trackOnlyRoot" value="true" />
<option name="workingDir" value="$FileDir$" />
<envs />
</TaskOptions>
<TaskOptions isEnabled="true">
<option name="arguments" value="$FileName$:$FileNameWithoutExtension$.css" />
<option name="checkSyntaxErrors" value="true" />
@@ -16,7 +36,7 @@
<option name="outputFromStdout" value="false" />
<option name="program" value="sass" />
<option name="runOnExternalChanges" value="true" />
<option name="scopeName" value="Project Files" />
<option name="scopeName" value="no-bootstrap" />
<option name="trackOnlyRoot" value="true" />
<option name="workingDir" value="$FileDir$" />
<envs />

View File

@@ -7,6 +7,9 @@ verify_ssl = true
[packages]
flask = "*"
flask-sqlalchemy = "*"
gunicorn = "*"
psycopg2-binary = "*"
[requires]
python_version = "3.7"

60
Pipfile.lock generated
View File

@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "a82b674d67d29678775ff6b773de1686a9593749ec14483b0d8e05131b662286"
"sha256": "c2d61bd8088f47c3f29ed6dbe2aa8a396284e7587021c1bc00d6ae8685e517dc"
},
"pipfile-spec": 6,
"requires": {
@@ -31,6 +31,22 @@
"index": "pypi",
"version": "==1.0.2"
},
"flask-sqlalchemy": {
"hashes": [
"sha256:3bc0fac969dd8c0ace01b32060f0c729565293302f0c4269beed154b46bec50b",
"sha256:5971b9852b5888655f11db634e87725a9031e170f37c0ce7851cf83497f56e53"
],
"index": "pypi",
"version": "==2.3.2"
},
"gunicorn": {
"hashes": [
"sha256:aa8e0b40b4157b36a5df5e599f45c9c76d6af43845ba3b3b0efe2c70473c2471",
"sha256:fa2662097c66f920f53f70621c6c58ca4a3c4d3434205e608e121b5b3b71f4f3"
],
"index": "pypi",
"version": "==19.9.0"
},
"itsdangerous": {
"hashes": [
"sha256:321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19",
@@ -78,6 +94,48 @@
],
"version": "==1.1.1"
},
"psycopg2-binary": {
"hashes": [
"sha256:19a2d1f3567b30f6c2bb3baea23f74f69d51f0c06c2e2082d0d9c28b0733a4c2",
"sha256:2b69cf4b0fa2716fd977aa4e1fd39af6110eb47b2bb30b4e5a469d8fbecfc102",
"sha256:2e952fa17ba48cbc2dc063ddeec37d7dc4ea0ef7db0ac1eda8906365a8543f31",
"sha256:348b49dd737ff74cfb5e663e18cb069b44c64f77ec0523b5794efafbfa7df0b8",
"sha256:3d72a5fdc5f00ca85160915eb9a973cf9a0ab8148f6eda40708bf672c55ac1d1",
"sha256:4957452f7868f43f32c090dadb4188e9c74a4687323c87a882e943c2bd4780c3",
"sha256:5138cec2ee1e53a671e11cc519505eb08aaaaf390c508f25b09605763d48de4b",
"sha256:587098ca4fc46c95736459d171102336af12f0d415b3b865972a79c03f06259f",
"sha256:5b79368bcdb1da4a05f931b62760bea0955ee2c81531d8e84625df2defd3f709",
"sha256:5cf43807392247d9bc99737160da32d3fa619e0bfd85ba24d1c78db205f472a4",
"sha256:676d1a80b1eebc0cacae8dd09b2fde24213173bf65650d22b038c5ed4039f392",
"sha256:6b0211ecda389101a7d1d3df2eba0cf7ffbdd2480ca6f1d2257c7bd739e84110",
"sha256:79cde4660de6f0bb523c229763bd8ad9a93ac6760b72c369cf1213955c430934",
"sha256:7aba9786ac32c2a6d5fb446002ed936b47d5e1f10c466ef7e48f66eb9f9ebe3b",
"sha256:7c8159352244e11bdd422226aa17651110b600d175220c451a9acf795e7414e0",
"sha256:945f2eedf4fc6b2432697eb90bb98cc467de5147869e57405bfc31fa0b824741",
"sha256:96b4e902cde37a7fc6ab306b3ac089a3949e6ce3d824eeca5b19dc0bedb9f6e2",
"sha256:9a7bccb1212e63f309eb9fab47b6eaef796f59850f169a25695b248ca1bf681b",
"sha256:a3bfcac727538ec11af304b5eccadbac952d4cca1a551a29b8fe554e3ad535dc",
"sha256:b19e9f1b85c5d6136f5a0549abdc55dcbd63aba18b4f10d0d063eb65ef2c68b4",
"sha256:b664011bb14ca1f2287c17185e222f2098f7b4c857961dbcf9badb28786dbbf4",
"sha256:bde7959ef012b628868d69c474ec4920252656d0800835ed999ba5e4f57e3e2e",
"sha256:cb095a0657d792c8de9f7c9a0452385a309dfb1bbbb3357d6b1e216353ade6ca",
"sha256:d16d42a1b9772152c1fe606f679b2316551f7e1a1ce273e7f808e82a136cdb3d",
"sha256:d444b1545430ffc1e7a24ce5a9be122ccd3b135a7b7e695c5862c5aff0b11159",
"sha256:d93ccc7bf409ec0a23f2ac70977507e0b8a8d8c54e5ee46109af2f0ec9e411f3",
"sha256:df6444f952ca849016902662e1a47abf4fa0678d75f92fd9dd27f20525f809cd",
"sha256:e63850d8c52ba2b502662bf3c02603175c2397a9acc756090e444ce49508d41e",
"sha256:ec43358c105794bc2b6fd34c68d27f92bea7102393c01889e93f4b6a70975728",
"sha256:f4c6926d9c03dadce7a3b378b40d2fea912c1344ef9b29869f984fb3d2a2420b"
],
"index": "pypi",
"version": "==2.7.7"
},
"sqlalchemy": {
"hashes": [
"sha256:781fb7b9d194ed3fc596b8f0dd4623ff160e3e825dd8c15472376a438c19598b"
],
"version": "==1.3.1"
},
"werkzeug": {
"hashes": [
"sha256:c3fd7a7d41976d9f44db327260e263132466836cef6f91512889ed60ad26557c",

1
Procfile Normal file
View File

@@ -0,0 +1 @@
web: gunicorn app:app

74
app.py
View File

@@ -1,13 +1,77 @@
from flask import Flask, render_template
import os
from flask import Flask, render_template, request, jsonify
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
# Check for environment variable
if not os.getenv("DATABASE_URL"):
raise RuntimeError("DATABASE_URL is not set")
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv("DATABASE_URL")
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['JSON_SORT_KEYS'] = False
db = SQLAlchemy(app)
@app.route("/")
def index():
return count(12)
result = Post.query.order_by(Post.priority).all()
print(result)
return render_template("main/index.html", count=12)
@app.route("/<int:item_count>")
def count(item_count):
return render_template("index.html", count=item_count)
@app.route("/api/post/<int:post_id>", methods=["POST"])
def get_post(post_id):
post = Post.query.get(post_id)
if post:
return jsonify({"success": True, "post": post.serialize})
else:
return jsonify({"success": False})
@app.route("/login", methods=["GET"])
def login():
return render_template("adm/login.html")
class Post(db.Model):
__tablename__ = "posts"
id = db.Column(db.Integer, primary_key=True)
priority = db.Column(db.Integer, unique=True, nullable=False)
category_id = db.Column(db.Integer, db.ForeignKey("category.id"), nullable=True)
category = db.relationship("Category", lazy=True)
title = db.Column(db.String(80), nullable=False)
intro = db.Column(db.Text, nullable=False)
description = db.Column(db.Text, nullable=True)
images = db.relationship("Image", backref="post", lazy=True)
@property
def serialize(self):
return {"id": self.id,
"priority": self.priority,
"category_id": self.category_id,
"category": self.category.name,
"title": self.title,
"intro": self.intro,
"description": self.description,
"images": self.images}
class Image(db.Model):
__tablename__ = "images"
id = db.Column(db.Integer, primary_key=True)
uri = db.Column(db.String(80), nullable=False)
post_id = db.Column(db.Integer, db.ForeignKey("posts.id"), nullable=False)
class Category(db.Model):
__tablename__ = "category"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)

11
requirements.txt Normal file
View File

@@ -0,0 +1,11 @@
-i https://pypi.org/simple
click==7.0
flask-sqlalchemy==2.3.2
flask==1.0.2
gunicorn==19.9.0
itsdangerous==1.1.0
jinja2==2.10
markupsafe==1.1.1
psycopg2-binary==2.7.7
sqlalchemy==1.3.1
werkzeug==0.14.1

View File

@@ -1,3 +1,3 @@
$grid-gutter-width: 0px;
$grid-gutter-width: 0;
@import "bootstrap/bootstrap";

View File

@@ -40,9 +40,6 @@ body {
padding-top: 4.5rem;
}
nav {
margin-bottom: $half-margin;
}
footer {
margin-top: $half-margin;

View File

@@ -0,0 +1,4 @@
{% extends "layout.html" %}
{% block nav %}{% include "adm/nav.html" %}{% endblock %}
{% block footer %}{% endblock %}

26
templates/adm/login.html Normal file
View File

@@ -0,0 +1,26 @@
{% extends "layout.html" %}
{% block main %}
<main class="container ">
<form>
<div class="form-group row justify-content-center">
<label for="email" class="col-sm-1 col-form-label">Email</label>
<div class="col-sm-3">
<input type="email" class="form-control" id="email" placeholder="Email">
</div>
</div>
<div class="form-group row justify-content-center">
<label for="password" class="col-sm-1 col-form-label">Password</label>
<div class="col-sm-3">
<input type="password" class="form-control" id="password" placeholder="Password">
</div>
</div>
<div class="form-group row justify-content-center">
<div class="">
<button type="submit" class="btn btn-primary">Sign in</button>
</div>
</div>
</form>
</main>
{% endblock %}

3
templates/adm/nav.html Normal file
View File

@@ -0,0 +1,3 @@
<nav>
</nav>

View File

@@ -6,9 +6,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap first, then custom style -->
<link rel="stylesheet" href="/static/bootstrap.css">
<link rel="stylesheet" href="/static/bootstrap.min.css">
<link rel="stylesheet" href="/static/style.css">
<title>{% block title %}{% endblock %}</title>
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
@@ -19,17 +21,11 @@
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"
integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"
crossorigin="anonymous"></script>
<title>{% block title %}{% endblock %}</title>
</head>
<body>
{% include "nav.html" %}
{% block main %}{% endblock %}
{% include "modal.html" %}
{% include "footer.html" %}
{% block nav %}{% endblock %}
{% block main %}{% endblock %}
{% block footer %}{% endblock %}
</body>
</html>

View File

@@ -1,4 +1,4 @@
{% extends "layout.html" %}
{% extends "main/layout.html" %}
{% block title %}Marlous van Leeuwen{% endblock %}
@@ -6,7 +6,6 @@
<main class="container">
<div class="row">
{% for i in range(count) %}
<div class="col-lg-3 col-md-4 col-6">
<a data-toggle="modal" data-target="#detailModal" data-name="{{ i }}">
<div class="card border-light">
@@ -20,7 +19,6 @@
</div>
</a>
</div>
{% endfor %}
</div>
</main>

View File

@@ -0,0 +1,9 @@
{% extends "layout.html" %}
{% block nav %}{% include "main/nav.html" %}{% endblock %}
{% block footer %}
{% include "main/modal.html" %}
{% include "main/footer.html" %}
{% endblock %}

31
templates/main/modal.html Normal file
View File

@@ -0,0 +1,31 @@
<div class="modal fade" id="detailModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title text-center" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
</p>
</div>
</div>
</div>
</div>
<script>
$('#detailModal').on('show.bs.modal', function (event) {
let card = $(event.relatedTarget); // Button that triggered the modal
let name = card.data('name'); // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
let modal = $(this);
modal.find('.modal-title').text(name);
{#modal.find('.modal-body input').val(recipient)#}
})
</script>

View File

@@ -1,15 +1,15 @@
<nav class="navbar navbar-expand-md navbar-light bg-light fixed-top">
<a class="navbar-brand" href="{{ url_for("index") }}">Marlous</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
<a class="nav-link" href="#">Home<span class="sr-only">(current)</span></a>
</li>
</ul>
</div>

View File

@@ -1,32 +0,0 @@
<div class="modal fade" id="detailModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>Hier staat een mooi verhaaltje over het project wat je net hebt aangeklikt.</p>
</div>
{# <div class="modal-footer">#}
{# <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>#}
{# <button type="button" class="btn btn-primary">Save changes</button>#}
{# </div>#}
</div>
</div>
</div>
<script>
$('#detailModal').on('show.bs.modal', function (event) {
let card = $(event.relatedTarget); // Button that triggered the modal
let name = card.data('name'); // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
let modal = $(this);
modal.find('.modal-title').text(name);
{#modal.find('.modal-body input').val(recipient)#}
})
</script>