From c26d3c09abea8aac5cdad752e23f19e5c8e98cd9 Mon Sep 17 00:00:00 2001 From: Matt Arnold Date: Sun, 6 Apr 2025 21:06:53 -0400 Subject: have gpt start us off --- .gitignore | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++ app.py | 39 +++++++++++++++++ config.py | 12 ++++++ forms.py | 7 +++ models.py | 14 ++++++ static/style.css | 34 +++++++++++++++ templates/base.html | 17 ++++++++ templates/index.html | 11 +++++ templates/post.html | 8 ++++ 9 files changed, 259 insertions(+) create mode 100644 .gitignore create mode 100644 app.py create mode 100644 config.py create mode 100644 forms.py create mode 100644 models.py create mode 100644 static/style.css create mode 100644 templates/base.html create mode 100644 templates/index.html create mode 100644 templates/post.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..df09c56 --- /dev/null +++ b/.gitignore @@ -0,0 +1,117 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +*.egg-info/ +.dist/ +build/ +develop-eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg +.installed.cfg +*.egg-info/ +.eggs/ + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Flask stuff +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule +celerybeat-schedule.* + +# SageMath parsed files +*.sage.py + +# Environment variables +.env +.env.* + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# Local configuration files +config.py diff --git a/app.py b/app.py new file mode 100644 index 0000000..7a1b07f --- /dev/null +++ b/app.py @@ -0,0 +1,39 @@ +from flask import Flask, render_template, request, redirect, url_for +from peewee import SqliteDatabase +from models import Post +from forms import PostForm + +app = Flask(__name__) +app.config.from_object('config') + +db = SqliteDatabase('blog.db') + +@app.before_request +def before_request(): + db.connect() + +@app.after_request +def after_request(response): + db.close() + return response + +@app.route('/') +def index(): + posts = Post.select().order_by(Post.created_at.desc()) + return render_template('index.html', posts=posts) + +@app.route('/post/') +def post(post_id): + post = Post.get(Post.id == post_id) + return render_template('post.html', post=post) + +@app.route('/create', methods=['GET', 'POST']) +def create(): + form = PostForm() + if form.validate_on_submit(): + Post.create(title=form.title.data, content=form.content.data) + return redirect(url_for('index')) + return render_template('create.html', form=form) + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..9416e9c --- /dev/null +++ b/config.py @@ -0,0 +1,12 @@ +import os + +class Config: + SECRET_KEY = os.urandom(24) + + @staticmethod + def init_app(app): + pass + +config = { + 'default': Config +} \ No newline at end of file diff --git a/forms.py b/forms.py new file mode 100644 index 0000000..c66954c --- /dev/null +++ b/forms.py @@ -0,0 +1,7 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, TextAreaField +from wtforms.validators import DataRequired + +class PostForm(FlaskForm): + title = StringField('Title', validators=[DataRequired()]) + content = TextAreaField('Content', validators=[DataRequired()]) \ No newline at end of file diff --git a/models.py b/models.py new file mode 100644 index 0000000..955a70a --- /dev/null +++ b/models.py @@ -0,0 +1,14 @@ +from peewee import Model, CharField, TextField, DateTimeField +from datetime import datetime +from app import db + +class BaseModel(Model): + class Meta: + database = db + +class Post(BaseModel): + title = CharField() + content = TextField() + created_at = DateTimeField(default=datetime.now) + +db.create_tables([Post]) \ No newline at end of file diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..8e258e5 --- /dev/null +++ b/static/style.css @@ -0,0 +1,34 @@ +body { + font-family: Arial, sans-serif; + margin: 0; + padding: 0; + background-color: #f4f4f4; +} + +header { + background-color: #333; + color: #fff; + padding: 1rem; +} + +header h1 { + margin: 0; +} + +header a { + color: #fff; + text-decoration: none; +} + +main { + padding: 1rem; +} + +a { + color: #333; + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..48b4d9c --- /dev/null +++ b/templates/base.html @@ -0,0 +1,17 @@ + + + + + + Blog + + + +
+

My Blog

+
+
+ {% block content %}{% endblock %} +
+ + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..9a05e7a --- /dev/null +++ b/templates/index.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} + +{% block content %} +

Posts

+ + Create a new post +{% endblock %} \ No newline at end of file diff --git a/templates/post.html b/templates/post.html new file mode 100644 index 0000000..5a28b2b --- /dev/null +++ b/templates/post.html @@ -0,0 +1,8 @@ +{% extends 'base.html' %} + +{% block content %} +

{{ post.title }}

+

{{ post.created_at.strftime('%Y-%m-%d %H:%M') }}

+
{{ post.content }}
+ Back to posts +{% endblock %} \ No newline at end of file -- cgit 1.4.1-2-gfad0