Esempio n. 1
0
def create_app(name):
    app = Flask(name)
    # app.config.update(DEBUG=True, SECRET_KEY='\xa5\xf1\xf1\xe4{\x02\xf2V\xec\x1c\xb0/h]\x08u\xab0\xb0\xf7\xd2\x89\xa6\xb7',
    #                     BABEL_DEFAULT_LOCALE='zh', EXPERIED_TIME=10*10, EXPLAIN_TEMPLATE_LOADING=True)
    # app.config.from_object('bbs.config.Config')
    app.config.update(get_config("app"))

    # register_shutdown_handler(app)
    # app.before_request(register_middleware)
    return app
Esempio n. 2
0
 def __new__(cls , name, bases, attrs):
     module = attrs.get('__module__')
     if module not in cls.config_cache:
         try:
             cls.config_cache = get_config(module)
         except Exception as e:
             import traceback; traceback.print_exc()
             cls.config_cache = {}
     add_attrs = cls.config_cache.get(name, {})
     return super(ViewMetaClass, cls).__new__(cls, 
             name, bases, dict_merge(add_attrs, attrs))
Esempio n. 3
0
import bbs.apps

from werkzeug.wsgi import DispatcherMiddleware, SharedDataMiddleware

from bbs.registers import regist_apps
from bbs.conf import get_config

apps = regist_apps(bbs.apps)

bbs_config = get_config(__name__)

front_app_name, backend_app = bbs_config.get('DISPATCH').popitem()
front_app = apps[front_app_name]
dispatch_app = {v: apps[k] for k, v in backend_app.items()}

app = DispatcherMiddleware(front_app, dispatch_app)
app = SharedDataMiddleware(app, bbs_config.get('SHAREDATA'))
Esempio n. 4
0
import json
import hashlib, datetime

from sqlalchemy import ForeignKey, Boolean, UnicodeText, Table, DateTime, \
        select, func, and_, Column, Integer, Unicode
from sqlalchemy.orm import backref, relationship, column_property

from bbs.orm import Base
from bbs.conf import get_config

SECRET_KEY = get_config('app').get('SECRET_KEY')

class User(Base):
    __tablename__ = 'users'

    id = Column(Integer, primary_key=True)
    username = Column(Unicode(20), unique=True, nullable=False)
    _password = Column(Unicode(128), nullable=False)
    is_super = Column(Boolean, default=False)
    
    added_at = Column(DateTime, default=datetime.datetime.now, nullable=False)

    # from sqlalchemy.ext.hybrid import hybrid_property
    # @hybrid_property
    # def fullname(self):
    #     return self.username + 'abc'

    def __repr__(self):
        return '<User {}>'.format(self.id)

    def __str__(self):
Esempio n. 5
0
def _create_engine():
    config = get_config('app')
    db_name = config.get('DB_FILE')
    echo  = config.get('DB_ECHO')

    return create_engine(db_name, echo=echo)
Esempio n. 6
0
import os.path as op 
from urllib.parse import urljoin

from flask import Blueprint, current_app, request, send_from_directory
from bbs.helpers import generate_media_filename

from bbs.conf import get_config

handler = Blueprint('handler', __name__)
media_path = get_config('app').get('MEDIA_PATH')

@handler.route('/upload_img', methods=['POST', ])
def upload_img():
    ck_num = request.values.get('CKEditorFuncNum')
    f = request.files.get('upload')
    filename = generate_media_filename() + op.splitext(f.filename)[1]
    full_path = op.join(media_path, filename)
    f.save(full_path)
    f.close()
    image_url = urljoin('/media/', filename)
    return '''
            <script type="text/javascript">
                window.parent.CKEDITOR.tools.callFunction(%(CKFuncNum)s, "%(image_path)s", "上传成功");
            </script>
    ''' % {'CKFuncNum': ck_num, 'image_path': image_url}