Skip to content

Commit

Permalink
Make herald page work when a venue has no more content
Browse files Browse the repository at this point in the history
  • Loading branch information
marksteward committed May 27, 2024
1 parent 5902697 commit 8002d39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
27 changes: 16 additions & 11 deletions apps/schedule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,17 @@ class HeraldStageForm(Form):
@schedule.route("/herald/<string:venue_name>", methods=["GET", "POST"])
@v_user_required
def herald_venue(venue_name):
def herald_message(message, proposal):
def herald_message(message, proposal=None):
app.logger.info(f"Creating new message {message}")
end = proposal.scheduled_time + timedelta(minutes=proposal.scheduled_duration)
if proposal is None:
end = datetime.now() + timedelta(days=1)
else:
end = proposal.scheduled_time + timedelta(minutes=proposal.scheduled_duration)
return AdminMessage(
f"[{venue_name}] -- {message}", current_user, end=end, topic="heralds"
)

now, next = (
proposals = (
Proposal.query.join(Venue, Venue.id == Proposal.scheduled_venue_id)
.filter(
Venue.name == venue_name,
Expand All @@ -480,12 +483,13 @@ def herald_message(message, proposal):
.limit(2)
.all()
)
now, next = (proposals + [None, None])[:2]

form = HeraldStageForm()

if form.validate_on_submit():
if form.now.update.data:
if form.now.talk_id.data != now.id:
if now is None or form.now.talk_id.data != now.id:
flash("'now' changed, please refresh")
return redirect(url_for(".herald_venue", venue_name=venue_name))

Expand All @@ -494,7 +498,7 @@ def herald_message(message, proposal):
now.may_record = form.now.may_record.data

elif form.next.update.data:
if form.next.talk_id.data != next.id:
if next is None or form.next.talk_id.data != next.id:
flash("'next' changed, please refresh")
return redirect(url_for(".herald_venue", venue_name=venue_name))
change = "may" if form.next.may_record else "may not"
Expand All @@ -508,20 +512,21 @@ def herald_message(message, proposal):
msg = herald_message(f"{next.user.name}, arrived.", next)

elif form.send_message.data:
# in lieu of a better time set TTL to end of next talk
msg = herald_message(form.message.data, next)
msg = herald_message(form.message.data)

db.session.add(msg)
db.session.commit()
return redirect(url_for(".herald_venue", venue_name=venue_name))

messages = AdminMessage.get_all_for_topic("heralds")

form.now.talk_id.data = now.id
form.now.may_record.data = now.may_record
if now:
form.now.talk_id.data = now.id
form.now.may_record.data = now.may_record

form.next.talk_id.data = next.id
form.next.may_record.data = next.may_record
if next:
form.next.talk_id.data = next.id
form.next.may_record.data = next.may_record

return render_template(
"schedule/herald/venue.html",
Expand Down
4 changes: 4 additions & 0 deletions templates/schedule/herald/venue.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ <h1>Now &amp; next on: {{ venue_name }}</h1>

<form method="post">
{{ form.hidden_tag() }}
{% if now %}
<h2>Now</h2>
<dl class="dl-horizontal">
<dt>Title</dt>
Expand All @@ -26,7 +27,9 @@ <h2>Now</h2>
<p>&nbsp;</p>
{{ render_field(form.now.speaker_here, horizontal=8) }}
<p>&nbsp;</p>
{% endif %}

{% if next %}
<h2>Next</h2>
<dl class="dl-horizontal">
<dt>Title</dt>
Expand All @@ -46,6 +49,7 @@ <h2>Next</h2>
<p>&nbsp;</p>
{{ render_field(form.next.speaker_here, horizontal=8) }}
<p>&nbsp;</p>
{% endif %}

<h2>Send message to the Greenroom</h2>

Expand Down

0 comments on commit 8002d39

Please sign in to comment.