Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Ease setup #18

Merged
merged 3 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,4 @@ shopyo/static/uploads/subcategory/
# modules in static since present in modules
shopyo/static/modules/

# ignore secrets
config.py
config.json
shopcube.db
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# ShopCube

![alt text](https://github.com/VaithiSniper/ShopCube/blob/dev/logo.png?raw=true)
![alt text](https://github.com/shopyo/ShopCube/blob/dev/logo.png?raw=true)


Copy paste config_demo.json to config.json in shopyo
Copy paste config_demo.py to config.py in shopyo and replace your SQLALCHEMY_DATABASE_URI details

install requirements

```
Expand All @@ -19,7 +16,7 @@ cd shopyo
python manage.py initialise
python manage.py rundebug
```

using shopyo/shopcube.db as db

browse around and go to /dashboard with login admin@domain.com and password pass

Expand All @@ -32,3 +29,21 @@ Current features:

Read the [shopyo](https://shopyo.readthedocs.io/en/latest/) docs to get more development insights

## Config DB


In shopyo/ create a new folder called instance

In shopyo/instance/ create a new file called config.py


In config.py add something like that, the following is for mysql:

```python
SQLALCHEMY_DATABASE_URI = "mysql+pymysql://{username}:{password}@{server_name}/{db_name}".format(
username='shopcube',
password='pass1234-A',
server_name='localhost',
db_name='shopcube'
)
```
45 changes: 32 additions & 13 deletions shopyo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,45 @@
from shopyoapi.path import modules_path
from shopyoapi.file import trycopy

try:
if not os.path.exists('config.py'):
trycopy('config_demo.py', 'config.py')
if not os.path.exists('config.json'):
trycopy('config_demo.json', 'config.json')
except PermissionError as e:
print('Cannot continue, permission error'
'initialising config.py and config.json, '
'copy and rename them yourself!')
raise e


from config import app_config

base_path = os.path.dirname(os.path.abspath(__file__))

def load_config_from_obj(app, config_name):

try:
configuration = app_config[config_name]
except KeyError as e:
print(
f"[ ] Invalid config name {e}. Available configurations are: "
f"{list(app_config.keys())}\n"
)
sys.exit(1)

app.config.from_object(configuration)


def load_config_from_instance(app, config_name):

if config_name != "testing":
# load the instance config, if it exists, when not testing
app.config.from_pyfile("config.py", silent=True)

# create empty instance folder and empty config if not present
try:
os.makedirs(app.instance_path)
with open(os.path.join(app.instance_path, "config.py"), "a"):
pass
except OSError:
pass

def create_app(config_name):

app = Flask(__name__)
configuration = app_config[config_name]
app.config.from_object(configuration)
load_config_from_obj(app, config_name)
load_config_from_instance(app, config_name)

migrate.init_app(app, db)
db.init_app(app)
ma.init_app(app)
Expand All @@ -59,6 +76,8 @@ def create_app(config_name):
mail = Mail()
mail.init_app(app)



configure_uploads(app, categoryphotos)
configure_uploads(app, subcategoryphotos)
configure_uploads(app, productphotos)
Expand Down
File renamed without changes.
15 changes: 2 additions & 13 deletions shopyo/config_demo.py → shopyo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Config:
"""Parent configuration class."""

DEBUG = False
# SQLALCHEMY_DATABASE_URI = "sqlite:///shopyo.db"
SQLALCHEMY_TRACK_MODIFICATIONS = False
SECRET_KEY = os.urandom(24)
BASE_DIR = base_path
Expand All @@ -21,12 +20,8 @@ class Config:
STATIC, "uploads", "subcategory"
)
PASSWORD_SALT = "abcdefghi"
# SQLALCHEMY_DATABASE_URI = "mysql+pymysql://{username}:{password}@{server_name}/{db_name}".format(
# username='shopyo_user',
# password='pass',
# server_name='localhost',
# db_name='shopyodb'
# )

SQLALCHEMY_DATABASE_URI = "sqlite:///shopcube.db"


class DevelopmentConfig(Config):
Expand All @@ -36,12 +31,6 @@ class DevelopmentConfig(Config):
DEBUG = True
# EXPLAIN_TEMPLATE_LOADING = True
LOGIN_DISABLED = True
SQLALCHEMY_DATABASE_URI = "mysql+pymysql://{username}:{password}@{server_name}/{db_name}".format(
username='freaksboutique_user',
password='root',
server_name='localhost',
db_name='freaksboutique'
)


class TestingConfig(Config):
Expand Down