Code Monkey home page Code Monkey logo

flask-admin's Introduction

Flask-Admin

The project was recently moved into its own organization. Please update your references to [email protected]:flask-admin/flask-admin.git.

image

image

Introduction

Flask-Admin is a batteries-included, simple-to-use Flask extension that lets you add admin interfaces to Flask applications. It is inspired by the django-admin package, but implemented in such a way that the developer has total control of the look, feel and functionality of the resulting application.

Out-of-the-box, Flask-Admin plays nicely with various ORM's, including

It also boasts a simple file management interface and a redis client console.

The biggest feature of Flask-Admin is flexibility. It aims to provide a set of simple tools that can be used for building admin interfaces of any complexity. So, to start off with you can create a very simple application in no time, with auto-generated CRUD-views for each of your models. But then you can go further and customize those views & forms as the need arises.

Flask-Admin is an active project, well-tested and production ready.

Examples

Several usage examples are included in the /examples folder. Please add your own, or improve on the existing examples, and submit a pull-request.

To run the examples in your local environment:

1. Clone the repository::

      git clone https://github.com/flask-admin/flask-admin.git
      cd flask-admin

2. Create and activate a virtual environment::

      virtualenv env -p python3
      source env/Scripts/activate

3. Install requirements::

      pip install -r examples/sqla/requirements.txt

4. Run the application::

      python examples/sqla/run_server.py

Documentation

Flask-Admin is extensively documented, you can find all of the documentation at https://flask-admin.readthedocs.io/en/latest/.

The docs are auto-generated from the .rst files in the /doc folder. So if you come across any errors, or if you think of anything else that should be included, then please make the changes and submit them as a pull-request.

To build the docs in your local environment, from the project directory:

tox -e docs-html

And if you want to preview any .rst snippets that you may want to contribute, go to http://rst.ninjs.org/.

Installation

To install Flask-Admin, simply:

pip install flask-admin

Or alternatively, you can download the repository and install manually by doing:

git clone [email protected]:flask-admin/flask-admin.git
cd flask-admin
python setup.py install

Tests

Test are run with pytest. If you are not familiar with this package you can get some more info from their website.

To run the tests, from the project directory, simply:

pip install -r requirements-dev.txt
pytest

You should see output similar to:

.............................................
----------------------------------------------------------------------
Ran 102 tests in 13.132s

OK

For all the tests to pass successfully, you'll need Postgres & MongoDB to be running locally. For Postgres:

> psql postgres
CREATE DATABASE flask_admin_test;
\q

> psql flask_admin_test
CREATE EXTENSION postgis;
CREATE EXTENSION hstore;

If you're using Homebrew on MacOS, you might need this:

# install postgis
> brew install postgis

# set up postgresql user
> createuser -s postgresql
> brew services restart postgresql

You can also run the tests on multiple environments using tox.

3rd Party Stuff

Flask-Admin is built with the help of Bootstrap, Select2 and Bootswatch.

If you want to localize your application, install the Flask-BabelEx package.

You can help improve Flask-Admin's translations through Crowdin: https://crowdin.com/project/flask-admin

flask-admin's People

Contributors

abkfenris avatar alanhamlett avatar artemserga avatar bekab95 avatar bepetersn avatar bryhoyt avatar caffeinatedmike avatar cjmayo avatar dalia-21 avatar datran avatar ei-grad avatar iurisilvio avatar jacobsvante avatar jbochi avatar longhotsummer avatar michaelbukachi avatar mikelambert avatar mrjoes avatar nad2000 avatar pawl avatar petrus-jvrensburg avatar plaes avatar raz0r avatar rochacbruno avatar sealemar avatar singingwolfboy avatar sumpfgottheit avatar techniq avatar titaniumhocker avatar vtomy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-admin's Issues

FileField support

I have a SqlAlchemy model with a String field that holds a file path. I'd really like to force this to be a wtf FileField, but based on the docs / src, I don't see how this is possible. Am I missing something?

Thanks!

init_app() and unit testing

I'm using application factory, and as a result, using admin.init_app() method inside of create_app function. Unit tests create a new app app on each run, so that init_app gets called multiple times. The problem is that it raises on second run:
Exception: Flask-Admin is already associated with an application

