Use the event UUID as the event identifier in URLs

This commit is contained in:
Gergely Polonkai 2018-07-09 12:11:51 +02:00
parent c7457f6ed1
commit 89605538c2
2 changed files with 11 additions and 8 deletions

View File

@ -20,9 +20,10 @@
from datetime import datetime from datetime import datetime
import os import os
from flask import Flask, current_app, redirect, render_template, request, url_for from flask import Flask, abort, current_app, redirect, render_template, request, url_for
from flask_babelex import Babel, get_locale as babel_get_locale from flask_babelex import Babel, get_locale as babel_get_locale
from flask_security import SQLAlchemyUserDatastore, current_user, login_required from flask_security import SQLAlchemyUserDatastore, current_user, login_required
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
def get_locale(): def get_locale():
@ -234,14 +235,19 @@ class CalendarSocialApp(Flask):
return render_template('user-settings.html', form=form) return render_template('user-settings.html', form=form)
@staticmethod @staticmethod
@route('/event/<int:event_id>') @route('/event/<string:event_uuid>')
def event_details(event_id): def event_details(event_uuid):
"""View to display event details """View to display event details
""" """
from .models import Event from .models import Event
event = Event.query.get_or_404(event_id) try:
event = Event.query.filter(Event.event_uuid == event_uuid).one()
except NoResultFound:
abort(404)
except MultipleResultsFound:
abort(500)
return render_template('event-details.html', event=event) return render_template('event-details.html', event=event)
@ -251,9 +257,6 @@ class CalendarSocialApp(Flask):
"""View to display profile details """View to display profile details
""" """
from flask import abort
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
from .models import Profile, User from .models import Profile, User
profile = current_user.profile profile = current_user.profile

View File

@ -121,7 +121,7 @@
<td class="{% if day.month != calendar.timestamp.month %} other-month{% endif %}{% if day.date() == now.date() %} today{% endif %}"> <td class="{% if day.month != calendar.timestamp.month %} other-month{% endif %}{% if day.date() == now.date() %} today{% endif %}">
<span class="day-num">{{ day.day }}</span> <span class="day-num">{{ day.day }}</span>
{% for event in calendar.day_events(day, user=current_user) %} {% for event in calendar.day_events(day, user=current_user) %}
<a href="{{ url_for('event_details', event_id=event.id) }}" class="event"> <a href="{{ url_for('event_details', event_uuid=event.event_uuid) }}" class="event">
{{ event.start_time_for_user(current_user).strftime('%H:%M') }}{{ event.end_time_for_user(current_user).strftime('%H:%M') }} {{ event.start_time_for_user(current_user).strftime('%H:%M') }}{{ event.end_time_for_user(current_user).strftime('%H:%M') }}
{{ event.title }} {{ event.title }}
</a> </a>