Skip to content

Commit

Permalink
Merge pull request #17 from samdoghor/flask
Browse files Browse the repository at this point in the history
feat: defined secret_key generator, create more templates
  • Loading branch information
samdoghor authored Oct 29, 2023
2 parents b8ad981 + dd075b4 commit 05dae18
Show file tree
Hide file tree
Showing 102 changed files with 1,627 additions and 11 deletions.
7 changes: 6 additions & 1 deletion myte/create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from rich import print as mprint
from rich.console import Console
from rich.text import Text
from secret_key_generator import GenerateSecretKey


class CreateProject:
Expand Down Expand Up @@ -62,11 +63,13 @@ def create_dir(project_name, selected_framework, selected_setup):
mprint(messages["usage_message"]["environment_variable"])
mprint(Text(messages["usage_message"]
["database_configuration"], "cyan").wrap(console, 70))
mprint(
f"""{messages["usage_message"]["secret_key_configuration"]}[red] -> {GenerateSecretKey.generate_secret_key()}[/red]""") # noqa
mprint("\n")

@staticmethod
def create_files(selected_framework, selected_setup):
""" This function defines the creation of directory """
""" This function defines the creation of files in same directory """

console = Console()

Expand Down Expand Up @@ -118,4 +121,6 @@ def create_files(selected_framework, selected_setup):
mprint(messages["usage_message"]["environment_variable"])
mprint(Text(messages["usage_message"]
["database_configuration"], "cyan").wrap(console, 70))
mprint(
f"""{messages["usage_message"]["secret_key_configuration"]}[red] -> {GenerateSecretKey.generate_secret_key()}[/red]""") # noqa
mprint("\n")
3 changes: 2 additions & 1 deletion myte/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

"environment_variable": "[cyan] - Rename example.env to .env [/cyan]",

"database_configuration": " - Go to config.py, decide the database you want to use, uncomment it and run the pip instructions there"
"database_configuration": " - Go to config.py, decide the database you want to use, uncomment it and run the pip instructions there ",
"secret_key_configuration": "[cyan] - Go to .env, replace 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' in SECRETKEY with[/cyan]"

},
"os":{
Expand Down
21 changes: 21 additions & 0 deletions myte/secret_key_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# secret_key_generator.py

"""
This module generates secret keys to used in the frameworks templates
"""


import secrets
import string


class GenerateSecretKey:
""" This class is use to generate secret key to be used for security
purposes """

def generate_secret_key(length=32):
""" The function generates a 32 character secret key """

alphabet = string.ascii_letters + string.digits
secret_key = ''.join(secrets.choice(alphabet) for _ in range(length))
return secret_key
160 changes: 160 additions & 0 deletions myte/templates/template-flask-moderate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# 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/
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/
cover/

# 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
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .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

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__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/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
7 changes: 7 additions & 0 deletions myte/templates/template-flask-moderate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# myte_moderate_flask_template

## Features

## Contribution

## Contact
16 changes: 16 additions & 0 deletions myte/templates/template-flask-moderate/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# database
DATABASE_HOST = ''
DATABASE_PORT = 5432
DATABASE_USERNAME = ''
DATABASE_PASSWORD = ''
DATABASE_NAME = ''

# application
APPHOST = '0.0.0.0'
APPPOST = 3000

# environment
ENVIRONMENT = 'dev'

# security
SECRETKEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
44 changes: 44 additions & 0 deletions myte/templates/template-flask-moderate/src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# app.py

"""
This module defines...
"""

# imports

from flask import Flask, render_template
from flask_migrate import Migrate

import config
from models import db

# configurations

app = Flask(__name__)

app.debug = config.DEBUG
app.config['SQLALCHEMY_DATABASE_URI'] = config.SQLALCHEMY_DATABASE_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = config.SQLALCHEMY_TRACK_MODIFICATIONS # noqa
app.config['SECRET_KEY'] = config.SECRET_KEY

db.init_app(app)
db.app = app
migrate = Migrate(app, db)

# application


@app.route('/', methods=['GET'])
def index():
""" This function defines... """

# write your logic here

return render_template('pages/index.html'), 200

# entrypoint


if __name__ == "__main__":
app.debug = config.DEBUG
app.run()
Empty file.
44 changes: 44 additions & 0 deletions myte/templates/template-flask-moderate/src/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# config.py

"""
This module defines...
"""

# imports

import os

from dotenv import load_dotenv

# configurations

load_dotenv()

DATABASE_USERNAME = os.getenv('DATABASE_USERNAME')
DATABASE_PASSWORD = os.getenv('DATABASE_PASSWORD')
DATABASE_HOST = os.getenv('DATABASE_HOST')
DATABASE_PORT = os.getenv('DATABASE_PORT')
DATABASE_NAME = os.getenv('DATABASE_NAME')

DEBUG = True

# databases
# delete any database you don't want to use

# postgreSQL - default (pip install psycopg2 (windows users) or psycopg2-binary (linux and mac users)) # noqa

SQLALCHEMY_DATABASE_URI = f'postgresql://{DATABASE_USERNAME}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}' # noqa

# # mySQL (pip install mysql-connector-python)
# uncomment line 35 to use MySQL DB and comment line 30

# SQLALCHEMY_DATABASE_URI = f'mysql://{DATABASE_USERNAME}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}' # noqa

# # SQLite (goto https://www.sqlite.org/download.html, download and install, if you've not) # noqa
# uncomment line 40 to use SQLite DB and comment line 30

# SQLALCHEMY_DATABASE_URI = f'sqlite:///{DATABASE_NAME}.db'

SQLALCHEMY_TRACK_MODIFICATIONS = False

SECRET_KEY = os.getenv('SECRETKEY')
36 changes: 36 additions & 0 deletions myte/templates/template-flask-moderate/src/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
This module defines all forms needed by the users
"""
# imports

from flask_wtf import FlaskForm
from flask_wtf.file import FileAllowed, FileField
from wtforms import IntegerField, SelectField, StringField, SubmitField
from wtforms.validators import DataRequired, Email


# forms


class CreateUserForm(FlaskForm):

""" This class is use to create new users """

name = StringField('Name', validators=[DataRequired()])
email_address = StringField('Email Address', validators=[Email()])
phone_number = IntegerField('Phone Number')
street_name = StringField('Street Name', validators=[DataRequired()])
city = StringField('City', validators=[DataRequired()])
state = StringField('State', validators=[DataRequired()])
country = SelectField('Country', validators=[DataRequired()], choices=[])
zipcode = StringField('Zipcode', validators=[DataRequired()])
user_photo = FileField('Logo', validators=[FileAllowed(
['jpg', 'png'], 'JPG & PNG Formats Only!')])
create_user = SubmitField('Add user')


class DeleteUserForm(FlaskForm):

""" This class is use to create new users """

delete_user = SubmitField('Yes')
Loading

0 comments on commit 05dae18

Please sign in to comment.