Skip to content

Commit

Permalink
Update import error messages to suggest installing extras
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelhwilliams committed Jul 25, 2024
1 parent 2751c88 commit ee20ab9
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions doc/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ images Allows working with image data
export Supports downloading data in a variety of formats (eg TSV, JSON, etc)
rediscli Allows Flask-Admin to display a CLI for Redis
translation Supports translating Flask-Admin into a number of languages
all Installs support for all features
=========================== ================================================

Once you've chosen the extras you need, install Flask-Admin by specifying them like so::
Expand Down
5 changes: 4 additions & 1 deletion flask_admin/contrib/appengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
try:
import wtforms_appengine
except ImportError:
raise Exception('Please install wtforms_appengine in order to use appengine backend')
raise Exception(
'Could not import `wtforms-appengine`. '
'Enable `appengine` integration by installing `flask-admin[appengine]`'
)

from .view import ModelView
8 changes: 5 additions & 3 deletions flask_admin/contrib/fileadmin/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ def __init__(self, container_name, connection_string):
"""

if not BlockBlobService:
raise ValueError('Could not import Azure Blob Storage SDK. '
'You can install the SDK using '
'pip install azure-storage-blob')
raise ValueError(
'Could not import `azure.storage.blob`. '
'Enable `azure-blob-storage` integration '
'by installing `flask-admin[azure-blob-storage]`'
)

self._container_name = container_name
self._connection_string = connection_string
Expand Down
6 changes: 4 additions & 2 deletions flask_admin/contrib/fileadmin/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ def __init__(self, bucket_name, region, aws_access_key_id,
"""

if not s3:
raise ValueError('Could not import boto. You can install boto by '
'using pip install boto')
raise ValueError(
'Could not import `boto`. '
'Enable `s3` integration by installing `flask-admin[s3]`'
)

connection = s3.connect_to_region(
region,
Expand Down
5 changes: 4 additions & 1 deletion flask_admin/contrib/geoa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import geoalchemy2
import shapely
except ImportError:
raise Exception('Please install geoalchemy2 and shapely in order to use geoalchemy integration')
raise Exception(
'Could not import `geoalchemy2` or `shapely`. '
'Enable `geoalchemy` integration by installing `flask-admin[geoalchemy]`'
)

from .view import ModelView
5 changes: 4 additions & 1 deletion flask_admin/contrib/mongoengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
try:
import flask_mongoengine
except ImportError:
raise Exception('Please install flask-mongoengine in order to use mongoengine backend')
raise Exception(
'Could not import `flask-mongoengine`. '
'Enable `mongoengine` integration by installing `flask-admin[mongoengine]`'
)

from .view import ModelView
from .form import EmbeddedForm
5 changes: 4 additions & 1 deletion flask_admin/contrib/peewee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import peewee
import wtfpeewee
except ImportError:
raise Exception('Please install peewee and wtf-peewee packages in order to use peewee integration')
raise Exception(
'Could not import `peewee` or `wtfpeewee`. '
'Enable `peewee` integration by installing `flask-admin[peewee]`'
)

from .view import ModelView
5 changes: 4 additions & 1 deletion flask_admin/contrib/pymongo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
try:
import pymongo
except ImportError:
raise Exception('Please install pymongo in order to use pymongo integration')
raise Exception(
'Could not import `pymongo`. '
'Enable `pymongo` integration by installing `flask-admin[pymongo]`'
)

from .view import ModelView
5 changes: 4 additions & 1 deletion flask_admin/form/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ class MyForm(BaseForm):
"""
# Check if PIL is installed
if Image is None:
raise ImportError('PIL library was not found')
raise Exception(
'Could not import `PIL`. '
'Enable `images` integration by installing `flask-admin[images]`'
)

self.max_size = max_size
self.thumbnail_fn = thumbgen or thumbgen_filename
Expand Down
6 changes: 4 additions & 2 deletions flask_admin/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2356,8 +2356,10 @@ def _export_tablib(self, export_type, return_url):
Exports a variety of formats using the tablib library.
"""
if tablib is None:
flash(gettext('Tablib dependency not installed.'), 'error')
return redirect(return_url)
raise Exception(
'Could not import `tablib`. '
'Enable `export` integration by installing `flask-admin[export]`'
)

filename = self.get_export_name(export_type)

Expand Down

0 comments on commit ee20ab9

Please sign in to comment.