diff --git a/mo/web/org.py b/mo/web/org.py
index 7fd69de53780c9ac48ead9bfe7ac7ca22d064722..b702ba1821b64a647a3e489b4199453311a3a881 100644
--- a/mo/web/org.py
+++ b/mo/web/org.py
@@ -112,7 +112,7 @@ def org_place_edit(id: int):
# School record removed
mo.util.log(
type=db.LogType.place,
- what=g.user.user_id,
+ what=school.place_id,
details={'action': 'school-delete', 'school': db.row2dict(school)},
)
app.logger.info(f"Deleting school record for place {place.place_id}")
@@ -122,15 +122,15 @@ def org_place_edit(id: int):
schoolChanges = db.get_object_changes(school)
elif request.form.get('type') == 'school':
# School record created
- newSchool = db.School()
- newSchool.place_id = place.place_id
+ new_school = db.School()
+ new_school.place_id = place.place_id
mo.util.log(
type=db.LogType.place,
- what=g.user.user_id,
- details={'action': 'school-add', 'place_id': place.place_id},
+ what=new_school.place_id,
+ details={'action': 'school-add'},
)
app.logger.info(f"Creating new school for place {place.place_id}")
- db.get_session().add(newSchool)
+ db.get_session().add(new_school)
# Take org directly to the school edit to fill the data
msg = 'Záznam o škole vytvořen, vyplňte prosím všechna data'
redirectURL = url_for('org_place_edit', id=id)
@@ -139,7 +139,7 @@ def org_place_edit(id: int):
app.logger.info(f"Place {id} modified, changes: {changes}")
mo.util.log(
type=db.LogType.place,
- what=g.user.user_id,
+ what=id,
details={'action': 'edit', 'changes': changes},
)
db.get_session().commit()
@@ -253,8 +253,21 @@ def org_place_delete(id: int):
if place.type == db.PlaceType.school:
school = sess.query(db.School).get(place.place_id)
+ mo.util.log(
+ type=db.LogType.place,
+ what=school.place_id,
+ details={'action': 'school-delete', 'school': db.row2dict(school)},
+ )
+ app.logger.info(f"Deleting school record for place {id}")
db.get_session().delete(school)
+ mo.util.log(
+ type=db.LogType.place,
+ what=id,
+ details={'action': 'delete', 'place': db.row2dict(place)},
+ )
+ app.logger.info(f"Deleting place {id}")
+
parent = place.parent
db.get_session().delete(place)
db.get_session().commit()
@@ -286,12 +299,13 @@ def org_place_new_child(id: int):
form.populate_obj(new_place)
new_place.parent = parent_place.place_id
new_place.level = parent_place.level + 1
- db.get_session().add(new_place)
+ sess.add(new_place)
+ sess.flush()
app.logger.info(f"New place created: {db.row2dict(new_place)}")
mo.util.log(
type=db.LogType.place,
- what=g.user.user_id,
+ what=new_place.place_id,
details={'action': 'new', 'place': db.row2dict(new_place)},
)
db.get_session().commit()