Exemplo n.º 1
0
    def init_admin(self):
        from .models import Post
        from .views import PostAdmin

        admin = self.super('admin')
        admin.add_view(
            PostAdmin(Post, db.session, name='博客管理', category='内容管理'))

        path = os.path.join(self.app.root_path, 'media')
        admin.add_view(FileAdmin(path, '/media/', name='文件管理',
                                 category='内容管理'))
Exemplo n.º 2
0
from flask.ext.admin import Admin, BaseView, expose
from flask.ext.admin.contrib.fileadmin import FileAdmin
from flask.ext.mail import Message, Mail
import os.path as op
from functools import wraps
from dbconnect import connection
import gc
import datetime
import pygal
from collections import Counter

app = Flask(__name__)
admin = Admin(app)
mail = Mail()
path = op.join(op.dirname(__file__), 'static/test')
admin.add_view(FileAdmin(path, '/static/test', name='Static Files'))

# set the secret key.  keep this really secret:
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
app.WTF_CSRF_SECRET_KEY = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
app.config['RECAPTCHA_PUBLIC_KEY'] = '6Ld14VEUAAAAACNJAmUPEAcFg1xRGSXUlN5rJSFw'
app.config[
    'RECAPTCHA_PRIVATE_KEY'] = '6Ld14VEUAAAAAOO5hyLVR-evTwtQVlaNQpwPcDfV'
#--mail--
app.config["MAIL_SERVER"] = "mail.btinternet.com"
app.config["MAIL_PORT"] = 465
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = '******'
app.config["MAIL_PASSWORD"] = '******'

mail.init_app(app)
Exemplo n.º 3
0
# Setup the admin interface
from flask import request, Response
from werkzeug.exceptions import HTTPException
from flask_admin import Admin
from flask.ext.admin.contrib.sqla import ModelView
from flask.ext.login import LoginManager
from flask.ext.admin.contrib.fileadmin import FileAdmin
import os.path as op

admin = Admin(app, name='Admin', template_mode='bootstrap3')


class ModelView(ModelView):
    def is_accessible(self):
        auth = request.authorization or request.environ.get(
            'REMOTE_USER')  # workaround for Apache
        if not auth or (auth.username,
                        auth.password) != app.config['ADMIN_CREDENTIALS']:
            raise HTTPException(
                '',
                Response('You have to an administrator.', 401,
                         {'WWW-Authenticate': 'Basic realm="Login Required"'}))
        return True


# Users
admin.add_view(ModelView(User, db.session))
# Static files
path = op.join(op.dirname(__file__), 'static')
admin.add_view(FileAdmin(path, '/static/', name='Static'))
Exemplo n.º 4
0
def __add_file_managers(app: Flask, admin: Admin):
    if app.has_static_folder:
        admin.add_view(FileAdmin(app.static_folder, name='Static Files', endpoint='static'))
Exemplo n.º 5
0
Arquivo: app.py Projeto: danhyun/fbone
def configure_extensions(app):
    # flask-sqlalchemy
    db.init_app(app)

    # flask-mail
    mail.init_app(app)

    # flask-cache
    cache.init_app(app)

    # flask-babel
    babel = Babel(app)

    @babel.localeselector
    def get_locale():
        override = request.args.get('lang')
        if override:
            session['lang'] = override
            return session.get('lang', 'en')
        else:
            accept_languages = app.config.get('ACCEPT_LANGUAGES')
            return request.accept_languages.best_match(accept_languages)

    # flask-login
    login_manager.login_view = 'frontend.login'
    login_manager.refresh_view = 'frontend.reauth'

    @login_manager.user_loader
    def load_user(id):
        return User.query.get(id)

    login_manager.setup_app(app)

    # flask-admin
    admin = Admin()
    # Setup locale
    admin.locale_selector(get_locale)
    # Views
    # Model admin
    admin.add_view(
        ModelView(User, db.session, endpoint='usermodel', category='Model'))
    admin.add_view(
        ModelView(UserDetail,
                  db.session,
                  endpoint='userdetailmodel',
                  category='Model'))
    admin.add_view(
        ModelView(UserRole, db.session, endpoint='rolemodel',
                  category='Model'))
    # File admin
    path = os.path.join(os.path.dirname(__file__), 'static/img/users')
    # Create directory if existed.
    try:
        os.mkdir(path)
    except OSError:
        pass
    admin.add_view(
        FileAdmin(path,
                  '/static/img/users',
                  endpoint='useravatar',
                  name='User Avatars',
                  category='Image'))
    admin.init_app(app)