Application fabrics are widely used for unittesting, and another extensions, like flask-sqlalchemy allow reinitialization with another app.
For now I hack this like this:
admin.app = None
admin.init_app(app)

Can not access current_user inside can_edit, can_view, etc

Instead of setting can_edit as a class-level variable (can_edit = True), I attempted to set it as a property so I can check the current_user (from Flask-Login) like so:

    @property
    def can_edit(self):
        if current_user.is_admin():
            return True
        ...

But I get the following error:

Traceback (most recent call last):
  File "c:\dev\expense-assist\packages\flask_failsafe.py", line 26, in wrapper
    return func(*args, **kwargs)
  File "c:\dev\expense-assist\application\__init__.py", line 21, in create_app
    configure_extensions(app)
  File "c:\dev\expense-assist\application\extensions.py", line 56, in configure_extensions
    manage.add_view(views.SupplierModelView(models.Supplier, db.session, name='Manage', category='Suppliers', endpoint='supplier'))
  File "c:\dev\expense-assist\packages\flask_admin\contrib\sqlamodel\view.py", line 191, in __init__
    super(ModelView, self).__init__(model, name, category, endpoint, url)
  File "c:\dev\expense-assist\packages\flask_admin\model\base.py", line 252, in __init__
    self.init_actions()
  File "c:\dev\expense-assist\packages\flask_admin\actions.py", line 53, in init_actions
    attr = getattr(self, p)
  File "c:\dev\expense-assist\application\admin\base.py", line 72, in can_delete
    return self.can_edit
  File "c:\dev\expense-assist\application\admin\base.py", line 46, in can_edit
    if current_user.is_admin():
  File "c:\dev\expense-assist\packages\werkzeug\local.py", line 336, in __getattr__
    return getattr(self._get_current_object(), name)
  File "c:\dev\expense-assist\packages\werkzeug\local.py", line 295, in _get_current_object
    return self.__local()
  File "c:\dev\expense-assist\packages\flask_login.py", line 403, in <lambda>
    current_user = LocalProxy(lambda: _request_ctx_stack.top.user)
AttributeError: 'NoneType' object has no attribute 'user'

It appears the code to find actions calling the can_edit property at startup and not during a request, which current_user needs -
https://github.com/mrjoes/flask-admin/blob/master/flask_admin/actions.py#L53

Allow searching integer values

Apparently you can't search numeric fields. Seems unreasonable to me, so it would be really nice to be able to jump to a certain primary key.

Composite primary keys

Hi,

First off: Many thanks for an awesome piece of software!

I've got a data model set-up in SQLAlchemy. Many of the tables use a composite primary key (orgid : Int, id : Int):

class User...:
    orgid = db.Column(db.Integer, primary_key=True)
    id = db.Column(db.Integer, db.Sequence('userId_seq'), primary_key=True)

Whenever i try to edit a user in this model i get a:

InvalidRequestError: Incorrect number of values in identifier to formulate primary key for query.get(); primary key columns are 'users.orgid','users.id'.

This threads back to line 501 in sqlamodel/view.py, which just returns an id.

Are composite keys supported by flask-admin?

Many thanks,
Tobias

TypeError: html_params() keywords must be strings

Running the "simple.py"-SqlAlchemy-example ends up in a TypeError
when clicking "Create" on any model.

TypeError: html_params() keywords must be strings

