Skip to content

Commit

Permalink
Dashboard: promote features in the right bar (#11287)
Browse files Browse the repository at this point in the history
* Dashboard: promote features in the right bar

Small logic to decide which feature to promote.
This is pretty simple for now, but it shows the pattern we are thinking about.

Required by readthedocs/ext-theme#103

* Improve logic from feedback

* Move partials to a better place

* Updates from feedback
  • Loading branch information
humitos committed Apr 22, 2024
1 parent fb90a34 commit 3912b7d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions readthedocs/projects/views/private.py
Expand Up @@ -40,6 +40,7 @@
from readthedocs.core.history import UpdateChangeReasonPostView
from readthedocs.core.mixins import ListViewWithForm, PrivateViewMixin
from readthedocs.core.notifications import MESSAGE_EMAIL_VALIDATION_PENDING
from readthedocs.core.permissions import AdminPermission
from readthedocs.integrations.models import HttpExchange, Integration
from readthedocs.invitations.models import Invitation
from readthedocs.notifications.models import Notification
Expand Down Expand Up @@ -113,6 +114,25 @@ def get_context_data(self, **kwargs):
# Alternatively, dynamically override super()-derived `project_list` context_data
# context[self.get_context_object_name(filter.qs)] = filter.qs

projects = AdminPermission.projects(user=self.request.user, admin=True)
n_projects = projects.count()
if n_projects < 3 and (timezone.now() - projects.first().pub_date).days < 7:
template_name = "example-projects.html"
elif (
n_projects
and not projects.filter(external_builds_enabled=True).exists()
):
template_name = "pull-request-previews.html"
elif (
n_projects
and not projects.filter(addons__analytics_enabled=True).exists()
):
template_name = "traffic-analytics.html"
else:
context["promotion"] = "security-logs.html"

context["promotion"] = f"projects/partials/dashboard/{template_name}"

return context

def validate_primary_email(self, user):
Expand Down

0 comments on commit 3912b7d

Please sign in to comment.