def _handle_image_delete(mapper, conn, target): """ 在删除了图片实体时,同时从本地硬盘和云端存储删除相关联的图片文件 :param mapper: :param conn: :param target: 待删除的Image对象 :return: """ try: if target.path: os.remove(op.join(base_path, target.path)) except: pass # 如果public_id不为空,说明是云端存储的,使用public_id删除 # 如果public_id为空,说明是本地存储的,则使用image.py中定义的after_delete的监听器删除 if target.public_id is not None: AppInfo.get_image_store_service().remove(target.public_id)
app.jinja_env.filters['datedelta'] = jinja2_filter_date_with_delta app.jinja_env.filters['heatmap'] = jinja2_filter_photo_collection_heat_map app.jinja_env.filters['averagerating'] = jinja2_filter_get_average_rating app.jinja_env.filters['numberoforder'] = jinja2_filter_get_number_of_order from flask_babelex import Babel babel = Babel(default_locale='zh_Hans_CN') babel.init_app(app) from flask.ext.sqlalchemy import SQLAlchemy db = SQLAlchemy(app) from app.app_provider import AppInfo AppInfo.set_app(app) AppInfo.set_db(db) # 初始化云端的图片存储服务 image_store = ImageStore(app) # 初始化Gallery存储的服务,用于存储所有的用户上传的头像 AppInfo.set_galleries_store_service(image_store) # 初始化Image存储的服务,用于存储所有摄影师上传的作品图像 AppInfo.set_image_store_service(image_store) # 初始化调试工具栏(Flask-DebugToolbar) toolbar = DebugToolbarExtension(app) # 初始化所有的routers定义 from app.routers import *
# coding=utf-8 from app.app_provider import AppInfo from user import User from sqlalchemy import Column, Integer, Text, DateTime from sqlalchemy.orm import backref db = AppInfo.get_db() class Comment(db.Model): """ 评论,该评论可能是针对一个订单,或者一个作品 如果针对一个订单,通过对象OrderComment进行关联 如果针对一幅作品,通过对象PhotoWorkComment进行关联 """ __tablename__ = 'comment' id = Column(Integer, primary_key=True) # 评论内容 content = Column(Text, nullable=False) # 评论创建时间 date = Column(DateTime, nullable=False) # 评论所属的用户 user_id = db.Column(db.Integer, db.ForeignKey(User.id)) user = db.relation(User, backref=backref('comments_created', uselist=True))
from flask import Flask from flask.ext.migrate import Migrate, MigrateCommand from flask.ext.script import Manager from flask.ext.security import SQLAlchemyUserDatastore, Security app = Flask(__name__, template_folder='app/templates', static_folder='app/static') import app.config as config app.config.from_object(config) from flask.ext.sqlalchemy import SQLAlchemy db = SQLAlchemy(app) from app.app_provider import AppInfo AppInfo.set_app(app) AppInfo.set_db(db) # Setup Flask-Security from app.models.user import User, Role # Set up flask security messages. for key, value in config.security_messages.items(): app.config['SECURITY_MSG_' + key] = value user_datastore = SQLAlchemyUserDatastore(db, User, Role) security = Security(app, user_datastore) if __name__ == "__main__": # app.run(host='0.0.0.0', port=80, debug=True) migrate = Migrate(app, db) manager = Manager(app)
def type_filter(type_code): return AppInfo.get_db().session.query(EnumValues).\ join(EnumValues.type, aliased=True).\ filter_by(code=type_code)