Traceback (most recent call last):
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/app.py", line 1701, in call
return self.wsgi_app(environ, start_response)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/app.py", line 1344, in dispatch_request
return self.view_functionsrule.endpoint
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/base.py", line 36, in inner
return f(self, *_kwargs)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/base.py", line 36, in inner
return f(self, *_kwargs)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/base.py", line 36, in inner
return f(self, *_kwargs)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/model/base.py", line 803, in create_view
return_url=return_url)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/base.py", line 177, in render
return render_template(template, *_kwargs)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/templating.py", line 125, in render_template
context, ctx.app)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask/templating.py", line 107, in _render
rv = template.render(context)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/jinja2/environment.py", line 894, in render
return self.environment.handle_exception(exc_info, True)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/model/create.html", line 2, in top-level template code
{% import 'admin/lib.html' as lib with context %}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/master.html", line 19, in top-level template code
{% block page_body %}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/master.html", line 69, in block "page_body"
{% block body %}{% endblock %}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/model/create.html", line 23, in block "body"
{% call lib.form_tag() %}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/lib.html", line 109, in template
{{ caller() }}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/model/create.html", line 24, in template
{{ lib.render_form_fields(form) }}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_admin/templates/admin/lib.html", line 77, in template
{{ form.hidden_tag() if form.hidden_tag is defined }}
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/flask_wtf/form.py", line 113, in hidden_tag
rv.append(unicode(field))
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/wtforms/fields/core.py", line 116, in unicode
return self()
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/wtforms/fields/core.py", line 139, in call
return self.widget(self, *_kwargs)
File "/Users/do/workspace/lessons/flask-admin/env/lib/python2.6/site-packages/wtforms/widgets/core.py", line 124, in call
return HTMLString('<input %s>' % self.html_params(name=field.name, *_kwargs))
TypeError: html_params() keywords must be strings

Installed Libraries (all installed with PIP):
Flask==0.9
Flask-Admin==1.0.2
Flask-SQLAlchemy==0.16
Flask-WTF==0.8
Jinja2==2.6
SQLAlchemy==0.7.8
WTForms==1.0.2
Werkzeug==0.8.3
flask-csrf==0.9.2
wsgiref==0.1.2

Small display issue

Simple but annoying

  1. Add any filter in model's list
  2. Remove those filter
  3. Button "Apply" is still here!

Access to an instance during create/update_model

There are some situations when one need do some actions after (or better during creation/saving of a new model).

For example, I need to generate a list of allowed endpoints for fresh or changed Role object.

With current behavior I have to copy the whole method code from the base class:

    def update_model(self, form, model):
        try:
            form.populate_obj(model)
            self.session.flush()

            self.update_role_allowed_endpoints(form, model)  # <------

            self.session.commit()
            return True
        except Exception, ex:
            flash(gettext('Failed to update model. %(error)s', error=str(ex)), 'error')
            return False

    def create_model(self, form):
        # Copypasted from base class to be able to modify model instance after creation
        try:
            model = self.model()
            form.populate_obj(model)
            self.session.add(model)
            self.session.flush()

            self.update_role_allowed_endpoints(form, model) # <-------

            self.session.commit()
            return True
        except Exception, ex:
            flash(gettext('Failed to create model. %(error)s', error=str(ex)), 'error')
            return False

Take note, changes take place in the middle of transaction, so any exceptions in my method do not break data consistency.

I propose to add 'model_changed' class attribute (a callable which takes a form and a model). And call it before transaction commit.

Different admin sites for blueprints?

I ran into an issue where I have an application that uses blueprints for the multiple sub-apps it serves. I wanted to make an admin page specifically for each blueprint but ran into an issue trying to create multiple Admin objects using the same app. Any suggestions?

I've looked through the source and the offending code is in the add_view function in base.py- it is registering the same view twice for the app. A simple fix would be to check if the blueprint is already registered prior to registering.

Can not access current_user inside can_edit, can_view, etc

Instead of setting can_edit as a class-level variable (can_edit = True), I attempted to set it as a property so I can check the current_user (from Flask-Login) like so:

    @property
    def can_edit(self):
        if current_user.is_admin():
            return True
        ...

But I get the following error:

