übernahme rescuer to finder
This commit is contained in:
parent
3a3bcea588
commit
5a5f7dae9e
5 changed files with 173 additions and 1 deletions
|
@ -25,8 +25,8 @@ class BirdAddForm(forms.ModelForm):
|
||||||
"place",
|
"place",
|
||||||
"find_circumstances",
|
"find_circumstances",
|
||||||
"diagnostic_finding",
|
"diagnostic_finding",
|
||||||
"comment",
|
|
||||||
"finder",
|
"finder",
|
||||||
|
"comment",
|
||||||
]
|
]
|
||||||
labels = {
|
labels = {
|
||||||
"bird_identifier": _("Kennung"),
|
"bird_identifier": _("Kennung"),
|
||||||
|
@ -57,6 +57,7 @@ class BirdEditForm(forms.ModelForm):
|
||||||
"sent_to",
|
"sent_to",
|
||||||
"find_circumstances",
|
"find_circumstances",
|
||||||
"diagnostic_finding",
|
"diagnostic_finding",
|
||||||
|
"finder",
|
||||||
"comment",
|
"comment",
|
||||||
]
|
]
|
||||||
labels = {
|
labels = {
|
||||||
|
@ -69,5 +70,6 @@ class BirdEditForm(forms.ModelForm):
|
||||||
"sent_to": _("Übermittelt nach"),
|
"sent_to": _("Übermittelt nach"),
|
||||||
"find_circumstances": _("Fundumstände"),
|
"find_circumstances": _("Fundumstände"),
|
||||||
"diagnostic_finding": _("Diagnose bei Fund"),
|
"diagnostic_finding": _("Diagnose bei Fund"),
|
||||||
|
"finder": _("Finder"),
|
||||||
"comment": _("Bermerkung"),
|
"comment": _("Bermerkung"),
|
||||||
}
|
}
|
||||||
|
|
18
app/bird/migrations/0002_alter_fallenbird_comment.py
Normal file
18
app/bird/migrations/0002_alter_fallenbird_comment.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.2.6 on 2023-10-10 06:34
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('bird', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='fallenbird',
|
||||||
|
name='comment',
|
||||||
|
field=models.TextField(blank=True, null=True, verbose_name='Bemerkung'),
|
||||||
|
),
|
||||||
|
]
|
72
app/rescuer_to_finder.py
Normal file
72
app/rescuer_to_finder.py
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
# assign environment variable DB_HOST to variable host
|
||||||
|
# assign environment variable DB_NAME to variable database
|
||||||
|
# assign environment variable DB_USER to variable db_user
|
||||||
|
# assign environment variable DB_PASSWORD to variable db_password
|
||||||
|
# assign environment variable DB_PORT to variable db_port
|
||||||
|
|
||||||
|
|
||||||
|
# establish connection to database
|
||||||
|
import os
|
||||||
|
import psycopg2
|
||||||
|
import psycopg2.extras
|
||||||
|
import psycopg2.extensions
|
||||||
|
|
||||||
|
host = os.environ['DB_HOST']
|
||||||
|
database = os.environ['DB_NAME']
|
||||||
|
user = os.environ['DB_USER']
|
||||||
|
password = os.environ['DB_PASSWORD']
|
||||||
|
port = os.environ['DB_PORT']
|
||||||
|
|
||||||
|
|
||||||
|
conn = psycopg2.connect(host=host, database=database, user=user, password=password, port=port)
|
||||||
|
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
||||||
|
cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||||
|
|
||||||
|
# check if column finder exists in table bird_fallenbird
|
||||||
|
cur.execute("SELECT column_name FROM information_schema.columns WHERE table_name = 'bird_fallenbird' AND column_name = 'finder'")
|
||||||
|
|
||||||
|
# if column finder does not exist in table bird_fallenbird, add column finder to table bird_fallenbird
|
||||||
|
if not cur.fetchone():
|
||||||
|
cur.execute("alter table bird_fallenbird add column finder text")
|
||||||
|
|
||||||
|
# query the table rescuer_rescuer and write the results to a variable
|
||||||
|
cur.execute("SELECT * FROM rescuer_rescuer")
|
||||||
|
rescuer_rescuer = cur.fetchall()
|
||||||
|
|
||||||
|
# query the table bird_fallenbird with its columns id and rescuer_id and write the results to a variable
|
||||||
|
cur.execute("SELECT id, rescuer_id FROM bird_fallenbird")
|
||||||
|
bird_fallenbird = cur.fetchall()
|
||||||
|
|
||||||
|
# iterate over the results of the query bird_fallenbird
|
||||||
|
# for each row, iterate over the results of the query rescuer_rescuer
|
||||||
|
# if the rescuer_id of the bird_fallenbird row matches the id of the rescuer_rescuer row, update the bird_fallenbird row finder with all the data of the rescuer_rescuer
|
||||||
|
# all rows of rescuer_rescuer should be inserted into the column finder of bird_fallenbird with the same rescuer_id
|
||||||
|
for row in bird_fallenbird:
|
||||||
|
for rescuer in rescuer_rescuer:
|
||||||
|
if row['rescuer_id'] == rescuer['id']:
|
||||||
|
# the data should be in the format column_name: column_value
|
||||||
|
finder = ''
|
||||||
|
for key, value in rescuer.items():
|
||||||
|
# exclude the id column
|
||||||
|
if key != 'id':
|
||||||
|
if key != 'user_id':
|
||||||
|
if value != '-':
|
||||||
|
if key == 'first_name':
|
||||||
|
key = 'Vorname'
|
||||||
|
elif key == 'last_name':
|
||||||
|
key = 'Nachname'
|
||||||
|
elif key == 'phone':
|
||||||
|
key = 'Telefonnummer'
|
||||||
|
elif key == 'street':
|
||||||
|
key = 'Straße'
|
||||||
|
elif key == 'street_number':
|
||||||
|
key = 'Hausnummer'
|
||||||
|
elif key == 'city':
|
||||||
|
key = 'Stadt'
|
||||||
|
elif key == 'zip_code':
|
||||||
|
key = 'PLZ'
|
||||||
|
finder += key + ': ' + str(value) + '\n'
|
||||||
|
finder = finder[:-2]
|
||||||
|
cur.execute("UPDATE bird_fallenbird SET finder = %s WHERE id = %s", (finder, row['id']))
|
||||||
|
|
||||||
|
|
8
bin/rescuer_to_finder
Normal file
8
bin/rescuer_to_finder
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/bash
|
||||||
|
echo "Copying rescuer_to_finder.py to django_fbf_web_1"
|
||||||
|
docker cp ./scripts/rescuer_to_finder.py django_fbf_web_1:/app/rescuer_to_finder.py
|
||||||
|
|
||||||
|
echo "Running rescuer_to_finder.py"
|
||||||
|
docker exec django_fbf_web_1 python3 /app/rescuer_to_finder.py
|
||||||
|
|
||||||
|
echo "Done"
|
72
bin/scripts/rescuer_to_finder.py
Normal file
72
bin/scripts/rescuer_to_finder.py
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
# assign environment variable DB_HOST to variable host
|
||||||
|
# assign environment variable DB_NAME to variable database
|
||||||
|
# assign environment variable DB_USER to variable db_user
|
||||||
|
# assign environment variable DB_PASSWORD to variable db_password
|
||||||
|
# assign environment variable DB_PORT to variable db_port
|
||||||
|
|
||||||
|
|
||||||
|
# establish connection to database
|
||||||
|
import os
|
||||||
|
import psycopg2
|
||||||
|
import psycopg2.extras
|
||||||
|
import psycopg2.extensions
|
||||||
|
|
||||||
|
host = os.environ['DB_HOST']
|
||||||
|
database = os.environ['DB_NAME']
|
||||||
|
user = os.environ['DB_USER']
|
||||||
|
password = os.environ['DB_PASSWORD']
|
||||||
|
port = os.environ['DB_PORT']
|
||||||
|
|
||||||
|
|
||||||
|
conn = psycopg2.connect(host=host, database=database, user=user, password=password, port=port)
|
||||||
|
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
||||||
|
cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||||
|
|
||||||
|
# check if column finder exists in table bird_fallenbird
|
||||||
|
cur.execute("SELECT column_name FROM information_schema.columns WHERE table_name = 'bird_fallenbird' AND column_name = 'finder'")
|
||||||
|
|
||||||
|
# if column finder does not exist in table bird_fallenbird, add column finder to table bird_fallenbird
|
||||||
|
if not cur.fetchone():
|
||||||
|
cur.execute("alter table bird_fallenbird add column finder text")
|
||||||
|
|
||||||
|
# query the table rescuer_rescuer and write the results to a variable
|
||||||
|
cur.execute("SELECT * FROM rescuer_rescuer")
|
||||||
|
rescuer_rescuer = cur.fetchall()
|
||||||
|
|
||||||
|
# query the table bird_fallenbird with its columns id and rescuer_id and write the results to a variable
|
||||||
|
cur.execute("SELECT id, rescuer_id FROM bird_fallenbird")
|
||||||
|
bird_fallenbird = cur.fetchall()
|
||||||
|
|
||||||
|
# iterate over the results of the query bird_fallenbird
|
||||||
|
# for each row, iterate over the results of the query rescuer_rescuer
|
||||||
|
# if the rescuer_id of the bird_fallenbird row matches the id of the rescuer_rescuer row, update the bird_fallenbird row finder with all the data of the rescuer_rescuer
|
||||||
|
# all rows of rescuer_rescuer should be inserted into the column finder of bird_fallenbird with the same rescuer_id
|
||||||
|
for row in bird_fallenbird:
|
||||||
|
for rescuer in rescuer_rescuer:
|
||||||
|
if row['rescuer_id'] == rescuer['id']:
|
||||||
|
# the data should be in the format column_name: column_value
|
||||||
|
finder = ''
|
||||||
|
for key, value in rescuer.items():
|
||||||
|
# exclude the id column
|
||||||
|
if key != 'id':
|
||||||
|
if key != 'user_id':
|
||||||
|
if value != '-':
|
||||||
|
if key == 'first_name':
|
||||||
|
key = 'Vorname'
|
||||||
|
elif key == 'last_name':
|
||||||
|
key = 'Nachname'
|
||||||
|
elif key == 'phone':
|
||||||
|
key = 'Telefonnummer'
|
||||||
|
elif key == 'street':
|
||||||
|
key = 'Straße'
|
||||||
|
elif key == 'street_number':
|
||||||
|
key = 'Hausnummer'
|
||||||
|
elif key == 'city':
|
||||||
|
key = 'Stadt'
|
||||||
|
elif key == 'zip_code':
|
||||||
|
key = 'PLZ'
|
||||||
|
finder += key + ': ' + str(value) + '\n'
|
||||||
|
finder = finder[:-2]
|
||||||
|
cur.execute("UPDATE bird_fallenbird SET finder = %s WHERE id = %s", (finder, row['id']))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue