Skip to content

Commit 727cea2

Browse files
authored
Merge pull request #18 from cmu-delphi/docs_update
Docs update
2 parents cc040f8 + 65cc0fa commit 727cea2

File tree

9 files changed

+47
-7
lines changed

9 files changed

+47
-7
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,50 @@ Open `http://localhost:8000` to view it in the browser
7979

8080
## [Django admin](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/) web interface (user should be `is_staff` or `is_superuser`)
8181
`http://localhost:8000/admin`
82+
83+
84+
## Import data from admin interface
85+
86+
For data import used [django-import-export](https://django-import-export.readthedocs.io/en/latest/index.html) library
87+
88+
The code consists of Django resource classes that are used for importing and exporting CSV files using the Django Import-Export library:
89+
1. `SignalResource` - this resource class is used for importing `Signal` models:
90+
* Defines various fields such as `name`, `display_name`, `pathogen`, `signal_type`, and `source`.
91+
* Defines the `before_import_row` method, which is called before importing each row and allows for pre-processing of the data.
92+
* Includes methods like `is_url_in_domain` to check if a URL belongs to a specific domain, `fix_boolean_fields` to handle boolean fields, and `process_links` to process the links field.
93+
94+
2. `SignalBaseResource` - This resource class is used for updating already created `Signal` models `base` fields with base Signals.
95+
* Defines various fields such as `name`, `display_name`, `base`, and `source`.
96+
* Defines the `before_import_row` method, which is called before importing each row and allows for pre-processing of the data.
97+
* The `process_base` method is responsible for processing the `base` field by retrieving the corresponding `Signal` object based on the provided `name` and `source`.
98+
99+
3. `SourceSubdivisionResource` - this resource class is used for importing `SourceSubdivision` models
100+
* It defines fields such as `name`, `display_name`, `description`, `data_source`, and `links`.
101+
* It includes the `before_import_row` method for pre-processing each row before importing.
102+
* The `process_links` method is responsible for processing the `links` field by creating `Link` objects based on the provided URLs.
103+
* The `process_datasource` method processes the `data_source` field by creating or retrieving a `DataSource` object based on the provided name.
104+
105+
These resource classes provide a structured way to import CSV files. They define the fields, handle pre-processing of data, and interact with the corresponding models and related objects.
106+
107+
### Import data flow
108+
109+
To import data from a CSV file must meet the requirements:
110+
* CSV file should be properly formatted and contains all the required fields for importing, as specified by the resource classes (`SignalResource`, `SignalBaseResource`, `SourceSubdivisionResource`). The header row of the CSV file should match the field names defined in the resource classes.
111+
* It should not contain empty rows from the CSV file before importing. Empty rows may cause validation errors during the import process.
112+
* Colums should be saparateb by `","`
113+
114+
Othervice you will receive Errors during import process:
115+
![Import errors](./docs/image-3.png)
116+
117+
118+
1. Import `SourceSubdivision` instances with `SourceSubdivisionResource` - [http://localhost:8000/admin/datasources/sourcesubdivision/import/](http://localhost:8000/admin/datasources/sourcesubdivision/import/)
119+
![Import `SourceSubdivision` instances](./docs/image.png)
120+
![Confirm importing `SourceSubdivision` instances](./docs/image-1.png)
121+
122+
2. Import `Signal` instances with `SignalResource` - [http://localhost:8000/admin/signals/signal/import/](http://localhost:8000/admin/signals/signal/import/)
123+
![Import `Signal` instances](./docs/image-2.png)
124+
![Confirm importing `Signal` instances](./docs/image-4.png)
125+
126+
3. Import `Signal.base` fields with `SignalBaseResource` - [http://localhost:8000/admin/signals/signal/import/](http://localhost:8000/admin/signals/signal/import/)
127+
![Import `Signal.base` field](./docs/image-5.png)
128+
![Confirm importing `Signal.base` fields](./docs/image-6.png)

docs/image-1.png

171 KB
Loading

docs/image-2.png

77.7 KB
Loading

docs/image-3.png

140 KB
Loading

docs/image-4.png

127 KB
Loading

docs/image-5.png

77.7 KB
Loading

docs/image-6.png

111 KB
Loading

docs/image.png

54 KB
Loading

src/templates/index.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@
6161
<i class="bi bi-list toggle-sidebar-btn"></i>
6262
</div><!-- End Logo -->
6363

64-
<div class="search-bar">
65-
<form class="search-form d-flex align-items-center" method="POST" action="#">
66-
<input type="text" name="query" placeholder="Search" title="Enter search keyword">
67-
<button type="submit" title="Search"><i class="bi bi-search"></i></button>
68-
</form>
69-
</div><!-- End Search Bar -->
70-
7164
<nav class="header-nav ms-auto">
7265
<ul class="d-flex align-items-center">
7366
<li class="nav-item d-block d-lg-none">

0 commit comments

Comments
 (0)