Traceback (most recent call last):
  File "c:\dev\expense-assist\packages\flask_failsafe.py", line 26, in wrapper
    return func(*args, **kwargs)
  File "c:\dev\expense-assist\application\__init__.py", line 21, in create_app
    configure_extensions(app)
  File "c:\dev\expense-assist\application\extensions.py", line 56, in configure_extensions
    manage.add_view(views.SupplierModelView(models.Supplier, db.session, name='Manage', category='Suppliers', endpoint='supplier'))
  File "c:\dev\expense-assist\packages\flask_admin\contrib\sqlamodel\view.py", line 191, in __init__
    super(ModelView, self).__init__(model, name, category, endpoint, url)
  File "c:\dev\expense-assist\packages\flask_admin\model\base.py", line 252, in __init__
    self.init_actions()
  File "c:\dev\expense-assist\packages\flask_admin\actions.py", line 53, in init_actions
    attr = getattr(self, p)
  File "c:\dev\expense-assist\application\admin\base.py", line 72, in can_delete
    return self.can_edit
  File "c:\dev\expense-assist\application\admin\base.py", line 46, in can_edit
    if current_user.is_admin():
  File "c:\dev\expense-assist\packages\werkzeug\local.py", line 336, in __getattr__
    return getattr(self._get_current_object(), name)
  File "c:\dev\expense-assist\packages\werkzeug\local.py", line 295, in _get_current_object
    return self.__local()
  File "c:\dev\expense-assist\packages\flask_login.py", line 403, in <lambda>
    current_user = LocalProxy(lambda: _request_ctx_stack.top.user)
AttributeError: 'NoneType' object has no attribute 'user'

It appears the code to find actions calling the can_edit property at startup and not during a request, which current_user needs -
https://github.com/mrjoes/flask-admin/blob/master/flask_admin/actions.py#L53

Use select field for enum's

ENUM columns (supported by at least SQLAlchemy/Postgres) are currently represented as simple text input fields.

It seems that checking column types doesn't really work (currently column.type returns VARCHAR(...)), so a way to define user-defined editors would be needed as a workaround.

Multiple actions in lists

For a project of mine, I need to select multiple items to carry out an action (in my case consolidate duplicate records).

I've started implementing a generalised format so other actions can be added by individuals (inspired by actions in Django with some implementation details cribbed from flask-peewee's admin module).

I've started with delete selected. I plan on cleaning it up for more general use but wanted to open it up to feedback before I go completely down the path.

https://github.com/beyondwords/flask-admin/commit/c7a3ba94fa425610b41df8b3fd59d6128bf7a744

Please contribute any comments on architecture.

  • An action is called with the BaseModelView sub-class, request, and id_list
  • The action must have label specified for the drop-down list
  • The action must check for permissions is_accessible, can_delete etc.
  • The action can either return a redirect/rendered page or None and use a flash message to return to the list
  • The action can be a simple function or a class instance with __call__ implemented

TypeError: macro 'render_form' takes not more than 2 argument(s)

When I attempt to create a new object, I get TypeError: macro 'render_form' takes not more than 2 argument(s).
Code implementing Flask-AdminEx: http://pastebin.com/bWr0K7Le
Traceback: http://pastebin.com/GpMBV9iV
Running Flask-AdminEx 0.0.1 8679ea3 on Python 2.7.2 on virtualenv 1.7 on OS X Snow Leopard 10.6.8.
Installed packages:

Flask-AdminEx==0.0.1
Flask-Bcrypt==0.5.2
Flask-SQLAlchemy==0.15
Flask-WTF==0.6
Jinja2==2.6
SQLAlchemy==0.7.5
WTForms==1.0.1
Werkzeug==0.8.3
py-bcrypt==0.2
wsgiref==0.1.2

form_override relationship property as HiddenField raises TypeError

I have a case where I have a parent/child entity relationship between an Invoice (parent) and LineItems (child).

class Invoice(db.Model, BaseMixin, AuditMixin):
    id = Column(Integer, primary_key=True)
    line_items = relationship('LineItem', backref=backref('invoice'))
    ....

class LineItem(db.Model, BaseMixin, AuditMixin):
    id = Column(Integer, primary_key=True)
    invoice_id = Column(Integer, ForeignKey('invoice.id'))
    # invoice = relationship from Invoice
    ...

When creating new line items, I pass the invoice_id explicitly and thus would like to set the id via a hidden input instead of having it a SelectList/etc.

class LineItemView(ParentModelView):
    form_overrides = dict(invoice=wtforms.HiddenField)
    ...

I was using 1.0.1 and had no issues, but now I get the following error:
TypeError: __init__() got an unexpected keyword argument 'allow_blank'