Exemplo n.º 6
0
def create_app(config_name):
    app = Flask(__name__)
    conf = config_dict[config_name]
    app.config.from_object(conf)
    app.config['UPLOAD_FOLDER'] = conf.UPLOAD_FOLDER

    # 初始化db
    db.init_app(app)

    global redis_store
    redis_store = redis.StrictRedis(host=conf.REDIS_HOST,
                                    port=conf.REDIS_PORT,
                                    password=conf.REDIS_PASSWD)

    # 初始化
    # csrf.init_app(app)

    Session(app)

    # 向app中添加自定义转换器
    app.url_map.converters['re'] = RegexConverter

    import danke.api_1_0
    app.register_blueprint(api_1_0.api, url_prefix="/api/v1_0")

    # 提供静态文件
    import danke.web_html
    app.register_blueprint(web_html.html)

    babel.init_app(app)

    # from danke.api_1_0.admin import MyView
    from danke.api_1_0.admin import CustomView, CustomModelView
    from flask.ext.admin.contrib.fileadmin import FileAdmin
    import os.path as op

    from danke.api_1_0.admin import User_info, Addr_info, GoodsType_info, Goods_info, GoodsSku_info, IndexGoodsBanner_info, GoodsImage_info, PromotionBanner_info, OrderInfo_info
    from danke.api_1_0.admin import GoodsColor_info, GoodsModel_info, Superuser_info, Groupadd_info, DiscountCoupons_info, Classify_info

    # Add views here
    adm.init_app(app)

    adm.add_view(Superuser_info(db.session, name=u'管理员', category=u'用户管理'))
    adm.add_view(User_info(db.session, name=u'用户', category=u'用户管理'))
    adm.add_view(Addr_info(db.session, name=u'地址', category=u'用户管理'))
    adm.add_view(Classify_info(db.session, name=u'商品分类', category=u'商品管理'))
    adm.add_view(GoodsType_info(db.session, name=u'商品类型', category=u'商品管理'))
    adm.add_view(Goods_info(db.session, name=u'商品', category=u'商品管理'))
    adm.add_view(GoodsColor_info(db.session, name=u'颜色', category=u'商品管理'))
    adm.add_view(GoodsModel_info(db.session, name=u'型号', category=u'商品管理'))
    adm.add_view(GoodsImage_info(db.session, name=u'商品图片', category=u'商品管理'))
    adm.add_view(GoodsSku_info(db.session, name=u'商品sku', category=u'商品管理'))
    adm.add_view(
        IndexGoodsBanner_info(db.session, name=u'轮播商品', category=u'商品管理'))
    adm.add_view(
        PromotionBanner_info(db.session, name=u'广告商品', category=u'商品管理'))
    adm.add_view(OrderInfo_info(db.session, name=u'订单详情', category=u'订单管理'))
    adm.add_view(Groupadd_info(db.session, name=u'拼团表', category=u'订单管理'))
    adm.add_view(DiscountCoupons_info(db.session, name=u'优惠券',
                                      category=u'优惠券'))

    path = op.join(op.dirname(__file__), 'static')
    adm.add_view(FileAdmin(path, '/static/', name=u'静态文件'))
    return app
Exemplo n.º 7
0
 def get_base_path(self):
     path = FileAdmin.get_base_path(self)
     theme = Setting.query.filter_by(name=u'theme').first().value
     return os.path.join(path, theme)
