Streamlined export_location to take the id instead of a string

This was quite the stupid bugger... it also involved changing a table in the database
projects
Domeniko Gentner 3 years ago
parent 698e1dee50
commit 8f6ec52750
  1. 6
      labertasche/blueprints/bp_comments.py
  2. 15
      labertasche/helper/__init__.py
  3. 2
      labertasche/models/t_comments.py

@ -146,7 +146,7 @@ def check_and_insert_new_comment():
print(e, file=stderr)
return make_response(jsonify(status="post-internal-server-error"), 400)
export_location(location)
export_location(t_comment.location_id)
return make_response(jsonify(status="post-success", comment_id=t_comment.comments_id), 200)
@ -164,7 +164,7 @@ def check_confirmation_link(email_hash):
setattr(comment, "is_published", True)
db.session.commit()
url = f"{settings.system['blog_url']}{location.location}#comment_{comment.comments_id}"
export_location(location.location)
export_location(location.id_location)
return redirect(url)
return redirect(f"{settings.system['blog_url']}?cnf=true")
@ -183,7 +183,7 @@ def check_deletion_link(email_hash):
query.delete()
db.session.commit()
url = f"{settings.system['blog_url']}?deleted=true"
export_location(location.location)
export_location(location.id_location)
return redirect(url)
return redirect(f"{settings.system['blog_url']}?cnf=true")

@ -132,16 +132,22 @@ def basic_login_required(f):
return wrapped_view
def export_location(location: str) -> bool:
def export_location(location_id: int) -> bool:
"""
Exports the comments for the location after the comment was accepted
:param location: relative url of the hugo page
:param location_id: The id of the store location to export
"""
try:
# flush before query
db.session.flush()
print(f"Location: {location_id}")
# Query
loc_query = db.session.query(TLocation).filter(TLocation.location == location).first()
loc_query = db.session.query(TLocation).filter(TLocation.id_location == location_id).first()
if loc_query:
print(f"has loc_query")
comments = db.session.query(TComments).filter(TComments.is_spam != True) \
.filter(TComments.is_published == True) \
.filter(TComments.location_id == loc_query.id_location) \
@ -151,6 +157,7 @@ def export_location(location: str) -> bool:
"comments": []
}
for comment in comments:
print(f"Data: {comment.comments_id}")
bundle['comments'].append(alchemy_query_to_dict(comment))
path_loc = re_match(".*(?=/)", loc_query.location)[0]
@ -163,6 +170,8 @@ def export_location(location: str) -> bool:
folder.mkdir(parents=True, exist_ok=True)
with out.open('w') as fp:
json.dump(bundle, fp)
print("Bundle here ---------- \n")
print(bundle)
return True

@ -19,7 +19,7 @@ class TComments(db.Model):
comments_id = db.Column(db.Integer, primary_key=True)
# foreign keys
location_id = db.Column(db.Text, ForeignKey('t_location.id_location'), nullable=False)
location_id = db.Column(db.Integer, ForeignKey('t_location.id_location'), nullable=False)
# data
email = db.Column(db.Text, nullable=False)

Loading…
Cancel
Save