69 lines
No EOL
2.4 KiB
Python
69 lines
No EOL
2.4 KiB
Python
"""
|
|
View saved events resource for the OpenEventDatabase.
|
|
"""
|
|
|
|
import os
|
|
import falcon
|
|
import jinja2
|
|
from oedb.utils.logging import logger
|
|
from oedb.utils.db import load_env_from_file
|
|
|
|
class DemoViewEventsResource:
|
|
"""
|
|
Resource for viewing saved events.
|
|
Handles the /demo/view-events endpoint.
|
|
"""
|
|
|
|
def __init__(self):
|
|
"""
|
|
Initialize the resource with a Jinja2 environment.
|
|
"""
|
|
# Set up Jinja2 environment
|
|
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
|
|
self.jinja_env = jinja2.Environment(
|
|
loader=jinja2.FileSystemLoader(template_dir),
|
|
autoescape=jinja2.select_autoescape(['html', 'xml'])
|
|
)
|
|
|
|
def on_get(self, req, resp):
|
|
"""
|
|
Handle GET requests to the /demo/view-events endpoint.
|
|
Returns an HTML page with a map showing events stored in localStorage.
|
|
|
|
Args:
|
|
req: The request object.
|
|
resp: The response object.
|
|
"""
|
|
logger.info("Processing GET request to /demo/view-events")
|
|
|
|
try:
|
|
# Set content type to HTML
|
|
resp.content_type = 'text/html'
|
|
|
|
# Load environment variables from .env file for OAuth2 configuration
|
|
load_env_from_file()
|
|
|
|
# Get OAuth2 configuration parameters
|
|
client_id = os.getenv("CLIENT_ID", "")
|
|
client_secret = os.getenv("CLIENT_SECRET", "")
|
|
client_redirect = os.getenv("CLIENT_REDIRECT", "")
|
|
|
|
# Load and render the template with the appropriate variables
|
|
template = self.jinja_env.get_template('view_events_new.html')
|
|
html = template.render(
|
|
client_id=client_id,
|
|
client_secret=client_secret,
|
|
client_redirect=client_redirect
|
|
)
|
|
|
|
# Set the response body and status
|
|
resp.text = html
|
|
resp.status = falcon.HTTP_200
|
|
logger.success("Successfully processed GET request to /demo/view-events")
|
|
except Exception as e:
|
|
logger.error(f"Error processing GET request to /demo/view-events: {e}")
|
|
resp.status = falcon.HTTP_500
|
|
resp.text = f"Error: {str(e)}"
|
|
|
|
# Create a global instance of DemoViewEventsResource
|
|
demo_view_events = DemoViewEventsResource() |