From 16b4dda0f1d2df3a280b6507e12fe381ba0e8e74 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 25 Feb 2016 15:53:36 +0100 Subject: * added user accounts with calendar preferences --- app/python/rcal/model.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/python/rcal/model.py b/app/python/rcal/model.py index 94e426f..705fba2 100644 --- a/app/python/rcal/model.py +++ b/app/python/rcal/model.py @@ -1,5 +1,5 @@ # pylint: disable=too-few-public-methods, invalid-name -from sqlalchemy import Column, ForeignKey +from sqlalchemy import Column, ForeignKey, Table from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship from sqlalchemy.types import (TIMESTAMP, Boolean, DateTime, Integer, String, @@ -8,6 +8,7 @@ from sqlalchemy.types import (TIMESTAMP, Boolean, DateTime, Integer, String, from dateutil.tz import tzutc +# pylint: disable=abstract-method, unused-argument class UTCDateTime(TypeDecorator): impl = DateTime @@ -119,4 +120,26 @@ class Category(BASE): session.add(category) return category -__all__ = ('Calendar', 'Entry', 'Category') + +user_selections = Table( + 'user_selections', BASE.metadata, + Column('_user', Integer, + ForeignKey('users.id', onupdate='CASCADE', ondelete='CASCADE')), + Column('_calendar', String(255), + ForeignKey('calendars.uid', onupdate='CASCADE', ondelete='CASCADE')) +) + + +class User(BASE): + __tablename__ = 'users' + + id = Column(Integer, primary_key=True) + login = Column(String(255), unique=True, index=True) + password = Column(String(255)) + is_admin = Column(Boolean) + last_login = Column(UTCDateTime) + + calendars = relationship('Calendar', + secondary=user_selections) + +__all__ = ('Calendar', 'Entry', 'Category', 'User') -- cgit v1.2.3