Skip to content

Commit 26a69cc

Browse files
committed
Bump version to 1.9.2; update dependencies and enhance documentation
1 parent 3e79d92 commit 26a69cc

File tree

4 files changed

+91
-25
lines changed

4 files changed

+91
-25
lines changed

build/lib/flask_wiz/cli.py

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
import click
33
from flask import Flask
44

5+
db_options = {'1':'mongodb', '2':'sqlite', '3':'mysql', '4':'postgresql'}
6+
value_key = {v: k for k,v in db_options.items()} #created reverse mapping of values to keys
7+
8+
#to display options
9+
def display_options():
10+
options = "\n".join([f"{key}: {value}" for key, value in db_options.items()])
11+
return f"Select database system:\n{options}\n(Enter either key or value)"
12+
513
def create_app():
614
app = Flask(__name__)
715

@@ -19,14 +27,46 @@ def cli():
1927
def new():
2028
name = click.prompt('Enter project name')
2129

22-
db_options = ['mongodb', 'sqlite', 'mysql', 'postgresql']
23-
db = click.prompt('Select database system', type=click.Choice(db_options))
30+
click.echo(display_options())
31+
db_input = click.prompt('Enter key / Value for db selection')
32+
33+
if db_input in db_options:
34+
db = db_options[db_input]
35+
elif db_input in value_key:
36+
db = value_key[db_input]
37+
else:
38+
click.echo('Invalid input')
39+
return
2440

2541
os.makedirs(name)
2642
os.chdir(name)
2743

2844
os.makedirs('templates')
45+
os.chdir('templates')
46+
47+
with open('home.html', 'w') as home_file:
48+
home_file.write("""<!DOCTYPE html>
49+
<html lang="en">
50+
<head>
51+
<meta charset="UTF-8">
52+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
53+
<title>Flask-app</title>
54+
</head>
55+
<body>
56+
<h1>flask app generated with flask-wiz</h1>
57+
<p>{{ message }}</p>
58+
</body>
59+
</html>""")
60+
61+
os.chdir('..')
62+
2963
os.makedirs('static')
64+
os.chdir('static')
65+
66+
os.makedirs('css')
67+
os.makedirs('js')
68+
os.makedirs('img')
69+
os.chdir('..')
3070

3171
with open('.gitignore', 'w') as gitignore_file:
3272
gitignore_file.write("# Default .gitignore for Flask project\n")
@@ -40,10 +80,12 @@ def new():
4080
with open('app.py', 'w') as app_file:
4181
db_module = None
4282

