Skip to content
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

Traffic analytics: don't pass context if the feature isn't enabled #7740

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion readthedocs/projects/views/private.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,10 @@ class TrafficAnalyticsViewBase(ProjectAdminMixin, PrivateViewMixin, TemplateView
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
project = self.get_project()
enabled = self._is_enabled(project)
context.update({'enabled': enabled})
if not enabled:
return context

# Count of views for top pages over the month
top_pages = PageView.top_viewed_pages(project)
Expand All @@ -1096,7 +1100,6 @@ def get_context_data(self, **kwargs):
context.update({
'top_viewed_pages': top_viewed_pages,
'page_data': page_data,
'enabled': self._is_enabled(project),
Comment on lines 1101 to -1099
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this fail if we don't pass top_viewed_pages?

{% for page, count in top_viewed_pages %}

Maybe that HTML block needs to check for if enabled, don't you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When templates find null data, they just ignore it, in this case it goes to the empty block.

})

return context
Expand Down