# Path: lolipop/models.py
# class Notice(db.Model):
#     __tablename__ = 'notice'
#     id = db.Column(db.Integer,primary_key = True)
#     title = db.Column(db.String)
#     content = db.Column(db.Text)
#     date_create = db.Column(db.DateTime,default = datetime.utcnow)
#     viewed = db.Column(db.Integer,default=0)
# 
#     def __str__(self):
#         return self.title
# 
#     def save(self):
#         db.session.add(self)
#         db.session.commit()
#         return self
# 
#     def delete(self):
#         db.session.delete(self)
#         db.session.commit()
#         return self
# 
# class Topic(db.Model):
#     __tablename__ = 'topics'
#     id = db.Column(db.Integer,primary_key = True)
#     title = db.Column(db.String)
#     node_id = db.Column(db.Integer,db.ForeignKey("nodes.id",use_alter=True,name="fk_node_id"))
#     user_id = db.Column(db.Integer,db.ForeignKey("users.id"))
#     date_created = db.Column(db.DateTime,default=datetime.utcnow)
#     viewed = db.Column(db.Integer,default = 0)
#     post_count = db.Column(db.Integer,default = 0)
# 
#     # when two table reference each other and one-to-one
#     # set uselist = False
#     first_post_id = db.Column(db.Integer,db.ForeignKey("posts.id",ondelete="CASCADE"))
#     first_post = db.relationship("Post",backref="first_post",foreign_keys=[first_post_id],uselist=False)
# 
#     last_post_id = db.Column(db.Integer,db.ForeignKey("posts.id",ondelete="CASCADE",onupdate="CASCADE"))
#     last_post = db.relationship("Post",backref="last_post",foreign_keys=[last_post_id],uselist=False)
# 
#     posts = db.relationship("Post",backref="topic",lazy="joined",primaryjoin="Post.topic_id == Topic.id",cascade="all,delete-orphan",post_update=True)
# 
#     def __init__(self,title=None):
#         if title:
#             self.title = title
# 
#     def get_name(self):
#         return self.title
# 
#     def __str__(self):
#         return self.title
# 
#     def __repr__(self):
#         return '<Topic:%s>' % self.id
# 
#     @property
#     def second_last_post_id(self):
#         return self.posts[-2].id
# 
#     def save(self,node=None,user=None,post=None):
#         #def save(self,post=None):
#         # edit title
#         if self.id:
#             db.session.add(self)
#             db.session.commit()
# 
#         self.node_id = node.id
#         self.user_id = user.id
#         db.session.add(self)
#         db.session.commit()
# 
#         post.save(user,self)
#         self.first_post_id = post.id
#         db.session.commit()
#         return self
# 
#     def delete(self):
#         #count = Post.query.filter(topic_id == self.id).filter(user_id == self.user_id).count()
#         #self.user.score -= count
#         db.session.delete(self)
#         db.session.commit()
# 
# Path: _helpers.py
# ONLINE_LAST_MINUTES = 5
# def force_int(value,default=1):
#     def block_code(self,text,lang):
# def fill_with_user(items):
# def fill_with_node(items):
# def fill_object(items,objects,*args,**kwargs):
# def _add_attr(item,objects_dict,arg,kwargs):
# def mark_online(user_id):
# def get_online_users():
# class BleepRenderer(HtmlRenderer,SmartyPants):
# class MaxinObject(object):


from flask import Blueprint,render_template
from lolipop.models import Notice,Topic
from _helpers import fill_with_user,fill_with_node,cache

bp = Blueprint('index',__name__)

@bp.route("/")
@bp.route("/index")
@cache.cached(timeout=1000)
def index():

# Path: lolipop/models.py
# class Notice(db.Model):
#     __tablename__ = 'notice'
#     id = db.Column(db.Integer,primary_key = True)
#     title = db.Column(db.String)
#     content = db.Column(db.Text)
#     date_create = db.Column(db.DateTime,default = datetime.utcnow)
#     viewed = db.Column(db.Integer,default=0)
# 
#     def __str__(self):
#         return self.title
# 
#     def save(self):
#         db.session.add(self)
#         db.session.commit()
#         return self
# 
#     def delete(self):
#         db.session.delete(self)
#         db.session.commit()
#         return self
# 
# class Topic(db.Model):
#     __tablename__ = 'topics'
#     id = db.Column(db.Integer,primary_key = True)
#     title = db.Column(db.String)
#     node_id = db.Column(db.Integer,db.ForeignKey("nodes.id",use_alter=True,name="fk_node_id"))
#     user_id = db.Column(db.Integer,db.ForeignKey("users.id"))
#     date_created = db.Column(db.DateTime,default=datetime.utcnow)
#     viewed = db.Column(db.Integer,default = 0)
#     post_count = db.Column(db.Integer,default = 0)
# 
#     # when two table reference each other and one-to-one
#     # set uselist = False
#     first_post_id = db.Column(db.Integer,db.ForeignKey("posts.id",ondelete="CASCADE"))
#     first_post = db.relationship("Post",backref="first_post",foreign_keys=[first_post_id],uselist=False)
# 
#     last_post_id = db.Column(db.Integer,db.ForeignKey("posts.id",ondelete="CASCADE",onupdate="CASCADE"))
#     last_post = db.relationship("Post",backref="last_post",foreign_keys=[last_post_id],uselist=False)
# 
#     posts = db.relationship("Post",backref="topic",lazy="joined",primaryjoin="Post.topic_id == Topic.id",cascade="all,delete-orphan",post_update=True)
# 
#     def __init__(self,title=None):
#         if title:
#             self.title = title
# 
#     def get_name(self):
#         return self.title
# 
#     def __str__(self):
#         return self.title
# 
#     def __repr__(self):
#         return '<Topic:%s>' % self.id
# 
#     @property
#     def second_last_post_id(self):
#         return self.posts[-2].id
# 
#     def save(self,node=None,user=None,post=None):
#         #def save(self,post=None):
#         # edit title
#         if self.id:
#             db.session.add(self)
#             db.session.commit()
# 
#         self.node_id = node.id
#         self.user_id = user.id
#         db.session.add(self)
#         db.session.commit()
# 
#         post.save(user,self)
#         self.first_post_id = post.id
#         db.session.commit()
#         return self
# 
#     def delete(self):
#         #count = Post.query.filter(topic_id == self.id).filter(user_id == self.user_id).count()
#         #self.user.score -= count
#         db.session.delete(self)
#         db.session.commit()
# 
# Path: _helpers.py
# ONLINE_LAST_MINUTES = 5
# def force_int(value,default=1):
#     def block_code(self,text,lang):
# def fill_with_user(items):
# def fill_with_node(items):
# def fill_object(items,objects,*args,**kwargs):
# def _add_attr(item,objects_dict,arg,kwargs):
# def mark_online(user_id):
# def get_online_users():
# class BleepRenderer(HtmlRenderer,SmartyPants):
# class MaxinObject(object):


# Path: views/index.py
from flask import Blueprint,render_template
from lolipop.models import Notice,Topic
from _helpers import fill_with_user,fill_with_node,cache


bp = Blueprint('index',__name__)

@bp.route("/")
@bp.route("/index")
@cache.cached(timeout=1000)
def index():

    notices = Notice.query.order_by(Notice.id.desc())