Merge branch 'guntherweissenbaeck/issue62' of github.com:guntherweissenbaeck/django_fbf into guntherweissenbaeck/issue62

This commit is contained in:
gw3000 2023-10-11 17:54:56 +02:00
commit 93d12059f5
4 changed files with 110 additions and 1 deletions

View file

@ -25,8 +25,8 @@ class BirdAddForm(forms.ModelForm):
"place",
"find_circumstances",
"diagnostic_finding",
"comment",
"finder",
"comment",
]
labels = {
"bird_identifier": _("Kennung"),
@ -57,6 +57,7 @@ class BirdEditForm(forms.ModelForm):
"sent_to",
"find_circumstances",
"diagnostic_finding",
"finder",
"comment",
]
labels = {
@ -69,5 +70,6 @@ class BirdEditForm(forms.ModelForm):
"sent_to": _("Übermittelt nach"),
"find_circumstances": _("Fundumstände"),
"diagnostic_finding": _("Diagnose bei Fund"),
"finder": _("Finder"),
"comment": _("Bermerkung"),
}

View 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'),
),
]

17
bin/rescuer_to_finder Normal file
View file

@ -0,0 +1,17 @@
#!/bin/bash
echo "-------------------"
echo "Copying rescuer_to_finder.py to django_fbf_web_1"
echo "-------------------"
docker cp ./scripts/rescuer_to_finder.py django_fbf_web_1:/app/rescuer_to_finder.py
echo "-------------------"
echo "Running rescuer_to_finder.py"
echo "-------------------"
docker exec django_fbf_web_1 python3 /app/rescuer_to_finder.py
echo "Removing rescuer_to_finder.py from django_fbf_web_1"
echo "-------------------"
docker exec django_fbf_web_1 rm /app/rescuer_to_finder.py
echo "Done"
echo "-------------------"

View 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']))