Mailspring/examples/N1-Send-Availability/backend/models.py
Drew Regitsky 92820fc3d2 fix(examples): revamp/fix Send-Availability, change URL to live Heroku link
Summary:
Several fixes and updates the the Send Availability example package. Switches from
using `electron-safe-ipc` to using `protocol.RegisterStringProtocol` to communicate
with the child window. Changes the URLs in the package from localhost to our live
demo backend.

Test Plan: manual

Reviewers: bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D2271
2015-11-19 18:16:38 -08:00

79 lines
2.4 KiB
Python

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer, ForeignKey, \
DateTime, Text, Boolean
from sqlalchemy.orm import relationship, backref
from session import new_engine
Base = declarative_base()
def init_db():
# engine = new_engine(None)
# engine.execute("CREATE DATABASE IF NOT EXISTS sendavailability "
# "DEFAULT CHARACTER SET utf8mb4 "
# "DEFAULT COLLATE utf8mb4_general_ci;")
Base.metadata.create_all(new_engine())
class Event(Base):
"""
A single event awaiting scheduling. Once a time has been selected by the
user, an email will be sent and this entry deleted.
"""
__tablename__ = 'event'
id = Column(Integer, primary_key=True)
title = Column(String(255))
location = Column(Text())
description = Column(Text())
@property
def organizer(self):
return filter(lambda a: a.is_sender, self.attendees)[0]
class EventTime(Base):
"""
A time range option for a single event. An event can have many times - the
user will choose one to schedule the event. Time ranges are deleted when
the event is deleted.
"""
__tablename__ = 'eventtime'
id = Column(Integer, primary_key=True)
start = Column(DateTime())
end = Column(DateTime())
key = Column(String(255))
event_id = Column(Integer, ForeignKey('event.id'))
event = relationship('Event',
foreign_keys=[event_id],
backref=backref('times', lazy='dynamic'),
lazy='joined',
single_parent=True,
cascade="all, delete-orphan")
class Attendee(Base):
"""
An attendee for a single event. These are not stored normalized, because
they're short-lived and need to be reliably deleted when the event is
deleted.
"""
__tablename__ = 'attendee'
id = Column(Integer, primary_key=True)
name = Column(String(255))
email = Column(String(255))
is_sender = Column(Boolean())
event_id = Column(Integer, ForeignKey('event.id'))
event = relationship('Event',
foreign_keys=[event_id],
backref=backref('attendees', lazy='dynamic'),
lazy='joined',
single_parent=True,
cascade="all, delete-orphan")