mirror of
https://github.com/lucaspalomodevelop/eventcally.git
synced 2026-03-13 00:07:22 +00:00
26 lines
784 B
Python
26 lines
784 B
Python
from project import db
|
|
from project.models import EventOrganizer, EventPlace, Location
|
|
from sqlalchemy import and_
|
|
from sqlalchemy.sql import func
|
|
|
|
|
|
def upsert_event_organizer(admin_unit_id, name):
|
|
result = EventOrganizer.query.filter(
|
|
and_(EventOrganizer.name == name, EventOrganizer.admin_unit_id == admin_unit_id)
|
|
).first()
|
|
if result is None:
|
|
result = EventOrganizer(name=name, admin_unit_id=admin_unit_id)
|
|
result.location = Location()
|
|
db.session.add(result)
|
|
|
|
return result
|
|
|
|
|
|
def get_event_places(organizer_id):
|
|
organizer = EventOrganizer.query.get(organizer_id)
|
|
return (
|
|
EventPlace.query.filter(EventPlace.admin_unit_id == organizer.admin_unit_id)
|
|
.order_by(func.lower(EventPlace.name))
|
|
.all()
|
|
)
|