Skip to content

Conversation

@tlambert03
Copy link
Owner

No description provided.

claude and others added 5 commits November 5, 2025 19:58
Created a comprehensive moderation page for reviewing protein submissions
and changes, allowing moderators to review all field changes and related
objects before approving or rejecting.

**Key Features:**

- Custom dashboard at /pending-proteins/ showing all pending proteins
- Intelligent diff comparison between current version and last approved version
- Comprehensive change tracking for:
  - Protein fields (name, sequence, chromophore, etc.)
  - States (added/removed/modified with all properties)
  - References (added/removed)
  - Lineage changes (parent, mutations)
  - State transitions (added/removed)
  - OSER measurements (added/removed)

- Clean, collapsible UI showing only changed fields
- Bulk actions: approve/reject multiple proteins at once
- Individual actions per protein with email capability
- Special handling for new submissions vs modifications
- Sequence mutations display for changed sequences
- Toast notifications for user feedback

**Implementation:**

1. **Backend** (`backend/proteins/views/protein.py`):
   - `_get_protein_changes()`: Helper function that compares pending protein
     with last approved version using django-reversion
   - `pending_proteins_dashboard()`: Main view rendering the dashboard
   - `pending_protein_action()`: AJAX endpoint for approve/reject actions

2. **Frontend** (`backend/proteins/templates/pending_proteins_dashboard.html`):
   - Card-based layout similar to spectrum moderation
   - Collapsible sections for each category of changes
   - Color-coded additions (green) and removals (red)
   - Responsive design with sticky bulk action bar

3. **URLs** (`backend/proteins/urls.py`):
   - `/pending-proteins/` - Main dashboard
   - `/ajax/pending_protein_action/` - Action endpoint

**Technical Details:**

- Leverages django-reversion's `last_approved_version()` method
- Handles nested related objects (states, spectra, measurements)
- Smart state comparison by unique fields to handle ID changes
- Displays field-level changes with old → new formatting
- Shows mutation notation for sequence changes
- Revision tracking with comments and user attribution

Closes the request for protein moderation functionality.
The last_approved_version() method returns a Version object when the protein
is pending, but was being treated as a Protein instance. Now properly
deserialize the Version back to a Protein using the old_object() helper
from history.py.

Fixes AttributeError: 'Version' object has no attribute 'states'
- Use Version.field_dict instead of old_object() to avoid broken transactions
- Skip related object comparisons when using field_dict (only show protein fields)
- Handle choice field display values using CHOICES tuples
- Update all references from last_approved to old_data variable

This fixes the TransactionManagementError that occurred when trying to query
related objects after the transaction rollback in old_object().
Added comprehensive sorting capabilities to the pending proteins dashboard:

**Sort Criteria:**
- Most/Least Recently Updated (modified date)
- Newest/Oldest (created date)
- Most/Least Viewed (Google Analytics data, 30-day window)
- Most/Least Favorited (user favorites count)
- Name (A-Z / Z-A)

**Backend Changes:**
- Fetch view data from Google Analytics via cached_ga_popular()
- Fetch favorite counts from Favorite model
- Add view_count and favorite_count to protein data
- Add ISO formatted timestamps for JavaScript sorting

**Frontend Changes:**
- Added sort dropdown with 10 sorting options
- Added data attributes to protein cards for client-side sorting
- Implemented sortProteins() JavaScript function
- Cards re-order dynamically without page reload

Sorting is purely client-side after initial page load for instant feedback.
Default sort remains 'Most Recently Updated' (modified desc).
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 3.01508% with 193 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.38%. Comparing base (d0c412e) to head (adaafba).

Files with missing lines Patch % Lines
backend/proteins/views/protein.py 3.01% 193 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #350      +/-   ##
==========================================
- Coverage   60.94%   58.38%   -2.57%     
==========================================
  Files         104      104              
  Lines        8559     8758     +199     
==========================================
- Hits         5216     5113     -103     
- Misses       3343     3645     +302     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants