Modules/Apps¶
Modules allow you to get Django’s plug and play behaviour. The are functionally similar to Django apps. Modules are created in the modules folder. This makes it easier to comprehend than Django as you can see at a glance what is the main script and what are modules/apps.
Easy way to create module¶
Once inside a Shopyo project directory (i.e
where the app.py and modules/ reside), run
shopyo startapp [OPTIONS] MODULENAME [BOXNAME]
For example if you run shopyo startapp product, it will auto create
the following module structure inside modules/
modules/product/
├── forms.py
├── global.py
├── info.json
├── models.py
├── static
├── templates
│ └── demo
│ ├── blocks
│ │ └── sidebar.html
│ └── dashboard.html
├── tests
│ ├── test_demo_functional.py
│ └── test_demo_models.py
└── view.py
Note
The models.py and forms.py files are generated with standard Shopyo imports (PkModel, FlaskForm) to get you started quickly.
In case you want to group modules together in a particular subcategory, you can create modules inside a box. For example first run
shopyo startapp subscriptions box__billing
This will create the box box__billing if it does not exist and then create the module
subscriptions insides it. If now you want another module, for example, invoices inside box__billing,
then you can run:
shopyo startapp invoices box__billing
With this your modules structure will look like this:
modules/
├── box__billing/
│ ├── subscriptions/
│ └── invoices/
└── ...
You can now access the /subscriptions and /invoices endpoints
See startapp for more details on command usage. You might find the EuroPython talk under the Education Section insightful
info.json¶
The info file allows you to specify module config. This allows you to specify the module url and panel icon.
{
"author": {
"mail": "",
"name": "",
"website": ""
},
"display_string": "Page",
"module_name":"page",
"type": "show",
"fa-icon": "fa fa-store",
"url_prefix": "/page",
"dashboard": "/dashboard"
}
"author: Metadata to keep track of author of the module. It stores author’smail,name, andwebsiteinformationdisplay_string: Display name on control panel. If you decide to use Shopyo as a Flask base, it does not matter thenmodule_name: Shopyo uses this to reference the module. Not to be duplicatedtype: Used to show or hide modules on control panel. If control panel module not present, you can skip itfa-icon: Used to show fontawesome icon on control panel. If control panel module not present, you can skip iturl_prefix: Needed to specify module’s base urldashboard: Used to redirect in control panel. For example the contact module’s url is/contact. But we want it to be public. So we have a panel redirect of/dashboardto direct admin to/contact/dashboard. Dont include if you don’t want redirect
Default Modules/Boxes¶
The app comes with several default modules now shipped as separate packages in default_packages/:
shopyo_appadmin
shopyo_auth
shopyo_base
shopyo_dashboard
shopyo_i18n
shopyo_page
shopyo_settings
shopyo_theme
www¶
This is the default public facing module located in shopyo/modules/www.
Using Shopyo as a Flask base¶
You can customise Shopyo in many ways. For eample, you can modify exiting modules, add more modules to default boxes or even remove the modules you do not need. You might however want to keep the following modules:
appadmin
auth
base
dashboard
settings
Importing modules¶
If you want to import from forms.py in same folder you write from .forms import ... . If you want to import from other modules you do: `from modules.modulename.forms import ...`
global.py¶
Expects
# global templates variables in here
available_everywhere = {
"x": 1
} # now x available in all templates
# global configs in here, defined by profile
configs = {
"development": {
"CONFIG_VAR": "DEVVALUE"
},
"production": {
"CONFIG_VAR": "PRODVALUE"
},
"testing": {
"CONFIG_VAR": "TESTVALUE"
}
} # these values will load depending on the current config profile
upload.py¶
upload.py has a def upload(): function where uploads should be done.
This uploads are done when we run shopyo initialise.