First application

Note

More documentation to read about this example at:

Here it is shown how to create the first pyforms app for a django project.

Note

The instructions on this page assumes you know how the Django framework works.

Prepare the django app

Create a empty django app folder with the next directory structure inside:

my_module_name
├── apps
│   └── __init__.py
└── __init__.py

Add the application to the settings.py

INSTALLED_APPS = [
    'my_module_name',
    ...
]

Create the first app

Create the file my_module_name/apps/site_crawl.py and add the next code to it.

from pyforms.basewidget import BaseWidget
from confapp import conf

class SiteCrawlApp(BaseWidget):

    UID                  = 'site-crawl-app'
    TITLE                = 'Site crawl'

    LAYOUT_POSITION      = conf.ORQUESTRA_HOME

    ORQUESTRA_MENU       = 'left'
    ORQUESTRA_MENU_ICON  = 'browser'
    ORQUESTRA_MENU_ORDER = 0

In the my_module_name/apps/__init__.py add the next code:

from .site_crawl import SiteCrawlApp

You have created the most basic application. Access to http://localhost:8000 using your browser and visualize it.

Now update the SiteCrawlApp application with the next code:

from pyforms.basewidget import BaseWidget
from confapp import conf

from pyforms.controls import ControlButton
from pyforms.controls import ControlText
from pyforms.controls import ControlList

class SiteCrawlApp(BaseWidget):

    UID                  = 'site-crawl-app'
    TITLE                = 'Site crawl'

    LAYOUT_POSITION      = conf.ORQUESTRA_HOME

    ORQUESTRA_MENU       = 'left'
    ORQUESTRA_MENU_ICON  = 'browser'
    ORQUESTRA_MENU_ORDER = 0


    def __init__(self, *args, **kwargs):

        super(SiteCrawlApp, self).__init__(*args, **kwargs)

        self._url          = ControlText('Page url')
        self._getlinks_btn = ControlButton('Get links', default=self.___getlinks_btn_evt, label_visible=False)

        self._links_list   = ControlList('Links list', horizontal_headers=['Found links'])

        self.formset = ['_url', '_getlinks_btn', '_links_list']


    def ___getlinks_btn_evt(self):

        self._links_list.value = [
            ['Link1'],
            ['Link2']
        ]

Restart your django project to visualize the updates.

Press the button to see what happens.

../_images/first-app.png