Skip to content

Commit

Permalink
refactor: do sqlalchemy queries from model classes instead of model i…
Browse files Browse the repository at this point in the history
…nstances
  • Loading branch information
azmeuk committed Feb 21, 2024
1 parent 6250cfc commit 522e619
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions web/b3desk/endpoints/meeting_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def add_meeting_files(meeting, owner):
if data["from"] == "URL":
return add_meeting_file_URL(data["value"], meeting.id, is_default)

# This is called by the JS after uploading a file on the 'add_dropzone_files'
# TODO: do everything in one single request?
if data["from"] == "dropzone":
return add_meeting_file_dropzone(
secure_filename(data["value"]), meeting.id, is_default
Expand Down Expand Up @@ -226,8 +228,7 @@ def set_meeting_default_file(meeting, owner):
if actual_default_file:
actual_default_file.is_default = False

meeting_file = MeetingFiles()
meeting_file = meeting_file.query.get(data["id"])
meeting_file = MeetingFiles.query.get(data["id"])
meeting_file.is_default = True

if actual_default_file:
Expand Down Expand Up @@ -487,10 +488,8 @@ def delete_meeting_file():
user = get_current_user()
data = request.get_json()
meeting_file_id = data["id"]
meeting_file = MeetingFiles()
meeting_file = meeting_file.query.get(meeting_file_id)
meeting = Meeting()
cur_meeting = meeting.query.get(meeting_file.meeting_id)
meeting_file = MeetingFiles.query.get(meeting_file_id)
cur_meeting = Meeting.query.get(meeting_file.meeting_id)

if cur_meeting.user_id != user.id:
return jsonify(
Expand All @@ -501,7 +500,7 @@ def delete_meeting_file():
db.session.commit()
new_default_id = None
if meeting_file.is_default:
cur_meeting = meeting.query.get(meeting_file.meeting_id)
cur_meeting = Meeting.query.get(meeting_file.meeting_id)
if len(cur_meeting.files) > 0:
cur_meeting.files[0].is_default = True
new_default_id = cur_meeting.files[0].id
Expand Down

0 comments on commit 522e619

Please sign in to comment.