-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add admin panel #243
Merged
Merged
Add admin panel #243
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ce8843c
Add admin panel w/ ability to edit user first/last name and email.
toolness 4f32501
Merge branch 'master' into flask-admin
toolness 13128e8
add CSV export to admin UI
toolness e649dd6
Add more columns and form fields to user admin.
toolness e19d739
Add stats panel to admin UI.
toolness 58b7ef9
Add stats_index.html template.
toolness 6080735
Link to recently-filed flask-admin issues.
toolness 5c6f71a
Add optional HTTP Basic Auth protection for /admin/.
toolness 49ef2c6
Add unit tests for admin.py.
toolness 8e406c0
Document ADMIN_UI_USERS, ADMIN_UI_BASIC_AUTH in readme.
toolness File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from flask import redirect, request | ||
from flask_login import current_user | ||
from flask_security.utils import url_for_security | ||
from flask_admin import Admin | ||
from flask_admin.contrib.sqla import ModelView | ||
import flask_wtf | ||
from wtforms import TextField | ||
|
||
from .models import User, db | ||
|
||
class NoiModelView(ModelView): | ||
# The latest docs for flask-admin document a SecureForm class, but | ||
# this hasn't yet been added to the latest release, so we'll use | ||
# the "old" way of enabling CSRF support, documented here: | ||
# | ||
# http://flask-admin.readthedocs.org/en/v1.3.0/introduction/ | ||
form_base_class = flask_wtf.Form | ||
|
||
can_delete = False | ||
can_create = False | ||
|
||
def is_accessible(self): | ||
return current_user.is_authenticated() and current_user.is_admin() | ||
|
||
def inaccessible_callback(self, name, **kwargs): | ||
return redirect(url_for_security('login', next=request.url)) | ||
|
||
|
||
class UserModelView(NoiModelView): | ||
column_list = ('first_name', 'last_name', 'email') | ||
form_columns = column_list | ||
column_searchable_list = ('first_name', 'last_name', 'email') | ||
|
||
def scaffold_form(self): | ||
form_class = super(UserModelView, self).scaffold_form() | ||
form_class.email = TextField('Email') | ||
return form_class | ||
|
||
def init_app(app): | ||
admin = Admin(app, template_mode='bootstrap3') | ||
admin.add_view(UserModelView(User, db.session)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from app import csrf | ||
from flask import current_app, make_response, request, Response | ||
from flask import current_app, make_response, request, Response, url_for | ||
|
||
from hashlib import sha256 | ||
from base64 import b64encode | ||
|
@@ -10,6 +10,12 @@ def add_header(response): | |
Add a Content Security Policy (CSP) header to the given response. | ||
''' | ||
|
||
if request.path.startswith(url_for('admin.index')): | ||
# Ugh, flask-admin has inline scripts. Since only a handful of | ||
# users will have access to this view anyways, just disable CSP | ||
# for it. | ||
return response | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed pallets-eco/flask-admin#1135 so we hopefully can remove this someday. |
||
|
||
script_src = [ | ||
"'self'", | ||
"use.typekit.net" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% extends 'admin/master.html' %} | ||
|
||
{% block body %} | ||
{% if current_user.is_authenticated() and current_user.is_admin() %} | ||
<p>Welcome to the NoI admin panel.</p> | ||
{% else %} | ||
<p>You probably shouldn't be here.</p> | ||
{% endif %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% extends admin_base_template %} | ||
|
||
{% block brand %} | ||
<a class="navbar-brand" href="{{ url_for('views.activity') }}">{{ gettext("Network of Innovators") }}</a> | ||
{% endblock %} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More context on this at pallets-eco/flask-admin#1134.