Exemplo n.º 8
0
            login_user(user)
            return redirect(url_for('.index'))
        link = '<p>Already have an account? <a href="' + url_for(
            '.login_view') + '">Click here to log in.</a></p>'
        self._template_args['form'] = form
        self._template_args['link'] = link
        return super(MyAdminIndexView, self).index()

    @expose('/logout/')
    def logout_view(self):
        logout_user()
        return redirect(url_for('.index'))


admin = Admin(app, index_view=MyAdminIndexView())

# class TopotypeView(ModelView):
#     column_auto_select_related = True
#     # column_display_all_relations = True

# Add administrative views here
admin.add_view(ModelView(User, db.session))
admin.add_view(ModelView(Dataset, db.session))
admin.add_view(ModelView(Topogram, db.session))
# admin.add_view(TopotypeView(Topotype, db.session))
admin.add_view(ModelView(Regexp, db.session))

path = os.path.join(os.path.join(os.getcwd(), 'src'), "static")
admin.add_view(FileAdmin(ASSETS_DIR, '/static/', name='Static Files'))
Exemplo n.º 9
0
__author__ = 'Genus'
# flask-admin ModelView
from flask_admin.contrib.sqla import ModelView
from flask.ext.admin.contrib.fileadmin import FileAdmin

# 파일업로드를 위함
import os.path as op

# custom
from . import admin, db
from .models import UserDB, UserProfile, PortFolio, ProfileRibbon, ProfileSocial

admin.add_view(ModelView(UserDB, db.session))
admin.add_view(ModelView(UserProfile, db.session))
admin.add_view(ModelView(PortFolio, db.session))
admin.add_view(ModelView(ProfileRibbon, db.session))
admin.add_view(ModelView(ProfileSocial, db.session))

path = op.join(op.dirname(__file__), 'media')
admin.add_view(FileAdmin(path, '/media/', name='Media Files'))
Exemplo n.º 10
0
 def get_base_path(self):
     path = FileAdmin.get_base_path(self)
     theme = Setting.query.filter_by(name=u'theme').first().value
     return os.path.join(path, theme)
Exemplo n.º 11
0
@app.route('/events')
def events():
	my_events = Events.objects()
	return render_template('events.html', my_events=my_events)

@app.route('/projects')
def projects():
	my_projects = Projects.objects()
	return render_template('projects.html', v_projects=my_projects)

@app.route('/faq')
def faq():
	return render_template('faq.html')

@app.route('/projectdetails/<project_id>')
def projectdetails(project_id):
	current_project = Projects.objects(id=project_id)
	all_projects = Projects.objects()
	for c in current_project:
		c_project = c
	return render_template('projectdetails.html', current_project=c_project, all_projects=all_projects)

	# Need to change current_project = and the for loop

if __name__ == '__main__':
	admin.add_view(ProjectView(Projects))
	admin.add_view(EventView(Events))
	path = op.join(op.dirname(__file__), 'static/images')
	admin.add_view(FileAdmin(path, name='Images'))
	app.run(debug=True)
Exemplo n.º 12
0

def add_user(name, email, password):
    #make connection to database
    db = MySQLdb.connect(host="localhost",
                         user="******",
                         passwd="root",
                         db="filebox")
    # you must create a Cursor object to let you execute queries
    cur = db.cursor()
    cur.execute(
        """INSERT INTO USERS (NAME, EMAIL, PASSWORD) VALUES (%s, %s, %s )""",
        (name, email, password))
    # cur.execute("SELECT VERSION()")
    # # Fetch a single row using fetchone() method.
    # data = cur.fetchone()
    # print "Database version : %s " % data
    db.commit()
    cur.close()
    db.close()


def create_user_folder(name):
    os.mkdir(path + '/files' + '/' + name)


admin.add_view(FileAdmin(path + '/files/', name='Files'))

if __name__ == '__main__':
    app.run()