Skip to content

Commit

Permalink
show graph to permission insteed of superuser
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrKudy authored and PetrDlouhy committed Nov 20, 2021
1 parent 9f9ef70 commit bba18f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 6 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Add ``admin_tools_stats`` (the Django admin charts application) & ``django_nvd3`
...
'django.contrib.admin',
)

Install the ``nvd3==1.7.1`` and ``d3==3.3.13`` javascript libraries. For installation with ``django-bower`` see section `Installation of javascript libraries with django-bower`_.
Set library paths if they differ from the ``django-bower`` defaults::

Expand Down Expand Up @@ -157,7 +157,11 @@ Add following code to dashboard.py::
# Copy following code into your custom dashboard
# append following code after recent actions module or
# a link list module for "quick links"
graph_list = get_active_graph()
if context['request'].user.has_perm('admin_tools_stats.view_dashboardstats'):
graph_list = get_active_graph()
else:
graph_list = []

for i in graph_list:
kwargs = {}
kwargs['require_chart_jscss'] = True
Expand Down
5 changes: 4 additions & 1 deletion admin_tools_stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def get_dateformat(interval, chart_type):
return interval_dateformat_map[interval]


@method_decorator(user_passes_test(lambda u: u.is_superuser), name='dispatch')
@method_decorator(
user_passes_test(lambda u: u.has_perm('admin_tools_stats.view_dashboardstats')),
name='dispatch',
)
class ChartDataView(TemplateView):
template_name = 'admin_tools_stats/chart_data.html'

Expand Down
6 changes: 5 additions & 1 deletion demoproject/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ def init_with_context(self, context):
# Copy following code into your custom dashboard
# append following code after recent actions module or
# a link list module for "quick links"
graph_list = get_active_graph()
if context['request'].user.has_perm('admin_tools_stats.view_dashboardstats'):
graph_list = get_active_graph()
else:
graph_list = []

for i in graph_list:
kwargs = {}
kwargs['require_chart_jscss'] = True
Expand Down

0 comments on commit bba18f8

Please sign in to comment.