Exemple #1
0
from flask import Flask
from flask.ext.superadmin import Admin
import sqlsoup

#db = sqlsoup.SQLSoup("mysql://*****:*****@db4free.net/codecalltut")
db = sqlsoup.SQLSoup("mysql://root:@localhost/codecalltut")
users = db.tblprereg.all()

app = Flask(__name__)
admin = Admin(app)

if __name__ == "__main__":
    app.run(debug=True)
Exemple #2
0
    user_id = db.Column(db.Integer(), db.ForeignKey(User.id))
    user = db.relationship(User, backref='posts')

    def __unicode__(self):
        return self.title


# Flask views
@app.route('/')
def index():
    return '<a href="/admin/">Click me to get to Admin!</a>'


if __name__ == '__main__':
    # Create admin
    admin = Admin(app, 'Simple Models')

    admin.locale_selector(get_locale)

    # Add views
    admin.register(User, session=db.session)
    admin.register(Post, session=db.session)

    # Create DB
    db.create_all()

    # Start app
    app.debug = True
    app.run('0.0.0.0', 8000)
Exemple #3
0
    @expose('/')
    def index(self):
        return self.render('admin/index.html')

    def is_accessible(self):
        return current_user.is_authenticated() and current_user.is_admin()


# Create customized index view class
class MyAdminIndexView(AdminIndexView):
    def is_accessible(self):
        return current_user.is_authenticated() and current_user.is_admin()


#admin
admin = Admin(app, 'Auth', index_view=MyAdminIndexView())
#admin = Admin(app, 'Simple Models')

# Add view
#admin.add_view(sqlamodel.ModelAdmin(User, session=db.session))
#admin.add_view(MyModelView(Friend, db.session))
#admin.add_view(MyModelView(Ask, db.session))

admin.register(User, session=db.session)
admin.register(Ask, session=db.session)
admin.register(Friend, session=db.session)
admin.register(Review, session=db.session)
admin.register(ContactUs, session=db.session)
admin.register(Recommendation, session=db.session)
admin.register(SendAsk, session=db.session)
admin.register(ReplyRecommendation, session=db.session)
Exemple #4
0
# -*- coding: utf-8 -*-
"""
All of our extensions are initialized here. They are registered in
app.py:register_extensions upon app creation
"""
from flask.ext.sqlalchemy import SQLAlchemy

db = SQLAlchemy()

from flask.ext.migrate import Migrate

migrate = Migrate()

from flask.ext.debugtoolbar import DebugToolbarExtension

debug_toolbar = DebugToolbarExtension()

from flask.ext.bcrypt import Bcrypt

bcrypt = Bcrypt()

from flask.ext.superadmin import Admin

admin = Admin(name="Rest Player Generator (RPG)")
Exemple #5
0
    {'WWW-Authenticate': 'Basic realm="Login Required"'})

def is_authenticated():
    auth = flask.request.authorization
    return auth and check_auth(auth.username, auth.password)


class ModelAdmin(_ModelAdmin):

    def is_accessible(self):
        return is_authenticated()

    def _handle_view(self, name, *args, **kwargs):
        if not self.is_accessible():
            return authenticate()


class AdminIndexView(_AdminIndexView):
    @expose('/')
    def index(self):
        if not is_authenticated():
            return authenticate()
        return super(AdminIndexView, self).index()


admin = Admin(app, index_view=AdminIndexView())
admin.register(User, admin_class=ModelAdmin, session=db.session)

if __name__ == '__main__':
    app.run()
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from flask.ext.superadmin import Admin, AdminIndexView
from flask.ext.superadmin.model.backends.mongoengine import ModelAdmin
from flask.ext.login import current_user

from webapp import app
from .models import User, DummyContent


# Create customized model view class
class MyModelView(ModelAdmin):
    def is_accessible(self):
        return current_user.is_authenticated()


# Create customized index view class
class MyAdminIndexView(AdminIndexView):
    def is_accessible(self):
        return current_user.is_authenticated()


# Create admin
admin = Admin(app, 'Backoffice', index_view=MyAdminIndexView())

# Add view
admin.add_view(MyModelView(User))
admin.add_view(MyModelView(DummyContent))
class SecuredAdminIndexView(AdminIndexView):
    def is_accessible(self):
        admin = current_user.has_role("admin")
        if not admin:
            flask.flash("You do not have permission to view this site")
            logout_user()

        return admin


class SecuredModelView(ModelAdmin):
    def is_accessible(self):
        return current_user.has_role("admin")


admin = Admin(app, app.config["PROJECT_NAME"])

model_classes = []
if app.config.get("AUTOGENERATE_MODEL_ADMIN", True):
    # We have to hook in to the db.Model metaclass to keep track of any table
    # classes we define
    class _AdminBoundDeclarativeMeta(sqlalchemy._BoundDeclarativeMeta):
        def __init__(self, name, bases, d):
            super(self.__class__, self).__init__(name, bases, d)
            if name != "Model":
                model_classes.append(self)

    db.Model = sqlalchemy.declarative_base(
        cls=sqlalchemy.Model,
        name="Model",
        metaclass=_AdminBoundDeclarativeMeta)
from flask import Flask
from flask.ext.superadmin import Admin, model, BaseView, expose
from models import *


class MyView(BaseView):
    def is_accessible(self):
        return login.current_user.is_authenticated()
    @expose('/')
    def index():
        return 'asdasdasdasd'

admin = Admin(app, name="Copylighter")


class UserModel(model.ModelAdmin):
	list_display = ('id','name','email')
	form_widget_args = {
        'name': {
            'readonly': True
        },
    }
	
class NoteModel(model.ModelAdmin):
	list_display = ('id', 'content','created_at',)
	column_searchable_list = ('content', 'id')
	fields = ('created_at','tags','content', 'isArchived', 'isSecret')

class NoteRefModel(model.ModelAdmin):
	list_display = ('id', 'note_id','user_id','created_at')