📜 ⬆️ ⬇️

LOTSMAN: We write our WorkFlow configurator. Start

Introduction


I work in an organization that began to introduce software from ASCON, to be precise, the “ASCON 2013 Solution Complex” (hereinafter referred to as the “Complex”) + COMPAS. I am in charge of administering this “Complex”. The “complex” has a three-tier architecture (Client-Server, Application-Database Server). The key product of the "Complex" is LOTSMAN: PLM, there is also a set of administration utilities. One of the administration utilities is called “LOTSMAN WorkFlow Configurator” (hereinafter referred to as WF configurator).

image
Figure 1 - LOTSMAN WorkFlow Configurator

During the work, the main disadvantages of the WF configurator were identified:

Since users had to add often and a lot, I had to figure out how to optimize this process.

The WF configurator has a lot of functionality, but for now I’m only interested in adding users.
')
To eliminate the estimated delays, I decided to work directly with the database, bypassing the "Application Server". After the analysis (I had to manually look at the contents of the tables), several tables (wfActors, wfDepartments, wfRoles, wfUserRoles) were identified, in which the necessary data are stored. As a result, the procedure of adding a user to a post has been reduced to the fact that you need to add an entry to just 1 table (wfUserRoles), which contains entries of the form (inIdUser, inIdRole, dtStart, dtEnd):

  1. inIdUser - user id;
  2. inIdRole- role id (position);
  3. dtStart - start date;
  4. dtEnd is the end date.

If the fields for the start / end date are NULL, it means that the user’s term in office is unlimited.

The action algorithm is as follows:

  1. We find the user id select * from wfActors where stDescription like '%' order by stDescription , the result is a table with user id fields, a Russian username. Remember the user id;
  2. We find which unit to add the user to select * from wfDepartments , the result is a table with the fields of the id-division, the name of the division, the id-parent of the division. We remember id-divisions;
  3. We find a position in the required subdivision select * from wfRoles where inIdDepartment = id-( . ) , the result is a table with the fields id-positions, id-subdivisions, the name of the position, remember id-positions.
  4. now we have user id and position id (in the required subdivision), all that remains is to add an entry to the insert into wfUserRoles values (id-, id-,null,null). table insert into wfUserRoles values (id-, id-,null,null).

Even executing these SQL queries in Managment Studio, the user was added faster than through the WF configurator. Then a script was written in Python that performed all these actions in the console.

The next step is to develop a GUI for this script, after analyzing which of the GUI libraries there are for Python I chose PySide.

The following was installed on the home computer:

1) Installed in the virtual:


2) Installed on the computer:


Once everything is installed, you can begin to develop.

I painted an application form in QT Designer, saved it in a file with the .ui extension.

PySide has a great tool, pyside-uic.exe, with which you can create a .py file from a ui file. To do this, it is sufficient to execute the following command in the console: pyside-uic.exe file.ui -o file.py If you also specify the -x argument, then this file.py can be immediately launched and the form drawn in Designer will be displayed. I found out about this parameter (-x) a little later, when I already used the instructions from zetcode.com/gui/pysidetutorial , so my code is slightly different from that generated using pyside-uic.exe file.ui -x -o file.py .

Here is the shape I got:

image
Figure 2 - My WorkFlow Configurator

Used pypyodbc library to work with the database, PySide to work with the form.

It turned out 3 files:

  1. GUI drawing and event binding from the form to various functions;
  2. class to work with the database
  3. just a text file from which the initial settings for the form are loaded (and saved on exit)

To add a user to a post, you must first connect the “Connect” button to the database (the login and password are currently registered directly in the program code), the “Organization Structure” tree appears, you can expand the elements if they have nested (1 click) and go to the selected element (double click), then select the position. Find a user by last name (“Search” button), select the found user and click the “INSERT” button (the position in the tree should be selected and the user should be selected in the search results field).

An interesting point was the construction of the tree, until this moment I did not come across this. I want to write something easier, but for now I’m forming a list of elements.

  treeItems=[] for l in sorted(list1): parent=str(l[2]) itemId=str(l[0]) descr=str(l[1]) treeItem=QtGui.QTreeWidgetItem([descr,itemId,parent]) treeItems.append(treeItem) treeItemsFin=[] i=1 for item in treeItems: for itemj in treeItems[i:]: if item.text(1)==itemj.text(2): item.insertChild(0,itemj) i+=1 treeItemsFin.append(item) self.treeWid.insertTopLevelItems(0,treeItemsFin) 


First, from a normal list (with items of the form: [id-item, description, parent-id]), form a list of objects of type QTreeWidgetItem (first cycle), and then from this list form another list of items, such as QTreeWidgetItem, but with a nesting.

So far I have intentionally refused to display already added users, because it seems to me that this is the problem with the ASCON WF configurator, they have the entire tree updated after each operation and it takes a lot of time.

In the future, I plan to make the display of users only in the selected branch.

So far, only I use this application, but perhaps other administrators will come in handy ... The application requires Python, PySide, pypyodbc installed on the administrator’s computer, unlike the WF configurator and ASCON, is cross-platform.

Results

Of the benefits, the main objectives are affected:
+ Russian search by users;
+ quick work time.

Minuses:
- posts are not displayed if they are in the root of the tree (i.e., in none of the divisions, I plan to finalize);
- already added users are not displayed in the tree (I plan to modify it);
- there is no functionality to create / delete a unit, position (I plan to finalize);
- there is no functionality for business processes, automatic operations, etc., which is in the ASCON WF configurator (I do not plan to add it in the near future, as I use it not so often and it seems to work fine).

That's all for now, the source code on github.com .

List of used sources


zetcode.com/gui/pysidetutorial
deptinfo-ensip.univ-poitiers.fr/ENS/pyside-docs/index.html
www.pythoncentral.io/pyside-pyqt-tutorial-using-built-in-signals-and-slots

Source: https://habr.com/ru/post/238813/


All Articles