From 89605538c2247bab94560a3f38f3042c47dfd88f Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 9 Jul 2018 12:11:51 +0200 Subject: [PATCH] Use the event UUID as the event identifier in URLs --- calsocial/__init__.py | 17 ++++++++++------- calsocial/templates/month-view.html | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/calsocial/__init__.py b/calsocial/__init__.py index 631f5bd..220d290 100644 --- a/calsocial/__init__.py +++ b/calsocial/__init__.py @@ -20,9 +20,10 @@ from datetime import datetime 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_security import SQLAlchemyUserDatastore, current_user, login_required +from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound def get_locale(): @@ -234,14 +235,19 @@ class CalendarSocialApp(Flask): return render_template('user-settings.html', form=form) @staticmethod - @route('/event/') - def event_details(event_id): + @route('/event/') + def event_details(event_uuid): """View to display event details """ 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) @@ -251,9 +257,6 @@ class CalendarSocialApp(Flask): """View to display profile details """ - from flask import abort - from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound - from .models import Profile, User profile = current_user.profile diff --git a/calsocial/templates/month-view.html b/calsocial/templates/month-view.html index cf38bf0..ca5d75d 100644 --- a/calsocial/templates/month-view.html +++ b/calsocial/templates/month-view.html @@ -121,7 +121,7 @@ {{ day.day }} {% for event in calendar.day_events(day, user=current_user) %} - + {{ event.start_time_for_user(current_user).strftime('%H:%M') }}–{{ event.end_time_for_user(current_user).strftime('%H:%M') }} {{ event.title }}