Repository navigation
feat: added banner message for survey report #33633
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
Changes from 17 commits
21ddede
d02d5f1
4530e02
c42c3c3
9778c83
79effe9
415bcee
a2c98dc
9a6ef63
2b65458
789d631
aab11ce
519e4da
a47b175
ba47acc
a8cdee5
237515a
1087363
28e3fb5
c4f65ec
8c56953
a32f3e4
5d6c531
c129b80
718b6f5
4cc231c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| {% load i18n static %}<!DOCTYPE html> | ||
| {% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %} | ||
| <html lang="{{ LANGUAGE_CODE|default:"en-us" }}" dir="{{ LANGUAGE_BIDI|yesno:'rtl,ltr,auto' }}"> | ||
| <head> | ||
| <title>{% block title %}{% endblock %}</title> | ||
| <link rel="stylesheet" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}"> | ||
| {% block dark-mode-vars %} | ||
| <link rel="stylesheet" href="{% static "admin/css/dark_mode.css" %}"> | ||
| <script src="{% static "admin/js/theme.js" %}" defer></script> | ||
| {% endblock %} | ||
| {% if not is_popup and is_nav_sidebar_enabled %} | ||
| <link rel="stylesheet" href="{% static "admin/css/nav_sidebar.css" %}"> | ||
| <script src="{% static 'admin/js/nav_sidebar.js' %}" defer></script> | ||
| {% endif %} | ||
| {% block extrastyle %}{% endblock %} | ||
| {% if LANGUAGE_BIDI %}<link rel="stylesheet" href="{% block stylesheet_rtl %}{% static "admin/css/rtl.css" %}{% endblock %}">{% endif %} | ||
| {% block extrahead %}{% endblock %} | ||
| {% block responsive %} | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <link rel="stylesheet" href="{% static "admin/css/responsive.css" %}"> | ||
| {% if LANGUAGE_BIDI %}<link rel="stylesheet" href="{% static "admin/css/responsive_rtl.css" %}">{% endif %} | ||
| {% endblock %} | ||
| {% block blockbots %}<meta name="robots" content="NONE,NOARCHIVE">{% endblock %} | ||
| <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> | ||
| </head> | ||
|
|
||
| <body class="{% if is_popup %}popup {% endif %}{% block bodyclass %}{% endblock %}" | ||
| data-admin-utc-offset="{% now "Z" %}"> | ||
| <!-- Container --> | ||
| <div id="container"> | ||
|
|
||
| {% if not is_popup %} | ||
| <!-- Header --> | ||
| {% block header %} | ||
| <div id="header"> | ||
| <div id="branding"> | ||
| {% block branding %}{% endblock %} | ||
| </div> | ||
| {% block usertools %} | ||
| {% if has_permission %} | ||
| <div id="user-tools"> | ||
| {% block welcome-msg %} | ||
| {% translate 'Welcome,' %} | ||
| <strong>{% firstof user.get_short_name user.get_username %}</strong>. | ||
| {% endblock %} | ||
| {% block userlinks %} | ||
| {% if site_url %} | ||
| <a href="{{ site_url }}">{% translate 'View site' %}</a> / | ||
| {% endif %} | ||
| {% if user.is_active and user.is_staff %} | ||
| {% url 'django-admindocs-docroot' as docsroot %} | ||
| {% if docsroot %} | ||
| <a href="{{ docsroot }}">{% translate 'Documentation' %}</a> / | ||
| {% endif %} | ||
| {% endif %} | ||
| {% if user.has_usable_password %} | ||
| <a href="{% url 'admin:password_change' %}">{% translate 'Change password' %}</a> / | ||
| {% endif %} | ||
| <form id="logout-form" method="post" action="{% url 'admin:logout' %}"> | ||
| {% csrf_token %} | ||
| <button type="submit">{% translate 'Log out' %}</button> | ||
| </form> | ||
| {% include "admin/color_theme_toggle.html" %} | ||
| {% endblock %} | ||
| </div> | ||
| {% endif %} | ||
| {% endblock %} | ||
| {% block nav-global %}{% endblock %} | ||
| </div> | ||
| {% endblock %} | ||
| <!-- END Header --> | ||
| {% block nav-breadcrumbs %} | ||
| <nav aria-label="{% translate 'Breadcrumbs' %}"> | ||
| {% block breadcrumbs %} | ||
| <div class="breadcrumbs"> | ||
| <a href="{% url 'admin:index' %}">{% translate 'Home' %}</a> | ||
| {% if title %} › {{ title }}{% endif %} | ||
| </div> | ||
| {% endblock %} | ||
| </nav> | ||
| {% endblock %} | ||
| {% endif %} | ||
| {% block survey_report_banner %}{% endblock %} | ||
|
Asespinel marked this conversation as resolved.
Resolved
|
||
| <div class="main" id="main"> | ||
| {% if not is_popup and is_nav_sidebar_enabled %} | ||
| {% block nav-sidebar %} | ||
| {% include "admin/nav_sidebar.html" %} | ||
| {% endblock %} | ||
| {% endif %} | ||
| <main id="content-start" class="content" tabindex="-1"> | ||
| {% block messages %} | ||
| {% if messages %} | ||
| <ul class="messagelist">{% for message in messages %} | ||
| <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message|capfirst }}</li> | ||
| {% endfor %}</ul> | ||
| {% endif %} | ||
| {% endblock messages %} | ||
| <!-- Content --> | ||
| <div id="content" class="{% block coltype %}colM{% endblock %}"> | ||
| {% block pretitle %}{% endblock %} | ||
| {% block content_title %}{% if title %}<h1>{{ title }}</h1>{% endif %}{% endblock %} | ||
| {% block content_subtitle %}{% if subtitle %}<h2>{{ subtitle }}</h2>{% endif %}{% endblock %} | ||
| {% block content %} | ||
| {% block object-tools %}{% endblock %} | ||
| {{ content }} | ||
| {% endblock %} | ||
| {% block sidebar %}{% endblock %} | ||
| <br class="clear"> | ||
| </div> | ||
| <!-- END Content --> | ||
| {% block footer %}<div id="footer"></div>{% endblock %} | ||
| </main> | ||
| </div> | ||
| </div> | ||
| <!-- END Container --> | ||
|
|
||
| <!-- SVGs --> | ||
| <svg xmlns="http://www.w3.org/2000/svg" class="base-svgs"> | ||
| <symbol viewBox="0 0 24 24" width="1rem" height="1rem" id="icon-auto"><path d="M0 0h24v24H0z" fill="currentColor"/><path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2V4a8 8 0 1 0 0 16z"/></symbol> | ||
| <symbol viewBox="0 0 24 24" width="1rem" height="1rem" id="icon-moon"><path d="M0 0h24v24H0z" fill="currentColor"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol> | ||
| <symbol viewBox="0 0 24 24" width="1rem" height="1rem" id="icon-sun"><path d="M0 0h24v24H0z" fill="currentColor"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol> | ||
| </svg> | ||
| <!-- END SVGs --> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """ | ||
| This is the survey report contex_processor modules | ||
|
|
||
| This is meant to determine the visibility of the survey report banner | ||
| across all admin pages in case a survey report has not been generated | ||
|
|
||
| """ | ||
|
|
||
| from datetime import datetime | ||
| from dateutil.relativedelta import relativedelta # for months test | ||
| from .models import SurveyReport | ||
|
|
||
|
|
||
| def admin_extra_context(request): | ||
|
Contributor
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. Random thought (completely optional): Is it easy to check if this request is for an admin view and return
Contributor
Author
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. I implemented the change requested with this change we should revert back the query counts by 1 in all the tests? Or just on particular ones?
Member
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. We will know for sure once the tests run completely but my guess is that for all of them. |
||
| """ | ||
| This function sends extra context to every admin site | ||
|
|
||
| The current treshhold to show the banner is one month but this can be redefined in the future | ||
|
|
||
| """ | ||
| months = 1 | ||
|
Member
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. We should move this to a setting so that it is configurable and also put a better default. Since we would like to get reports about twice a year, we could set the default to 6.
Contributor
Author
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. Thanks for the feedback ioll change it to 6 |
||
| try: | ||
| latest_report = SurveyReport.objects.latest('created_at') | ||
| months_treshhold = datetime.today().date() - relativedelta(months=months) # Calculate date one month ago | ||
| show_survey_report_banner = latest_report.created_at.date() <= months_treshhold | ||
| except SurveyReport.DoesNotExist: | ||
| show_survey_report_banner = False | ||
|
|
||
| return { | ||
| 'show_survey_report_banner': show_survey_report_banner, | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.