<s> from flask import render_template <EOL> from . . core . models import BaseMixin , db <EOL> from . . ext import cache <EOL> from . config import TEMPLATE , ROOT <EOL> class Page ( db . Model , BaseMixin ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> active = db . Column ( db . Boolean , default = True ) <EOL> slug = db . Column ( db . String ( <NUM_LIT:100> ) , nullable = False , unique = True ) <EOL> link = db . Column ( db . String ( <NUM_LIT> ) ) <EOL> content = db . Column ( db . Text ) <EOL> parent_id = db . Column ( db . Integer , db . ForeignKey ( '<STR_LIT>' ) ) <EOL> children = db . relation ( <EOL> '<STR_LIT>' , <EOL> cascade = '<STR_LIT:all>' , <EOL> backref = db . backref ( '<STR_LIT>' , remote_side = '<STR_LIT>' ) ) <EOL> def __unicode__ ( self ) : <EOL> return self . slug <EOL> def render ( self ) : <EOL> return render_template ( TEMPLATE , page = self ) <EOL> @ property <EOL> def uri ( self ) : <EOL> cache_key = '<STR_LIT>' . format ( slug = self . slug ) <EOL> uri = cache . get ( cache_key ) <EOL> if not uri : <EOL> parent = self . parent_id and self . parent . uri or ( '<STR_LIT>' % ROOT ) <EOL> uri = "<STR_LIT>" . format ( parent = parent , slug = self . slug ) <EOL> cache . set ( cache_key , uri ) <EOL> return uri <EOL> @ classmethod <EOL> def route ( cls , slug ) : <EOL> page = cls . query . filter_by ( slug = slug ) . first ( ) <EOL> if page is None : <EOL> return page <EOL> return page . uri </s>
