def init_admin(app, db): auth_admin = Auth(app, db) User = auth_admin.User User.create_table(fail_silently=True) if not User.select().where(User.username == 'admin').exists(): admin = User(username='******', email='', admin=True, active=True) admin.set_password('admin') admin.save() admin = Admin(app, auth_admin) from hse_arch.models.customer import Customer from hse_arch.models.order import Order, OrderItem from hse_arch.models.product import Product, ProductIngredient, Ingredient from hse_arch.models.producers import Producer from hse_arch.models.category import Category from hse_arch.models.user import User admin.register(Customer, CustomerAdmin) admin.register(Order) admin.register(OrderItem) admin.register(Product) admin.register(Ingredient) admin.register(Producer) admin.register(Category) admin.register(ProductIngredient) admin.register(User) admin.setup() return admin
def setup_admin(): auth = Auth(app, db, user_model=User) admin = Admin(app, auth) admin.register(User, UserAdmin) admin.register(Photo, PhotoAdmin) auth.register_admin(admin) admin.setup() return auth, admin
def create_app(): app = Flask(__name__) app.config.update( DEBUG=True, SECRET_KEY='supersecret', DATABASE={ 'name': 'example.db', 'engine': 'peewee.SqliteDatabase', }, ) app.db = Database(app) Feedloggr(app, app.db) # OPTIONALLY SETUP BEGINS # Simple authentication for the admin interface app.auth = Auth(app, app.db) app.auth.User.create_table(fail_silently=True) # Try to create a new admin user, but fail silently if it already exists try: user = app.auth.User.create( username='******', email='.', password='', admin=True, active=True, ) except PIE: pass else: user.set_password('admin') user.save() # Initialize the admin interface app.admin = Admin(app, app.auth) app.auth.register_admin(app.admin) # Register the feedloggr feeds model app.admin.register(feedloggr_Feeds, feedloggr_FeedsAdmin) app.admin.setup() # OPTIONALLY SETUP ENDS return app
return render_template('apply.html', title='Apply', form=form) @app.route('/') def index(): auth = Auth(app, models.DATABASE) #admin = Admin(app, auth) #admin.register(models.User) #admin.setup() if __name__ == '__main__': models.initialize() # needed for authentication admin = Admin(app, name="GrizzHacks") admin.add_view(UserView(models.User)) admin.add_view(MyModelView(models.Apply)) admin.add_view(MyModelView(models.emailSignup)) # admin.set_password('admin') try: models.User.create_user(email='*****@*****.**', password='******', admin=True) except ValueError: pass app.run(debug=DEBUG, host=HOST, port=PORT)
# app.scripts.config.serve_locally = True app.title = 'Test Dash Project' server = app.server DATABASE = { 'name': DB_NAME, 'engine': 'peewee.SqliteDatabase', } SECRET_KEY = SECRET_KEY_SERVER server.config.from_object(__name__) db = DataBase(server) auth = Auth(app=server, db=db, user_model=Users) admin = Admin(app=server, auth=auth) admin.register(model=Cities) admin.register(model=Date) admin.register(model=Devices) admin.register(model=HoursInDay) admin.register(model=PageViewsByDevices) admin.register(model=RegionsMap) admin.register(model=TrafficSource) admin.register(model=Users) admin.register(model=VisitsCountByHour) admin.register(model=VisitsCountByTrafficSource) admin.setup() # Setup the LoginManager for the server login_manager = LoginManager() login_manager.init_app(server)
def init_app(self, app): # Инициируем Админку self.extension = Admin(app.web_app, app.auth)
url_prefix='/%s' % app_config.PROJECT_SLUG) file_handler = logging.FileHandler('%s/app.log' % app_config.SERVER_LOG_PATH) file_handler.setLevel(logging.INFO) app.logger.addHandler(file_handler) app.logger.setLevel(logging.INFO) class SlideAdmin(ModelAdmin): exclude = ('slug', ) # Set up flask peewee db wrapper db = Database(app) auth = Auth(app, db, prefix='/%s/accounts' % app_config.PROJECT_SLUG) admin = Admin(app, auth, prefix='/%s/admin' % app_config.PROJECT_SLUG) admin.register(Slide, SlideAdmin) admin.register(SlideSequence) admin.setup() @app.route('/%s/admin/stack/' % app_config.PROJECT_SLUG, methods=['GET']) def _stack(): """ Administer a stack of slides. """ context = make_context(asset_depth=1) sequence = SlideSequence.select() sequence_dicts = sequence.dicts()
def save_model(self, instance, form, adding=False): instance = super(PhotoAdmin, self).save_model(instance, form, adding) if 'image_file' in request.files: file = request.files['image_file'] instance.save_image(file) return instance class NotePanel(AdminPanel): template_name = 'admin/note.html' def get_context(self): return { 'list': Order.select(), } admin = Admin(app, auth, branding='Example Site') auth.register_admin(admin) admin = CustomAdmin(app, auth) admin.register(Photo, PhotoAdmin) admin.register(Goods, GoodsAdmin) admin.register(User, UserAdmin) admin.register(Reviews, ReviewsAdmin) admin.register(Order) admin.register_panel('Orders', NotePanel)
import datetime from flask import request, redirect from wtforms import fields, widgets from flask_peewee.admin import Admin, ModelAdmin, AdminPanel from flask_peewee.filters import QueryFilter from app import app, db from auth import auth from models import User, Message, Note, Relationship from models import Photo admin = Admin(app, auth, branding='Naucilus') #WTFform class CKTextAreaWidget(widgets.TextArea): def __call__(self, field, **kwargs): # add WYSIWYG class to existing classes existing_classes = kwargs.pop('class', '') or kwargs.pop('class_', '') kwargs['class'] = u'%s %s' % (existing_classes, "ckeditor") return super(CKTextAreaWidget, self).__call__(field, **kwargs) class CKTextAreaField(fields.TextAreaField): widget = CKTextAreaWidget() @app.route('/admin/post') def adminposting():
class CountryAdmin(ModelAdmin): columns = ('id', 'countrycode', 'countryname') class ChargeAdmin(ModelAdmin): columns = ('id', 'id_cc_card', 'creationdate', 'amount', 'chargetype') class DidAdmin(ModelAdmin): columns = ('id', 'did', 'iduser', 'activated', 'reserved') class DidDestinationAdmin(ModelAdmin): columns = ('destination', 'id_cc_card', 'id_cc_did', 'activated') admin = Admin(app, auth, branding='A2Billing API Admin Site') admin.register(Card, CardAdmin) admin.register(CardGroup, CardGroupAdmin) admin.register(Callerid, CalleridAdmin) admin.register(Logrefill, LogrefillAdmin) admin.register(Logpayment, LogpaymentAdmin) admin.register(Call, CallAdmin) admin.register(Country, CountryAdmin) admin.register(Charge, ChargeAdmin) # admin.register(Did, DidAdmin) # admin.register(DidDestination, DidDestinationAdmin) auth.register_admin(admin)
# -*- coding: utf-8 -*- """Copyright (c) 2012 Sergio Gabriel Teves All rights reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ """ Created on 29/09/2012 """ from flask_peewee.admin import Admin from pystatus.app import application, auth from pystatus.app.models import Process admin = Admin(application, auth) admin.register(Process)
class DidDestinationAdmin(ModelAdmin): columns = ('destination', 'id_cc_card', 'id_cc_did', 'activated') class CountryServerAdmin(ModelAdmin): columns = ('id', 'countrycode', 'countryname', 'countryprefix', 'server', 'port') class TicketAdmin(ModelAdmin): columns = ('id', 'title', 'description', 'creationdate', 'priority', 'creator', 'creator_type', 'id_component', 'status', 'viewed_cust', 'viewed_agent', 'viewed_admin') admin = Admin(app, auth, branding='Redirect API Admin Site') ''' admin.register(Card, CardAdmin) admin.register(CardGroup, CardGroupAdmin) admin.register(Callerid, CalleridAdmin) admin.register(Logrefill, LogrefillAdmin) admin.register(Logpayment, LogpaymentAdmin) admin.register(Call, CallAdmin) admin.register(Country, CountryAdmin) admin.register(Charge, ChargeAdmin) admin.register(Did, DidAdmin) admin.register(DidDestination, DidDestinationAdmin) admin.register(CountryServer, CountryServerAdmin) admin.register(Ticket, TicketAdmin) auth.register_admin(admin)
# configure our database DATABASE = { 'name': 'expense.db', 'engine': 'peewee.SqliteDatabase', } DEBUG = True SECRET_KEY = 'ssshhhh' app = Flask(__name__) app.config.from_object(__name__) # create an Auth object for use with our flask app and database wrapper # auth = Auth(app, db) admin = Admin(app, None) admin.register(User) admin.register(Expense) admin.register(Chat) admin.setup() # create a RestAPI container api = RestAPI(app) # register the Note model api.register(User) api.register(Expense) api.register(Chat) api.setup()
import datetime from flask_peewee.admin import Admin, ModelAdmin, AdminPanel from app import app from auth import auth from models import User, Relationship class UserStatsPanel(AdminPanel): template_name = 'admin/user_stats.html' def get_context(self): last_week = datetime.datetime.now() - datetime.timedelta(days=7) signups_this_week = User.select().where(User.joined > last_week).count() return { 'signups': signups_this_week, } class UserAdmin(ModelAdmin): # it doesn't work yet because flask-peewe has error columns = ('email', 'active', 'admin', 'joined') admin = Admin(app, auth, branding=app.config['BRAND']) auth.register_admin(admin, UserAdmin) admin.register_panel('User stats', UserStatsPanel) admin.register(Relationship)
print("user_model.DoesNotExist") pass from .forms import LoginForm, RegisterForm user_datastore = FixPeeweeUserDatastore(db, Users, Role, UserRoles) # security = Security(app, user_datastore) security = Security(app, user_datastore, login_form=LoginForm, register_form=RegisterForm) # create admin object admin = Admin( app, auth, prefix=app.config['ADMIN_URL'], branding=app.config['BRANDING'], ) admin.register(Users, UsersAdmin) admin.register(Role, RoleAdmin) admin.register(UserRoles, UserRolesAdmin) admin.register(Recharge, RechargeAdmin) admin.register(TakeOut, TakeOutAdmin) admin.register(GameType, GameTypeAdmin) admin.register(Assets, AssetsAdmin) admin.register(Commodity, CommodityAdmin) admin.register(Order, OrderAdmin) admin.register(OrderDetail, OrderDetailAdmin) admin.register(GameAssets, GameAssetsAdmin) admin.register(Coin, CoinAdmin) admin.register(ShopCoin, ShopCoinAdmin)
from flask_peewee.admin import Admin, ModelAdmin from app import app, db from auth import auth from models import User, Location, Acl from pbkdf2 import hashing_passwords as hp admin = Admin(app, auth, branding='MQTTitude') # or you could admin.register(User, ModelAdmin) -- you would also register # any other models here. class LocationAdmin(ModelAdmin): columns = ( 'tst', 'username', 'device', 'lat', 'lon', ) class UserAdmin(ModelAdmin): columns = ( 'username', 'superuser', 'pbkdf2', ) # Upon saving the User model in admin, set the PBKDF2 hash for
import psyc.models.processor as processor import psyc.models.execution as execution from gevent.wsgi import WSGIServer from flask_peewee.admin import Admin port = 9080 auth.User.create_table(fail_silently=True) url.Url.create_table(fail_silently=True) resource.Resource.create_table(fail_silently=True) catalog.Catalog.create_table(fail_silently=True) processor.Processor.create_table(fail_silently=True) execution.Execution.create_table(fail_silently=True) admin = Admin(app,auth) auth.register_admin(admin) admin.register(url.Url, url.UrlAdmin) admin.register(resource.Resource, resource.ResourceAdmin) admin.register(catalog.Catalog, catalog.CatalogAdmin) admin.register(processor.Processor, processor.ProcessorAdmin) admin.register(execution.Execution, execution.ExecutionAdmin) admin.setup() import psyc.rest import psyc.views catalog.register() #app.run(host='0.0.0.0', port=port, debug=True) http_server = WSGIServer(('', port), app)
import datetime from flask import request, redirect from flask_peewee.admin import Admin, ModelAdmin #, AdminPanel from flask_peewee.filters import QueryFilter from app import app, db from auth import auth from models import Councillor, Promise, Decision, Comment admin = Admin(app, auth, branding='KandiDaten Backend') class CouncillorAdmin(ModelAdmin): columns = ('council', 'first_name', 'last_name', 'party', 'canton') # foreign_key_lookups = {'party': 'name', 'canton': 'initials'} # filter_fields = ('name', 'active_date', 'party__name', 'canton__initials') class PromiseAdmin(ModelAdmin): columns = ( 'date', 'text', 'councillor', ) foreign_key_lookups = {'councillor': 'last_name'} exclude = ('created_date', ) class DecisionAdmin(ModelAdmin): columns = (