It appears with the new model_form_converter change, the converter explicitly adds the allow_blank keyword argument without checking whether the overridden type supports it.
https://github.com/mrjoes/flask-admin/blob/master/flask_admin/contrib/sqlamodel/form.py

Is there a better way this should be handled?

Import error trying to use sqlamodel

I'm unable to use the sqlamodel extension due to an import error. Please see below. Perhaps a packaging problem?

from flask.ext.adminex.ext.sqlamodel import ModelBase

File "/Users/andy/.virtualenvs/marty/lib/python2.7/site-packages/flask/exthook.py", line 86, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named flask.ext.adminex.ext

Possible typo in admin.base Default View docs

Following this example from the docs

class MyHomeView(AdminIndexView):
    @expose('/')
    def index(self):
        return render_template('adminhome.html')

admin = Admin(index_view=MyHomeView)

will eventually raise this error

TypeError: unbound method create_blueprint() must be called with MyHomeView instance as first argument (got Admin instance instead)

The passed in index_view is expected to be an instance not a class. Its not clear to me if this is a typo in the docs or if this line of code

self.index_view = index_view or AdminIndexView(endpoint=endpoint, url=url)

should instantiate index_view if its a class object.

Easier way to manually apply column filters

I have a situation where I've added a column filter to a view and would like to manually apply it in a request. For example, with the following view:

class LineItemView(ModelView):
    column_filters = [FilterEqual(models.LineItem.invoice_id, "parent")]

to apply the filter via url, I need to use something like /admin/lineitem/?flt0_0={{request.args["id"]}}, which is confusing, and reliant on knowing the index position of the filters you want to apply.

Since this is an instance filter with a name ("parent") and a specific filter (FilterEqual) instead of a genearl column name (ex. ['foo']), it would be nice if you could apply the filter like this:
/admin/lineitem/?flt_admin={{request.args["id"]}}

For the cases where just a field name is used, maybe something like:
/admin/lineitem/?flt_admin_eq={{request.args["id"]}}
/admin/lineitem/?flt_admin_ne={{request.args["id"]}}
/admin/lineitem/?flt_admin_gt={{request.args["id"]}}
/admin/lineitem/?flt_admin_lt={{request.args["id"]}}

Thoughts?

List columns, rename columns, etc.

Going through the examples and trying to use some of my apps into it. I was wondering if we could actually make list_columns, rename_columns, etc. more into options instead of customization?

For example, I want to be able to use the normal sqlalchemy interface, but according to the documentation I would need to create a custom interface in order to utilize the list_columns functionality. I would not be able to use the sqlalchemy interface.

As a workaround I made it so that I could pass those customization when I first create the View. Would this be the best way to do it? Or should we come up with some sort of API to do such a thing?

translation issues

flask-admin uses babel domains, which are not yet on the official flask-babel repo ( i think mrjoes sent a pull request 3 months ago)
as a result of that, flask-admin currently cannot be translated, unless you fork, or clone/use mr joes flask-babel fork or wait for flask-babel to pull mrjoes commits.

this dependency / issue isnt documented anywhere, and flask-admin does not complain about the them not being implemented, and instead defaults to the currently set strings.

tl;dr : why implement it that way, ( dependency on not yet pulled to official flask-babel repo ) ?

thanks.

No way to add converters to AdminModelConverter

Currently I’m having to rewrite ModelView.scaffold_form in a subclass to add more converters for sqlamodel. I’m not sure what the best place to specify project specific converters would be. Any thoughts?

Required fields for many-to-many relationships

Hi, I tried using flask-admin for a many-to-many relationship defined in SQLAlchemy like so: http://docs.sqlalchemy.org/en/rel_0_7/orm/tutorial.html#building-a-many-to-many-relationship

The UI works great, however because the fields are designated as "required", on a blank database I am not able to use the UI to add any rows to the database. The forms to add rows in both tables will give an error "This field is required.", and the select box is empty because the other table is still empty. What should I do?

primary key is not shown in ModelView

not sure whether this is a bug report or just a question.

regarding the visibility of primary keys.

