Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chemicals #36

Merged
merged 20 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ ipython_config.py
__pypackages__/

# Environments
.env
*.env
.env.development.local
.env.test.local
.env.production.local
Expand Down
182 changes: 11 additions & 171 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Install prerequisites:
or
- docker

Setting up the .env file:
Setting up the `.backend.env` file:

```python
# .env
Expand Down Expand Up @@ -38,192 +38,32 @@ conda activate flask

### React

In the frontend directory, run:
In the `frontend/` directory, run:

````bash
npm install
````

## Setting up the PostgreSQL Database

### Docker
# Running the ELN instance

### Backend
````bash
docker compose -d --build
docker compose up -d --build
````

### Native

In the terminal (backend/), initialize a postgres database by:
or with a respective .env file:
````bash
initdb -D database
docker compose --env-file .backend.env up -d --build
````

start the server modus/instance of postgres

````bash
pg_ctl -D database -l logfile start

#waiting for server to start.... done
#server started
````

create a non-superuser:

````bash
createuser --encrypted --pwprompt admin
# asks for name and password
````

using this superuser, create inner database inside the base database

````bash
createdb --owner=admin flask_database
````

### Populating the Database

Migrations to the database need to be applied by:
```python
python3 manage.py makemigrations
python3 manage.py migrate
```
If you want to add entries to the database yourself, you need to create a superuser first:
```python
python3 manage.py createsuperuser
```
Otherwise, you can populate the database with example data (including superuser (email:'admin@admin.com', password:'admin'))
```python
python3 manage.py loaddata init.json
```

### Backing up the Database

#### Via Django

````bash
python3 manage.py dumpdata --indent=2 > init.json
````

#### Using pg_dump

See: [pg_dump manual](https://www.postgresql.org/docs/12/app-pgdump.html)

````bash
pg_dump -h [host] -U [option] -W -F [file_type] [database_name] > [backup_name]
````

for example:

````bash
pg_dump -h localhost -U admin -W -F t userinterface_db > ./init.tar
````


### Stop running the Postgres Instance

#### Docker
#### Stop running the Postgres Instance

````bash
docker compose down
````
### Frontend

#### Native
In `frontend/`, run:

monitor whether a postgres instance/server is running or not
````bash
ps aux | grep postgres
npm start
````
if no instance is running, you will see only one line as the answer to your query - which is from your grep search,
ending with: grep --color=auto postgres
(ignore this line)

e.g. the output of `ps aux | grep postgres` was:
````bash
# username 2673 0.0 0.0 14760 512 pts/11 S+ 07:34 0:00 grep --color=auto postgres
# username 30550 0.0 0.0 179144 18996 ? S Jun13 0:01 /home/username/miniconda3/envs/django/bin/postgres -D mylocal_db
# username 30552 0.0 0.0 179276 4756 ? Ss Jun13 0:00 postgres: checkpointer process
# username 30553 0.0 0.0 179144 5216 ? Ss Jun13 0:01 postgres: writer process
# username 30554 0.0 0.0 179144 8464 ? Ss Jun13 0:01 postgres: wal writer process
# username 30555 0.0 0.0 179700 5792 ? Ss Jun13 0:01 postgres: autovacuum launcher process
# username 30556 0.0 0.0 34228 3416 ? Ss Jun13 0:03 postgres: stats collector process
````

if an instance of postgresql server is running, then several processes are running
you can kill the server by the first number of the leading line!

````bash
kill <number>
````


# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
97 changes: 97 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
## Setting up the PostgreSQL Database

### Native

In the terminal (backend/), initialize a postgres database by:
````bash
initdb -D database
````

start the server modus/instance of postgres

````bash
pg_ctl -D database -l logfile start

#waiting for server to start.... done
#server started
````

create a non-superuser:

````bash
createuser --encrypted --pwprompt admin
# asks for name and password
````

using this superuser, create inner database inside the base database

````bash
createdb --owner=admin flask_database
````

### Populating the Database

Migrations to the database need to be applied by:
```python
python3 manage.py makemigrations
python3 manage.py migrate
```
If you want to add entries to the database yourself, you need to create a superuser first:
```python
python3 manage.py createsuperuser
```
Otherwise, you can populate the database with example data (including superuser (email:'admin@admin.com', password:'admin'))
```python
python3 manage.py loaddata init.json
```

### Backing up the Database

#### Via Django

````bash
python3 manage.py dumpdata --indent=2 > init.json
````

#### Using pg_dump

See: [pg_dump manual](https://www.postgresql.org/docs/12/app-pgdump.html)

````bash
pg_dump -h [host] -U [option] -W -F [file_type] [database_name] > [backup_name]
````

for example:

````bash
pg_dump -h localhost -U admin -W -F t userinterface_db > ./init.tar
````


### Stop running the Postgres Instance

monitor whether a postgres instance/server is running or not
````bash
ps aux | grep postgres
````
if no instance is running, you will see only one line as the answer to your query - which is from your grep search,
ending with: grep --color=auto postgres
(ignore this line)

e.g. the output of `ps aux | grep postgres` was:
````bash
# username 2673 0.0 0.0 14760 512 pts/11 S+ 07:34 0:00 grep --color=auto postgres
# username 30550 0.0 0.0 179144 18996 ? S Jun13 0:01 /home/username/miniconda3/envs/django/bin/postgres -D mylocal_db
# username 30552 0.0 0.0 179276 4756 ? Ss Jun13 0:00 postgres: checkpointer process
# username 30553 0.0 0.0 179144 5216 ? Ss Jun13 0:01 postgres: writer process
# username 30554 0.0 0.0 179144 8464 ? Ss Jun13 0:01 postgres: wal writer process
# username 30555 0.0 0.0 179700 5792 ? Ss Jun13 0:01 postgres: autovacuum launcher process
# username 30556 0.0 0.0 34228 3416 ? Ss Jun13 0:03 postgres: stats collector process
````

if an instance of postgresql server is running, then several processes are running
you can kill the server by the first number of the leading line!

````bash
kill <number>
````
6 changes: 4 additions & 2 deletions backend/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"""

from pathlib import Path
from decouple import config, Csv
from decouple import config, Csv # Config, RepositoryEnv, Csv #
from datetime import timedelta

# config = Config(RepositoryEnv(Path(Path(__file__).resolve().parent.parent.parent, ".backend.env")))

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand Down Expand Up @@ -46,7 +48,7 @@
'rest_framework_simplejwt.token_blacklist',
'corsheaders',

'phonenumber_field',
# 'phonenumber_field',
# 'barcode_field'
# 'django_rdkit',

Expand Down
2 changes: 1 addition & 1 deletion backend/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
router.register(r'building', BuildingViewSet, basename='buildings')
router.register(r'unit', UnitViewSet, basename='units')
router.register(r'substance', SubstanceViewSet, basename='substances')
router.register(r'component', ComponentViewSet, basename='containers')
router.register(r'component', ComponentViewSet, basename='components')
router.register(r'compound', CompoundViewSet, basename='compounds')
router.register(r'container', ContainerViewSet, basename='containers')

Expand Down
2 changes: 1 addition & 1 deletion backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def list(self, request):
def create(self, request):
serializer = self.serializer_class(data=request.data)
if serializer.is_valid():
# todo: problems with create user?
# todo: problems with create_user?!
self.model.objects.create(**serializer.validated_data)
return Response(serializer.validated_data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Expand Down
Empty file removed backend/barcode_field/__init__.py
Empty file.
3 changes: 0 additions & 3 deletions backend/barcode_field/admin.py

This file was deleted.

6 changes: 0 additions & 6 deletions backend/barcode_field/apps.py

This file was deleted.

16 changes: 0 additions & 16 deletions backend/barcode_field/core.py

This file was deleted.

Loading
Loading