Plasta is a framework written in Python for rapid deployment of CRUDs in a simple way, in a few steps and in few lines of code.
Is designed with the MVC pattern and the DRY (Don't Repeat Yourself) development technique.
Sinopsis
In software engineering we often find the task of performing various CRUD (Create, read, update and delete) in the development of a typical management system or application. This leads to the repetitive task of writing the same operations over and over again for each CRUD being performed, increasing deployment time, lines of code, risk of errors and increased maintenance. Plasta born to cover the task of automating these processes.
It focuses on both deployment and maintenanceof an aplication is minimized, for this the core of Plasta is designed so that at any time, if necessary, you can reimplement any method that does not meet our interests. Leaving it open to the possibility of a more comfortable development.
Technical features
Structure of a CRUD
Each CRUD is made up of a Python package, that contains the follow structure:
- Object Class (e.g.: People).
- Manager Class (e.g.: PeopleManager)
- Main Class of the CRUD (e.g.: PeopleGUI)
- Adding a Record Class (e.g.: AddPeople)
- Qt's .ui File for screen.
Then the resulting package would be something like this:
/people
|--- __init__.py
|--- manager.py
|--- gui.py
|--- add.py
|--- add.ui
1. Creating the init.py file
Here define your class attributes
from storm.locals import *
class People (object):
# table name in the database for this object
__storm_table__ = "peoples"
# attributes of the class
ide = Int(primary = True)
names = Unicode(allow_none = False)
phone = Unicode()
address = Unicode()
zone = Int()
def __init__(self, names, phone, address, zone):
self.names = names
self.phone = phone
self.address = address
self.zone = zone
# value to be displayed when you invoke this function
def __str__(self):
return self.names
2. Creating the manager.py file
Once the Person object made, we create the controller class for this object.
from plasta.logic.manager import BaseManager
from people import People
class PeopleManager( BaseManager ):
def __init__( self, store, reset = False ):
BaseManager.__init__( self, store, reset )
# object to be handled by this controller
self.CLASS = People
self._start_operations()
3. Creating the gui.py file
from plasta.gui import BaseGUI
from people import People
from people.add import AddPeople
class PeopleGUI(BaseGUI):
def __init__(self, manager, managers = []):
# calls the base class constructor
BaseGUI.__init__(self, manager, managers)
# class display to add and edit dialogs
self.DialogAddClass = AddPeople
# attributes used as filters
self.addFiler(u'Names', People.names)
self.addFiler(u'Phone', People.phone)
self.addFiler(u'Address', People.address)
self.addFiler(u'Zone', People.zone)
# columns / attributes shown in the list
self.addTableColumn(u'Names', People.names)
self.addTableColumn(u'Phone', People.phone)
self.addTableColumn(u'Address', People.address)
self.addTableColumn(u'Zone', People.zone, alignment='C')
# performs operations start to lift the window
self._start_operations()
4. Creating the add.py file
Finally create the add.py file, and its contents would be this:
from os.path import join, abspath, dirname
from plasta.gui.add_window import BaseAdd
from people import People
class AddPeople(BaseAdd):
def __init__(self, manager, itemToEdit = False, managers = []):
# base class constructor
BaseAdd.__init__(self, manager, itemToEdit)
# read and get up ui file information
self.loadUI(join(abspath(dirname(__file__)),'add.ui'))
# here indicate what interface widget
# it corresponds to an attribute of the class
self.linkToAttribute(self.leNames, People.names)
self.linkToAttribute(self.lePhone, People.phone)
self.linkToAttribute(self.leAddress, People.address)
self.linkToAttribute(self.leZone, People.zone)
self._start_operations()
Wooyla, the resulting crud would look like:
Using the Plasta generator to create this package, the command would be:
$ python plastagen g crud -u people names phone address zone
For more details see Creating the first package Plasta
Introduction
Getting started
API
Use cases
- Create an object containing references
- Passing reference from one model to another
- Change the order of attributes displayed in the list
- Rename the attributes displayed in the list
- Change the main attribute of the class 'ide' by other
- Formatting attributes in the list
Example Apps
- Contact list
- Movements manager
Documentation available in Spanish here