Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
GovernmentPlates committed Jan 27, 2024
0 parents commit 2ffff86
Show file tree
Hide file tree
Showing 47 changed files with 1,376 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: flake8 Lint

on: [push, pull_request]

jobs:
flake8-lint:
runs-on: ubuntu-latest
name: Lint
steps:
- name: Check out source repository
uses: actions/checkout@v3
- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: "3.11.3"
- name: flake8 Lint
uses: py-actions/flake8@v2
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Byte-compiled / optimized / DLL files
**/__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# 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/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# 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/
.DS_Store
15 changes: 15 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"recommendations": [
// linters and formatters
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"stylelint.vscode-stylelint",
"ms-python.flake8",
"ms-python.black-formatter",
// python
"ms-python.python",
"ms-python.vscode-pylance",
// Jinja
"samuelcolvin.jinjahtml",
]
}
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Flask Boilerplate
Your simple, yet opinionated, boilerplate for Flask projects.

## Why?
I've been using Flask for a while now, and I've found myself repeating the same steps over and over again when starting a new project. In order to save myself (and you) some time, I decided to create this boilerplate.

## Features
- User authentication (login, logout, register)
- 'Sane' defaults for Flask configuration
- A understandable project file structure
- A simple SQLite database (you can, of course, replace this with any other database that SQLAlchemy supports)
- Jinja2 templates with Flowbite (Tailwind) CSS (CDN version)
- A CLI for managing aspects of your project (use `kettle --help` to see the available commands)*

**In order to use `kettle`, you will need to install it with `pip install --editable cli` from the root directory of the project.*

## Get started

*I'm assuming you have Python 3.11+ installed on your machine and that you are comfortable with using the command line on your machine.*

1. Clone this repository and `cd` into it
2. Create a virtual environment with `python3 -m venv venv` (or `python -m venv venv` if you're on Windows) and activate it with `source venv/bin/activate` (or `venv\Scripts\activate.bat` if you're on Windows)
3. Install the dependencies with `pip install -r requirements.txt`
4. Run the application with `flask run` (or `python -m flask run` if you're on Windows) - you can also append `--debug` to enable debug mode
5. Open your browser and go to `http://localhost:5000`

And voilà, you're ready to open this project in your favorite editor and start working on your next big thing!

## Contributing
If you have any suggestions or improvements, then feel free to open an issue or a pull request. I'll be happy to take a look at it!

## Thanks

### Icons
The boiler, gears and download icon (as seen on the front page) are sourced from [Icons8](https://icons8.com/).

### CSS/UI
The CSS and UI is sourced from [Flowbite](https://flowbite.com/), which is a library of components and layouts for [Tailwind CSS](https://tailwindcss.com/).

### User profile avatars
The user profile avatars are sourced from [UI Avatars](https://ui-avatars.com/).

### Libraries
- [Flask](https://flask.palletsprojects.com/en/)
- [Flask-Login](https://flask-login.readthedocs.io/en/latest/)
- [Flask-WTF](https://flask-wtf.readthedocs.io/en/)
- [Flask-SQLAlchemy](https://flask-sqlalchemy.palletsprojects.com/en/)
- [python-dotenv](https://pypi.org/project/python-dotenv/)

*See the `requirements.txt` for the full list of libraries that is used.*

## License/Legal/"Don't sue me, thanks" section
The boilerplate is not licensed, however, the libraries used are. Please check the respective licenses for each library.

Disclaimer: Flask is a trademark of [Pallets](https://palletsprojects.com/), and is not affiliated with this project in any way.
Binary file added app.db
Binary file not shown.
3 changes: 3 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from app import create_app

app = create_app()
38 changes: 38 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from flask import Flask, abort
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager

from .modules.util.config import eval_bool_env_var

db = SQLAlchemy()
login = LoginManager()


def create_app(config_class=Config):
app = Flask(__name__, template_folder="templates")
app.config.from_object(Config)

db.init_app(app)
login.init_app(app)
login.login_view = "auth.login"

from app.main import main as main

app.register_blueprint(main)

from app.auth import auth as auth

app.register_blueprint(auth)

from app import errors

app.register_blueprint(errors.error)

@app.before_request
def maintenance_mode():
# If maintenance mode is enabled, return a 503
if eval_bool_env_var(app.config["MAINTENANCE_MODE"]):
abort(503)

return app
5 changes: 5 additions & 0 deletions app/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from flask import Blueprint

auth = Blueprint("auth", __name__)

from app.auth import routes # noqa: E402, F401
22 changes: 22 additions & 0 deletions app/auth/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from flask_wtf import FlaskForm
from wtforms import EmailField, StringField, PasswordField, SubmitField
from wtforms.validators import DataRequired, Email, Length


class RegistrationForm(FlaskForm):
first_name = StringField(
"First Name", validators=[DataRequired(), Length(min=2, max=30)]
)
last_name = StringField(
"Last Name", validators=[DataRequired(), Length(min=2, max=30)]
)
email = EmailField("Email", validators=[DataRequired(), Email()])
password = PasswordField("Password", validators=[DataRequired()])
repeat_password = PasswordField("Password", validators=[DataRequired()])
submit = SubmitField("Register")


class LoginForm(FlaskForm):
email = EmailField("Email", validators=[DataRequired(), Email()])
password = PasswordField("Password", validators=[DataRequired()])
submit = SubmitField("Login")
Loading

0 comments on commit 2ffff86

Please sign in to comment.