43-
if db == 'mongodb':
44-
db_module = 'pymongo'
45-
app_file.write(
46-
"""from flask import Flask
83+
84+
match db_input:
85+
case '1':
86+
db_module = 'pymongo'
87+
app_file.write(
88+
"""from flask import Flask, render_template, redirect
4789
from pymongo import MongoClient
4890
4991
app = Flask(__name__)
@@ -52,64 +94,71 @@ def new():
5294
5395
@app.route('/')
5496
def index():
55-
return 'Namaste Duniya! This is a Flask app generated by Flask-Wiz for MongoDB.'
97+
return render_template('home.html', message = 'Namaste Duniya! This is a Flask app generated by Flask-Wiz for MongoDB.')
5698
5799
if __name__ == '__main__':
58100
app.run()
59101
""")
60-
elif db == 'sqlite':
61-
db_module = 'sqlite3'
62-
app_file.write(
63-
"""from flask import Flask
102+
case '2':
103+
db_module = 'sqlite3'
104+
app_file.write(
105+
"""from flask import Flask, render_template, redirect
64106
import sqlite3
65107
66108
app = Flask(__name__)
67109
conn = sqlite3.connect('database.db')
68110
69111
@app.route('/')
70112
def index():
71-
return 'Namaste Duniya! This is a Flask app generated by Flask-Wiz for SQLite.'
113+
return render_template('home.html', message = 'Namaste Duniya! This is a Flask app generated by Flask-Wiz for SQLite.')
72114
73115
if __name__ == '__main__':
74116
app.run()
75117
""")
76-
elif db == 'mysql':
77-
db_module = 'pymysql'
78-
app_file.write(
79-
"""from flask import Flask
118+
case '3':
119+
db_module = 'pymysql'
120+
app_file.write(
121+
"""from flask import Flask, render_template, redirect
80122
import pymysql
81123
82124
app = Flask(__name__)
83125
conn = pymysql.connect(host='localhost', user='root', password='', database='my_database')
84126
85127
@app.route('/')
86128
def index():
87-
return 'Namaste Duniya! This is a Flask app generated by Flask-Wiz MySQL.'
129+
return render_template('home.html', message = 'Namaste Duniya! This is a Flask app generated by Flask-Wiz MySQL.')
88130
89131
if __name__ == '__main__':
90132
app.run()
91133
""")
92-
elif db == 'postgresql':
93-
db_module = 'psycopg2'
94-
app_file.write(
95-
"""from flask import Flask
134+
case '4':
135+
db_module = 'psycopg2'
136+
app_file.write(
137+
"""from flask import Flask, render_template, redirect
96138
import psycopg2
97139
98140
app = Flask(__name__)
99141
conn = psycopg2.connect(host='localhost', user='postgres', password='', dbname='my_database')
100142
101143
@app.route('/')
102144
def index():
103-
return 'Namaste Duniya! This is a Flask app generated by Flask-Wiz PostgreSQL.'
145+
return render_template('home.html', message = 'Namaste Duniya! This is a Flask app generated by Flask-Wiz PostgreSQL.')
104146
105147
if __name__ == '__main__':
106148
app.run()
107149
""")
150+
case _:
151+
print('Invalid choice. Please choose a valid database system.')
108152

109153
if db_module:
110-
os.system(f"pip install {db_module}") # Install the required database module
111154

112-
click.echo(f'New Flask project "{name}" created successfully with {db} database!')
155+
if db_module != 'sqlite3':
156+
os.system(f"pip install {db_module}") # Install the required database module
157+
158+
# to create a requirements file
159+
os.system(f"pip freeze > requirements.txt")
160+
161+
click.echo(f'New Flask project "{name}" created successfully with {db_module} database!')
113162

114163
if __name__ == '__main__':
115164
cli()

dist/flask_wiz-1.9.2-py3-none-any.whl

4.01 KB
Binary file not shown.

dist/flask_wiz-1.9.2.tar.gz

3.41 KB
Binary file not shown.

flask_wiz.egg-info/PKG-INFO

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
Metadata-Version: 2.1
22
Name: flask-wiz
3-
Version: 1.9.1
3+
Version: 1.9.2
44
Author: Krish Soni
55
Description-Content-Type: text/markdown
6+
Requires-Dist: flask
7+
Requires-Dist: click
8+
Requires-Dist: Flask
69

710
# Flask-Wiz: Simplified Flask Setup
811

@@ -29,10 +32,24 @@ pip install flask-wiz
2932

3033
```Terminal
3134
flask-wiz new
35+
Project Name: my_project
36+
Database (MongoDB/SQLite/MySQL/PostgreSQL):
37+
```
38+
39+
```Terminal
40+
<project_name>/
41+
42+
├── templates/
43+
├── static/
44+
├── .gitignore
45+
└── .env
3246
```
3347

3448
3. **Follow the Prompts**: Flask-Wiz will guide you through the setup process, including selecting your desired database and configuring directory structure.
3549

3650
4. **Start Developing**: Once the setup is complete, you're ready to start developing your Flask application!
3751

3852
Flask-Wiz simplifies the setup process for Flask projects, allowing you to focus on building your application without worrying about initial configuration.
53+
54+
## Need More Assistance
55+
- Visit: https://www.blackbox.ai/agent/flask-wizhelpN9qFZun

0 commit comments

Comments
 (0)