This repository was archived by the owner on Nov 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathsection.py
More file actions
98 lines (75 loc) · 2.45 KB
/
Copy pathsection.py
File metadata and controls
98 lines (75 loc) · 2.45 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import enum
from sqlalchemy import (
Column,
Enum,
Float,
Integer,
String,
ForeignKey,
)
from sqlalchemy.orm import relationship, backref
from .auth import CrudPermissions, P_READ, P_ADMIN_DISC
from . import DiscussionBoundBase
from .langstrings import LangString
from ..lib.sqla_types import URLString
import assembl.graphql.docstrings as docs
class SectionTypesEnum(enum.Enum):
HOMEPAGE = 'HOMEPAGE'
DEBATE = 'DEBATE'
SYNTHESES = 'SYNTHESES'
RESOURCES_CENTER = 'RESOURCES_CENTER'
SEMANTIC_ANALYSIS = 'SEMANTIC_ANALYSIS'
CUSTOM = 'CUSTOM'
ADMINISTRATION = 'ADMINISTRATION'
section_types = [t.value for t in SectionTypesEnum.__members__.values()]
class Section(DiscussionBoundBase):
__doc__ = docs.Section.__doc__
"""Assembl configurable sections."""
__tablename__ = "section"
type = Column(String(60), nullable=False)
id = Column(Integer, primary_key=True)
discussion_id = Column(
Integer,
ForeignKey(
'discussion.id',
ondelete='CASCADE',
onupdate='CASCADE',
),
nullable=False, index=True)
discussion = relationship(
"Discussion",
backref=backref(
'sections',
cascade="all, delete-orphan"),
)
title_id = Column(
Integer(), ForeignKey(LangString.id))
title = relationship(
LangString,
lazy="joined", single_parent=True,
primaryjoin=title_id == LangString.id,
backref=backref("section_from_title", lazy="dynamic"),
cascade="all, delete-orphan")
url = Column(URLString)
section_type = Column(
Enum(*section_types, name='section_types'),
nullable=False,
default=SectionTypesEnum.CUSTOM.value,
server_default=SectionTypesEnum.CUSTOM.value,
doc=docs.Section.section_type
)
order = Column(
Float, nullable=False, default=0.0, doc=docs.Section.order)
def get_discussion_id(self):
return self.discussion_id or self.discussion.id
@classmethod
def get_discussion_conditions(cls, discussion_id, alias_maker=None):
return (cls.discussion_id == discussion_id,)
__mapper_args__ = {
'polymorphic_identity': 'section',
'polymorphic_on': type,
'with_polymorphic': '*'
}
crud_permissions = CrudPermissions(
P_ADMIN_DISC, P_READ, P_ADMIN_DISC, P_ADMIN_DISC)
LangString.setup_ownership_load_event(Section, ['title'])