Added internal statistics page#819
Open
ba11e-mos wants to merge 6 commits into
Open
Conversation
Define two minimal models on the project-root `web` app to record total visits per URL path and unique visitor sessions/users. Both expose admin classes (read-only fields, sensible orderings) so the data can be inspected without going through the statistics page.
Increment the path's `PageView.count` and upsert the visitor identifier on every successful `GET` response. The path is normalized by stripping any leading language prefix so `/en/foo/` and `/foo/` aggregate to the same row, and a small set of non-page prefixes (`/static/`, `/api/`, `/jsi18n/`, etc.) is excluded so they don't drown out real traffic.
Render an internal-only page summarizing site traffic, average reservations per hour of day and per-machine-type usage. Each section exposes its own time-range filter (last week/month/year/custom interval) that updates the corresponding charts via an AJAX call to a new JSON endpoint, keeping the rest of the page intact.
Cover access control (anonymous, non-member, internal user, superuser), template context shape, the per-section date-range filter (week/all/ custom and per-section isolation) and the AJAX JSON endpoint (machine-type and time payloads, error responses, range filter respect).
532a41d to
293338d
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #819 +/- ##
==========================================
+ Coverage 87.99% 88.29% +0.29%
==========================================
Files 153 155 +2
Lines 6249 6443 +194
==========================================
+ Hits 5499 5689 +190
- Misses 750 754 +4
🚀 New features to boost your workflow:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Builds on the work started in #669. Re-implemented on top of current
mainwith per-section time-range filters, AJAX updates, mobile-responsive layout and tests.Proposed changes
Adds an internal-only statistics page (
/statistics/on the internal subdomain) that contains:PageViewMiddlewarethat records every successfulGET.Each chart section has its own time-range filter (last week / month / year / custom interval). Filter changes update the section in place via an AJAX call to a new JSON endpoint, i thought it would be nice with a seamless transition:)
New project-root
webmodelsPageViewandVisitorback the traffic stats. Language-prefixed paths (/en/foo/) are normalized to their canonical form (/foo/) before being stored, so traffic aggregates per page rather than per language. It should be possible to separate statistics by language in the future if wanted.Future work
PhysicalVisitor similar) plus an ingestion endpoint or scheduled import, then reuse the same per-section filter UI.Review guidance
src/internal/views.py(StatisticsView+APIStatisticsDataView). The JSON endpoint reuses the same filtering helpers as the page render, so behaviour stays in sync.webapp to keep this PR small. Could move to a dedicated app later if needed. Two consequences worth knowing: model registration runs fromWebAdminConfig.ready()to dodge anadmin.siteLazyObject race, andWebAdminSite.get_app_list()regroupsPageView/Visitorunder a synthetic "Statistics" header so they don't sit under "Web".internal.is_internalpermission via thedecorator_includewrap ininternal/urls.py— i.e. any internal-site member can view the page. No stricter per-view permission was added since the data shown (reservation usage, page-view counts) isn't sensitive in the same way as e.g. member or quote data. If a tighter gate is wanted later, a newinternal.view_statisticspermission can be added without touching the view code.semantic_date.html).Deployment notes
web_pageviewandweb_visitor(web/0001_pageview_visitor).web.middleware.PageViewMiddlewareis registered inMIDDLEWAREand starts collecting traffic automatically when the deploy goes live — no environment variables, management commands or manual data steps required.Checklist
makemigrations,makemessagesandcompilemessages