-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from TUB-DVG/154-add-db-diff-functionality-fo…
…r-another-app Rollback feature for tools_over app
- Loading branch information
Showing
24 changed files
with
1,222 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+84.1 KB
webcentral/doc/01_data/02_tool_over/2024_05_EWB_tools_with_english_translation.xlsx
Binary file not shown.
Binary file added
BIN
+65.5 KB
webcentral/doc/01_data/02_tool_over/test_data/test_data_full_tool_list.xlsx
Binary file not shown.
Binary file added
BIN
+8.47 KB
webcentral/doc/01_data/02_tool_over/test_data/test_data_testing_update_wufi.xlsx
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Updating and rollback tools | ||
In this guide it is shown how a bulk update and import of tools and digital applications can be done using csv/excel-files. First a up-to-date excel file is needed, which holds the german and english data of all tools of the database. This file can be exported from the database using the django custom management command `data_export`: | ||
|
||
1. Open a terminal in the root of the project repository. Ensure that the app is running (in this guide the development mode is used). Switch into the shell of the `webcentral` docker container: | ||
``` | ||
./run webcentral_shell | ||
``` | ||
And move into the `src/` directory: | ||
``` | ||
cd src/ | ||
``` | ||
2. Export a file `tools_latest_dump.xlsx`: | ||
``` | ||
python manage.py data_export tools_latest_dump.xlsx | ||
``` | ||
When using the development-mode the file will be available in `webcentral/src/`-folder. | ||
```{note} | ||
If the production-mode was used to export the excel-file, it has to be copied out of the docker container using the docker cp-command from a terminal within the host-system | ||
``` | ||
3. Update the content of the excel-file. | ||
4. Import the excel file using the `data_import`-command: | ||
``` | ||
python manage.py data_import tools_over tools_latest_dump.xlsx | ||
``` | ||
When updating a tool or application creates a new state of the tool in the database a `History` object is created. | ||
In that object the old state of the tool is saved as a stringified JSON object. When a rollback needs to be done, the following steps can be taken: | ||
5. Login into the admin panel. The credentials can be fund in the `.env`-file. | ||
6. Find the `History`-tab on the left side of the admin panel inside the `tools_over`-menu. | ||
![Image of the tools_over tab](../img/tools_over_tab.png) | ||
Click on the history-element to be redirected to the history object listing page. There all history objects are shown, whereby each object is named after the tool or digtal application its state it is saving and the timestamp at which the update for the tool was done. When clicking on one of the history object a details page should open, which should look like the following: | ||
![Image of the tools_over tab](../img/details_tools_comparison.png) | ||
On the left side the current state of the tool `BESMod` is shown. On the right side the state is show to which the tool potentially could be rollbacked. The lines with the yellow background show, where attributes differ between the current state and the rollback state. To rollback the tool-state the user needs to go back to the history listing page and select the tool states, which should be rolled back: | ||
![Image of the tools_over tab](../img/select_rollback.png) | ||
After selecting the tools, which should rollback, select from the actions dropdown menu `Rollback selected change` and press apply. | ||
The history object should then disappear and the state of the selected tools should be rollbacked. |
2 changes: 2 additions & 0 deletions
2
webcentral/doc/06_sphinx/source/dev/custom_tags_and_template_tags.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Custom tags and template tags | ||
Build-in tags and template tags are decsribed in the [django documentation](https://docs.djangoproject.com/en/5.1/ref/templates/builtins/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Export data | ||
In the following sections it is described how to export structured data for a specific `django` app from the database into spreadsheet files. Thereby the data from the database is exported in files with the tabular structure present in `webcentral/doc/01_data/`. Each of the subsequent folders corespond to a `django` app whereby the different `django` apps are present in the folder `webcentral/src/`. | ||
This approach can be helpful, when data was imported into the database in several ways (via admin-panel, via spreadsheet files etc.) and a central data source is needed for future imports. | ||
|
||
## Structure of the source code | ||
The `data_export` function can be called from the `django` `manage.py` management script. The general structure of the custom management command is written out below: | ||
```bash | ||
python manage.py data_export app-name spreadsheet-filename.xlsx | ||
``` | ||
This command starts the `data_export` for one of the `django` apps inside the `webcentral/src/` folder with the name `app-name` and exports a spreadsheet file `spreadsheet-filename.xlsx` into the `webcentral/src/` folder. | ||
```{note} | ||
The spreadsheet file will only be visible on the host system when using the development mode of the `EWB Wissensplattform`. If you are using the production mode of the application you need to copy the created .xlsx file manually to the host filesystem. | ||
``` | ||
```{note} | ||
It can happen, that it is not possible to open the spreadsheet on the host-system because of insuficient rights. If on a linux-system you can use the `chown` utility to change the file owner to the current OS-user. | ||
``` | ||
## Code structure | ||
Similar to the the `data_import`-structure, a script `data_export.py` inside the folder `webcentral/src/common/management/commands/` is needed to introduce a custom management command `data_export`. It defines a class `CustomCommand`, which inherits from the `BaseCommand` `django` class. In the `CustomCommand` two methods need to be implemented: The `add_arguments()`- and the `handle()`-method, whereby the `add_arguments()` is used to add argument-structure to the command and the `handle()`-method is used to add functionality. | ||
The `handle()`-method then searches the installed `django`-app for the given app in the first argument and loads the `data_export.py`-module inside that app-directory. Inside the app specific `data_export.py`-module a class `DataExport` is definied, which is implemented differently for each app based on the structure of the apps models and the corresponding spreadsheet file. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import importlib | ||
|
||
from django.core.management.base import BaseCommand, CommandError | ||
from django.conf import settings | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Exports Data as a Excel sheet from specified App" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("type_of_data", nargs="+", type=str) | ||
parser.add_argument("filename", nargs="+", type=str) | ||
|
||
def handle(self, *args, **options): | ||
""" """ | ||
|
||
filename = options["filename"][0] | ||
|
||
type_of_data = options["type_of_data"][0] | ||
data_import_module = self._checkIfInInstalledApps(type_of_data) | ||
appDataExportObj = data_import_module.DataExport(filename) | ||
appDataExportObj.exportToXlsx() | ||
|
||
def _checkIfInInstalledApps(self, type_of_data): | ||
"""Check if user given argument `type_of_data` matches | ||
one of the installed apps. If it does, check if a `data_export`-module | ||
is present in that app. | ||
""" | ||
installed_django_apps = settings.INSTALLED_APPS | ||
app_names = [app.split(".")[0] for app in installed_django_apps] | ||
if type_of_data in app_names: | ||
if ( | ||
importlib.util.find_spec(type_of_data + ".data_export") | ||
is not None | ||
): | ||
return importlib.import_module(type_of_data + ".data_export") | ||
raise CommandError( | ||
"""specified type_of_data has no corresponding app or has no | ||
data_export.py in the app.""" | ||
) |
Oops, something went wrong.