示例#1
0
 def get_count_query(self):
     parent = self._get_parent_from_args()
     sel = db.select([db.func.count(Page.id)])
     if parent:
         sel = sel.where(Page.parent == parent)
     else:
         sel = sel.where(
             db.and_(
                 Page.parent == None,
                 db.inspect(Page).polymorphic_on
                 == db.inspect(self.model).polymorphic_identity,
             )
         )
     return db.session.execute(sel)
示例#2
0
文件: metadata.py 项目: ra2003/oy-cms
 def before_flush(self, session, is_modified):
     if self.should_auto_generate is None:
         self.should_auto_generate = True
     if not self.should_auto_generate:
         return
     cols = ["keywords", "meta_title", "meta_description"]
     state = db.inspect(self)
     for col in cols:
         state = db.inspect(self)
         if state.attrs[col].history.unchanged:
             continue
         func = getattr(self, f"__get_{col}__", None)
         if callable(func):
             setattr(self, col, func())
示例#3
0
 def is_valid_parent(cls, parent):
     model = db.inspect(parent).mapper.class_
     if not cls.should_allow_parents():
         return False
     elif cls.valid_parent_node_types is cls.ALL_NODE_TYPES:
         return True
     return model in cls.valid_parent_node_types
示例#4
0
 def is_valid_child(cls, child):
     model = db.inspect(child).mapper.class_
     if not cls.should_allow_children():
         return False
     elif cls.valid_child_node_types is cls.ALL_NODE_TYPES:
         return True
     return model in cls.valid_child_node_types
示例#5
0
 def _before_setting_parent(cls,
                            instance,
                            value,
                            oldvalue=None,
                            initiator=None):
     if not db.inspect(instance).mapper.class_.is_valid_parent(value):
         raise ValueError(
             f"{cls.__name__} does not accept parents of type {value.__class__.__name__}."
         )
示例#6
0
 def before_commit(self, session, is_modified):
     session.flush()
     state = db.inspect(self)
     tbl = state.mapper.primary_base_mapper.tables[0]
     rps = [self.slug]
     parent = self.parent
     while parent is not None:
         rps.append(parent.slug)
         parent = parent.parent
     rps.reverse()
     new_url_path = "/".join(rps)
     up = db.update(tbl).where(tbl.c.id == self.id).values(
         url_path=new_url_path)
     session.execute(up)
     session.refresh(self)
     with session.no_autoflush:
         for child in self.children:
             AbstractPage.before_commit(child, session, True)
示例#7
0
 def _before_appending_nodes(cls, instance, value, initiator=None):
     if not db.inspect(instance).mapper.class_.is_valid_child(value):
         raise ValueError(
             f"{cls.__name__} does not accept children of type {value.__class__.__name__}."
         )
示例#8
0
文件: misc.py 项目: ra2003/oy-cms
 def after_flush_postexec(self, session, is_modified):
     if self.sort_order is None:
         self.sort_order = db.inspect(self).mapper.primary_key[0]