Skip to content

Commit

Permalink
Release v1.0.8 - Fix Broken Release
Browse files Browse the repository at this point in the history
  • Loading branch information
app-generator committed Aug 11, 2022
1 parent 5ba1b13 commit 4b11836
Show file tree
Hide file tree
Showing 78 changed files with 167,332 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
__pycache__
*.pyc
*.pyo
*.pyd
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# True for development, False for production
DEBUG=True

# Flask ENV
FLASK_APP=run.py
FLASK_ENV=development

# Used for CDN (in production)
# No Slash at the end
ASSETS_ROOT=/static/assets
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# tests and coverage
*.pytest_cache
.coverage

# database & logs
*.db
*.sqlite3
*.log

# venv
env
venv

# other
.DS_Store

# sphinx docs
_build
_static
_templates

# javascript
package-lock.json
.vscode/symbols.json

apps/static/assets/node_modules
apps/static/assets/yarn.lock
apps/static/assets/.temp

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [1.0.8] 2022-08-11
### Patch

- Fix Broken Release
- wrong Flask codebase was used.

## [1.0.7] 2022-08-11
### Improvements

Expand Down
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.9

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

COPY requirements.txt .

# install python dependencies
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

# gunicorn
CMD ["gunicorn", "--config", "gunicorn-cfg.py", "run:app"]
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn run:app --log-file=-
43 changes: 1 addition & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Open-source **Flask Dashboard** generated by `AppSeed` op top of an iconic desig
> Features
- `Up-to-date dependencies`
- Database: `mysql`
- Database: `SQLite`
- `DB Tools`: SQLAlchemy ORM, Flask-Migrate (schema migrations)
- Session-Based authentication (via **flask_login**), Forms validation

Expand All @@ -21,7 +21,6 @@ Open-source **Flask Dashboard** generated by `AppSeed` op top of an iconic desig

<br />


## ✨ Start the app in Docker

> **Step 1** - Download the code from the GH repository (using `GIT`)
Expand All @@ -44,46 +43,6 @@ Visit `http://localhost:5085` in your browser. The app should be up & running.

<br />

## ✨ Set up the MySql Database

**Note:** Make sure your Mysql server is properly installed and accessible.

> **Step 1** - Create the MySql Database to be used by the app
- `Create a new MySql` database
- `Create a new user` and assign full privilegies (read/write)

<br />

> **Step 2** - Edit the `.env` to match your MySql DB credentials. Make sure `DB_ENGINE` is set to `mysql`.
- `DB_ENGINE` : `mysql`
- `DB_NAME` : default value = `appseed_db`
- `DB_HOST` : default value = `localhost`
- `DB_PORT` : default value = `3306`
- `DB_USERNAME`: default value = `appseed_db_usr`
- `DB_PASS` : default value = `pass`

<br />

Here is a sample:

```txt
# .env sample
DEBUG=False # False enables the MySql Persistence
DB_ENGINE=mysql # Database Driver
DB_NAME=appseed_db # Database Name
DB_USERNAME=appseed_db_usr # Database User
DB_PASS=STRONG_PASS_HERE # Password
DB_HOST=localhost # Database HOST, default is localhost
DB_PORT=3306 # MySql port, default = 3306
```

<br />


## ✨ How to use it

> Download the code
Expand Down
44 changes: 44 additions & 0 deletions apps/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- encoding: utf-8 -*-
"""
Copyright (c) 2019 - present AppSeed.us
"""

from flask import Flask
from flask_login import LoginManager
from flask_sqlalchemy import SQLAlchemy
from importlib import import_module


db = SQLAlchemy()
login_manager = LoginManager()


def register_extensions(app):
db.init_app(app)
login_manager.init_app(app)


def register_blueprints(app):
for module_name in ('authentication', 'home'):
module = import_module('apps.{}.routes'.format(module_name))
app.register_blueprint(module.blueprint)


def configure_database(app):

@app.before_first_request
def initialize_database():
db.create_all()

@app.teardown_request
def shutdown_session(exception=None):
db.session.remove()


def create_app(config):
app = Flask(__name__)
app.config.from_object(config)
register_extensions(app)
register_blueprints(app)
configure_database(app)
return app
12 changes: 12 additions & 0 deletions apps/authentication/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- encoding: utf-8 -*-
"""
Copyright (c) 2019 - present AppSeed.us
"""

from flask import Blueprint

blueprint = Blueprint(
'authentication_blueprint',
__name__,
url_prefix=''
)
31 changes: 31 additions & 0 deletions apps/authentication/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- encoding: utf-8 -*-
"""
Copyright (c) 2019 - present AppSeed.us
"""

from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField
from wtforms.validators import Email, DataRequired

# login and registration


class LoginForm(FlaskForm):
username = StringField('Username',
id='username_login',
validators=[DataRequired()])
password = PasswordField('Password',
id='pwd_login',
validators=[DataRequired()])


class CreateAccountForm(FlaskForm):
username = StringField('Username',
id='username_create',
validators=[DataRequired()])
email = StringField('Email',
id='email_create',
validators=[DataRequired(), Email()])
password = PasswordField('Password',
id='pwd_create',
validators=[DataRequired()])
48 changes: 48 additions & 0 deletions apps/authentication/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- encoding: utf-8 -*-
"""
Copyright (c) 2019 - present AppSeed.us
"""

from flask_login import UserMixin

from apps import db, login_manager

from apps.authentication.util import hash_pass

class Users(db.Model, UserMixin):

__tablename__ = 'Users'

id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), unique=True)
email = db.Column(db.String(64), unique=True)
password = db.Column(db.LargeBinary)

def __init__(self, **kwargs):
for property, value in kwargs.items():
# depending on whether value is an iterable or not, we must
# unpack it's value (when **kwargs is request.form, some values
# will be a 1-element list)
if hasattr(value, '__iter__') and not isinstance(value, str):
# the ,= unpack of a singleton fails PEP8 (travis flake8 test)
value = value[0]

if property == 'password':
value = hash_pass(value) # we need bytes here (not plain str)

setattr(self, property, value)

def __repr__(self):
return str(self.username)


@login_manager.user_loader
def user_loader(id):
return Users.query.filter_by(id=id).first()


@login_manager.request_loader
def request_loader(request):
username = request.form.get('username')
user = Users.query.filter_by(username=username).first()
return user if user else None
Loading

0 comments on commit 4b11836

Please sign in to comment.