working:
I have a table (Country) with automatic integer primary key and a table (Country_division) referring to it. When I insert a country_division in its table, the interface allows me to select a country. I never see the value of the primary key, but it works.

not working:
I have a table (rank) with string primary key that is manually assigned. as above, I cannot see the column in the interface, but this is now a problem, because I can't specify the key manually.

since I'm still giving form to the database, I can consider falling back to automatic integer primary keys.

Float: TypeError: a float is required

class Test(db.Model):
value = db.Column(db.Float, default=0.0, nullable=True)

when i use this with flask-admin as following:
admin.add_view(sqlamodel.ModelView(Test, db.session))

when i create a Test, it raise:

File "E:\bin\Python27\lib\site-packages\wtforms\fields\core.py", line 539, in _value

return format % self.data


TypeError: a float is required

here, type(self.data) is class 'sqlalchemy.schema.ColumnDefault'
and format is "%0.2f"

SQLA example doesn't work out of the box

When trying to use sqla's simple.py example bundled with flask-adminex, I get an error when displaying a ModelView with a non-empty model.
The error is UndefinedError: 'get_pk_value' is undefined

Process:

  • Run examples/sqla/simple.py after removing any examples/sqla/test.sqlite
  • Go to user view
  • Add a user
  • UndefinedError: 'get_pk_value' is undefined

From here you can:

  • Go back to admin
  • Go to post view
  • Add a post (you can see on the form that the user you just created is selectable)
  • UndefinedError: 'get_pk_value' is undefined

Because user is correctly added to the sqlite base, I think this is a typo or something.
Ismael.

ImportError: No module named flask.ext.adminex.model

When I attempt to run from flask.ext.adminex.ext.sqlamodel import ModelView, I get the following:

Traceback (most recent call last):
  File "run.py", line 19, in <module>
    from metacraft.views.admin import adminex
  File "/Users/natan/Development/metacraft/metacraft/views/admin.py", line 5, in <module>
    from flask.ext.adminex.ext.sqlamodel import ModelView
  File "/Users/natan/.virtualenvs/metacraft/lib/python2.7/site-packages/Flask_AdminEx-0.0.1-py2.7.egg/flask_adminex/ext/sqlamodel/__init__.py", line 1, in <module>
    from .view import ModelView
  File "/Users/natan/.virtualenvs/metacraft/lib/python2.7/site-packages/Flask_AdminEx-0.0.1-py2.7.egg/flask_adminex/ext/sqlamodel/view.py", line 14, in <module>
    from flask.ext.adminex.model import BaseModelView
  File "/Users/natan/.virtualenvs/metacraft/lib/python2.7/site-packages/flask/exthook.py", line 86, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named flask.ext.adminex.model

Running Python 2.7.2 with virtualenv 1.7 on OS X Snow Leopard 10.6.8 with the following packages:

