1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
from sqlalchemy import create_engine, Table, Column, Text, String, Integer, DateTime, JSON, ForeignKey
from sqlalchemy.orm import relationship
import sqlalchemy.sql.functions as func
from sqlalchemy_utc import UtcDateTime, utcnow
from wtforms_alchemy import ModelForm
from app.sql.common import db, Base, Session
# from app.sql.models.page import Page
from app.settings import app_cfg
class Graph(Base):
"""Table for storing references to graphs"""
__tablename__ = 'graph'
id = Column(Integer, primary_key=True)
home_page_id = Column(Integer, nullable=True)
path = Column(String(64, convert_unicode=True), nullable=False)
title = Column(String(64, convert_unicode=True), nullable=False)
username = Column(String(32, convert_unicode=True), nullable=False)
description = Column(Text(convert_unicode=True), nullable=False)
settings = Column(JSON, default={}, nullable=True)
created_at = Column(UtcDateTime(), default=utcnow())
updated_at = Column(UtcDateTime(), onupdate=utcnow())
pages = relationship('Page', lazy='dynamic')
def toJSON(self):
return {
'id': self.id,
'home_page_id': self.home_page_id,
'path': self.path,
'title': self.title,
'username': self.username,
'description': self.description,
'settings': self.settings,
'created_at': self.created_at,
'updated_at': self.updated_at,
}
def toFullJSON(self):
data = self.toJSON()
data['pages'] = [ page.toLinkJSON() for page in self.pages ]
return data
class GraphForm(ModelForm):
class Meta:
model = Graph
exclude = ['settings', 'created_at', 'updated_at']
def get_session():
return Session()
|