Package: decore-Base
Introductiondecore Base is an out-of-the-box “Python to Vue.js” data application dashboard that helps you go from idea to view in a few simple steps. It is aimed at those who want to focus on the results of their algorithms, do scientific work or perform teaching and learning functions.Notesdecore Base is currently a work in progress, only locally deployable, only available for Windows and not yet production ready.The recommended IDE is Visual Studio Code and all my comments and documentation here will also refer to vscode only.Insights into the current status of the Decore project.This documentation was translated from German into English with Deepl.Features and IntegrationsReady-made SPA (Single Page Application) with Vue.js using Quasar Framework (https://github.com/quasarframework/quasar)Predefined Webapi for meta and actions with Flask (https://github.com/pallets/flask)Integrated ORM for data management and database interfaces (SQLite) powered by the great Peewee (https://github.com/coleifer/peewee)Data validation using Cerberus (https://github.com/pyeve/cerberus)Password management using pykeepass (https://github.com/libkeepass/pykeepass)Please support these great projects!ContributionThe biggest help I can get right now is if you take a look at the project and tell me what you think. I am grateful for any criticism.My current sample project is included directly in the Python package. To install the example application, please read the documentation inExample. Please readInstallation,UseandPreparationfirst.Anything found in the documentation in terms of features, bugs or ambiguities, please let me know.Please use the problem area in the repository for this purpose.Get startedTo illustrate application creation with decore Base, we will now create a small web application together.The decoartorators are primarily used to create meta-information for later evaluation in thedecore Frontweb application and are nothing to be afraid of.It’s really simple, please follow me!InstallationLet’s first create an empty Python project in your desired directory.To install decore Base, we run the following command in the project root directory. Let’s use the terminal in vscode.pipinstalldecore-BaseThis requires an enabled Python environment! To learn more about this, visitPython environments in VS Code.PreperationNow let’s create a new file namedapp.pyin the project root directory.To use decore Base, we first import it into the moduleapp.py.fromdecore_baseimportdecoreThen we use thepreparecommand to create all the necessary auxiliary files in the project root directory.Now, to actually prepare the application, we run the commandpython app.py--preparein the terminal. The path must be in the project root directory, i.e. where theapp.pyis located.UsageTo allow the Python interpreter to process the future base classes, we add the following import.frombasesimport*Typically, a Python main module contains a query that checks if it is the main module so that we can call themainfunction afterwards.Next, we create a lineif __name__ == '__main__':in theapp.pyfile.To create a new Decore application instance, we use a@decore.appdecoratedmain()function in theapp.pyfile, just below the line:if __name__ == '__main__':.fromdecore_baseimportdecorefrombasesimport*if__name__=='__main__':@decore.app(title='My App')defmain():passModelIn a model we define the data fields that are needed for the later assigned base. It serves as a database interface to the database drivers such as SQLite, MySQL, PostgreSQL, etc.We now create the file first_model.py in the directorymodelsand insert the following code:NoteTo avoid possible circular imports we create the model classes in a separate directorymodelsin our project root directory. The directorymodelswas created by the previously executed commandpython app.py--prepare.fromdecore_base.uniform.conform_modelimport*classFirst_model(Conform_model):firstname=CharField(verbose_name='First Name')lastname=CharField(verbose_name='Last Name')NoteIn the example shown here, we import, from theuniform library, the Conform_model class and extend it with the firstname and lastname fields.The models indecore Baseare based on the great Peewee ORM. To learn more about Peewee, visitPeewee ORM.WarningWhen importing please note that we import everything (*) from the conform_model namespace to get the field classes as well.BaseThese base classes serve the decore application as a carrier element for the view components, maintain the data model and are thus also considered the data source for evaluation in thedecore Frontweb application.Now we need to create a new Python module containing a base class, for example:first_base.py, in thebasesdirectory in our project root directory.
Thebasesdirectory was co-created by thepython app.py--preparecommand executed earlier.fromdecore_baseimportdecorefrommodels.first_modelimportFirst_model@decore.base(title='First Base',icon='mdi-home',model=First_model)classFirst_base:passNoteTo use the previously created model, we import it into the Base class and pass it to themodelparameter.WarningIn order for the Python interpreter to be able to process the base classes, we have to import them into the __init__.py file in thebasesdirectory. The order of the individual imports also determines the order indecore Front.We edit the__init__.pyfile and insert the following code:from.first_baseimportFirst_baseViewViews are used by the decore application to present the data sets in thedecore Frontweb application.With the view decorator we can now create a view component and link it to the previously created base class.We now edit thefirst_base.pyfile again and extend the code as follows:fromdecore_baseimportdecorefrommodels.first_modelimportFirst_model@decore.base(title='First Base',icon='mdi-home',model=First_model)classFirst_base:@decore.view(title='First View',icon='mdi-home',type='table',fields=[First_model.firstname,First_model.lastname])deffirst_view():passDialogDialogs are the supporting elements for widgets in thedecore Frontweb application. They can only be added to views and control the visibility and display style of child elements. Dialogs also get control over the submit functions of the widgets.In our case, we create a diaolg to create a new person with first name and last name.Here we go … again the filefirst_base.pyand extend the code as follows:fromdecore_baseimportdecorefrommodels.first_modelimportFirst_model@decore.base(title='My First Base',icon='mdi-home',model=First_model)classFirst_base:@decore.view(title='Person',icon='mdi-account',type='table',fields=[First_model.firstname,First_model.lastname])deffirst_view():@decore.dialog(title='Add Person',icon='mdi-plus',type='standard',display='drawer',activator='default-menu')deffirst_dialog():passWidgetWidgets are components with which we can perform interactions on the single record. They can only be added to dialogs and are stackable.What we need now is to create an input form to enter the data for the new person.fromdecore_baseimportdecorefrommodels.first_modelimportFirst_model@decore.base(title='My First Base',icon='mdi-home',model=First_model)classFirst_base:@decore.view(title='Person',icon='mdi-account',type='table',fields=[First_model.firstname,First_model.lastname])deffirst_view():@decore.dialog(title='Add Person',icon='mdi-plus',type='standard',display='drawer',activator='default-menu')deffirst_dialog():@decore.widget(title='Add Person Form',icon='mdi-account',type='form',fields=[First_model.firstname,First_model.lastname])deffirst_widget():passActionActions are methods with whichdecore Frontcan communicate withdecore Base. They can be added to views and widgets and are the only real class methods in the meta kit.We now need an action to store the data of the new person and extend the code infirst_base.pyas follows:fromdecore_baseimportdecorefrommodels.first_modelimportFirst_model@decore.base(title='My First Base',icon='mdi-home',model=First_model)classFirst_base:@decore.view(title='Person',icon='mdi-account',type='table',fields=[First_model.firstname,First_model.lastname])deffirst_view():@decore.dialog(title='Add Person',icon='mdi-plus',type='standard',display='drawer',activator='default-menu')deffirst_dialog():@decore.widget(title='Add Person Form',icon='mdi-account',type='form',fields=[First_model.firstname,First_model.lastname])deffirst_widget():@decore.action(title='Save Person',icon='mdi-content-save',type='submit')deffirst_action(self,data):item=First_model(**data['item'])item.title=item.firstname+' '+item.lastnameifitem.save():returnTrue,item.title+' saved successfully'else:returnFalse,'Error while saving '+item.titleNoteTo create a record with decore Base, we need to create an instance of the model. In our caseFirst_model. The instance is filled with the data from the form and then saved.The ID in the form of a UUID is generated automatically and does not have to be specified separately.WarningThe fieldtitlewas inherited from the classDeform_modeland must be used for each record creation. Otherwise the item will fail the validation.Run, Development and BuildTo start only your application, runpython app.pyin your project root directory. Use the terminal in vscode.Open the browser and typehttp://localhost:5555.DevelopmentTo develop your application, use your debugger with the[dev] decore base developmentprofile in vscode.Open the browser and typehttp://localhost:5555.BuildTo build your application, runpython app.py--buildin your project root directory. Use the terminal in vscode.Sample applicationTo better understand how decore base works, it is best to look at the sample application. The application represents my continuous development of decore base.https://github.com/KemoPanzah/decore_Sample