Flask-AdminEx==0.0.1
Flask-Bcrypt==0.5.2
Flask-SQLAlchemy==0.15
Flask-WTF==0.6
Jinja2==2.6
SQLAlchemy==0.7.5
WTForms==1.0.1
Werkzeug==0.8.3
py-bcrypt==0.2
wsgiref==0.1.2```

FileField support

I have a SqlAlchemy model with a String field that holds a file path. I'd really like to force this to be a wtf FileField, but based on the docs / src, I don't see how this is possible. Am I missing something?

Thanks!

WTForms 1.0.2 support

New version WTForms (1.0.2) makes Flask-admin crashed with error:

File "/home/klen/Projects/tweetchi/base/core/admin.py", line 10, in <module>
  admin.add_model(Alembic, AlembicView)
File "/home/klen/Projects/tweetchi/base/core/ext.py", line 38, in add_model
  self.add_view(view(model, db.session))
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/flask_admin/contrib/sqlamodel/view.py", line 141, in __init__
  super(ModelView, self).__init__(model, name, category, endpoint, url)
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/flask_admin/model/base.py", line 222, in __init__
  self._refresh_cache()
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/flask_admin/model/base.py", line 234, in _refresh_cache
  self._create_form_class = self.get_create_form()
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/flask_admin/model/base.py", line 419, in get_create_form
  return self.get_form()
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/flask_admin/model/base.py", line 411, in get_form
  return self.scaffold_form()
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/flask_admin/contrib/sqlamodel/view.py", line 367, in scaffold_form
  converter=form.AdminModelConverter(self))
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/wtforms/ext/sqlalchemy/orm.py", line 303, in model_form
  converter)
File "/home/klen/Projects/tweetchi/.env/local/lib/python2.7/site-packages/wtforms/ext/sqlalchemy/orm.py", line 241, in model_fields
  field_args.get(name), db_session)
TypeError: convert() takes exactly 5 arguments (6 given)

With WTForms==1.0.1 it works as fine.

How to custom form?

for example, if I have model as following:
class T(db.Model):
a = db.column()
b = db.column()
c = db.column()
d = db.column()
e = db.column()

In admin, when i create, i only want the create form show a and b, how to do it?

Thanks.

link to non_admin part

I'm new to Flask so be patient reading and explicit writing!

how do I link the admin pages to the root of the normal Flask interface?
can I have this link in the name of the app?

I tried
admin = Admin(app, name='<a href="/">ghini</a>')
and not surprisingly, it did not work.

Quickstart's Model Views section extremely confusing

When going through the Model Views part of the quickstart, I ran into multiple issues of wrong variables:

  • from flask.ext.sqlalchemy import db doesn't exist (I assume it should be imported from app itself)
  • ModelView vs ModelBase vs ModelBaseView confusion
  • UserView vs MyView confusion

Also, one probably shouldn't use phrase 'very easy' when talking about adding new database model handlers ;)

Configuring App causes Admin UI to 404?

Using the initial example in the tutorial works. But if I do any configuration of the application, the admin UI will 404. E.g.

from flask import Flask
from flask.ext.admin import Admin

app = Flask(__name__)
app.config.from_pyfile('testapp.cfg')

admin = Admin(app)

app.run()

If I navigate to http://localhost:5000/admin/, I get a 404. Comment out the app.config ... line and it works fine. Doesn't matter what I put in the config file

I'm using Flask 0.9 and Flask-Admin 1.0.1

In default create and edit forms, Cancel button is not displayed

Regression in cade92d

Issue can be fixed by

diff --git flask_admin/model/base.py flask_admin/model/base.py
index 91ea697..8368899 100644
--- flask_admin/model/base.py
+++ flask_admin/model/base.py
@@ -806,7 +806,7 @@ class BaseModelView(BaseView, ActionsMixin):

         return self.render(self.create_template,
                            form=form,
-                           return_url=return_url)
+                           cancel_url=return_url)

     @expose('/edit/', methods=('GET', 'POST'))
     def edit_view(self):
@@ -835,7 +835,7 @@ class BaseModelView(BaseView, ActionsMixin):

         return self.render(self.edit_template,
                                form=form,
-                               return_url=return_url)
+                               cancel_url=return_url)

     @expose('/delete/', methods=('POST',))
     def delete_view(self):

OR

diff --git flask_admin/templates/admin/model/create.html flask_admin/templates/admin/model/create.html
index be1a044..d07afc9 100644
--- flask_admin/templates/admin/model/create.html
+++ flask_admin/templates/admin/model/create.html
@@ -22,7 +22,7 @@

   {% call lib.form_tag() %}
       {{ lib.render_form_fields(form) }}
-      {{ lib.render_form_buttons(cancel_url, extra()) }}
+      {{ lib.render_form_buttons(return_url, extra()) }}
   {% endcall %}
 {% endblock %}

diff --git flask_admin/templates/admin/model/edit.html flask_admin/templates/admin/model/edit.html
index ea03875..74dabc7 100644
--- flask_admin/templates/admin/model/edit.html
+++ flask_admin/templates/admin/model/edit.html
@@ -9,7 +9,7 @@
 {% block body %}
     {% call lib.form_tag() %}
         {{ lib.render_form_fields(form) }}
-        {{ lib.render_form_buttons(cancel_url) }}
+        {{ lib.render_form_buttons(return_url) }}
     {% endcall %}
 {% endblock %}

PyPI?

Any plans to publish to PyPI? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.