-
Notifications
You must be signed in to change notification settings - Fork 611
feat:inlinePanel nested #595
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
Open
Anushreebasics
wants to merge
1
commit into
wagtail:main
Choose a base branch
from
Anushreebasics:nested_inlinepanel_demo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
bakerydemo/locations/migrations/0009_locationweekdayslot_locationhourslot.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
|
|
||
|
|
||
| import django.db.models.deletion | ||
| import modelcluster.fields | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("locations", "0008_alter_locationpage_body"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="LocationWeekDaySlot", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.AutoField( | ||
| auto_created=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| verbose_name="ID", | ||
| ), | ||
| ), | ||
| ( | ||
| "sort_order", | ||
| models.IntegerField(blank=True, editable=False, null=True), | ||
| ), | ||
| ( | ||
| "day", | ||
| models.CharField( | ||
| choices=[ | ||
| ("MON", "Monday"), | ||
| ("TUE", "Tuesday"), | ||
| ("WED", "Wednesday"), | ||
| ("THU", "Thursday"), | ||
| ("FRI", "Friday"), | ||
| ("SAT", "Saturday"), | ||
| ("SUN", "Sunday"), | ||
| ], | ||
| default="MON", | ||
| help_text="Select the day of the week", | ||
| max_length=3, | ||
| ), | ||
| ), | ||
| ( | ||
| "location", | ||
| modelcluster.fields.ParentalKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="week_day_slots", | ||
| to="locations.locationpage", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "verbose_name": "Week Day Slot", | ||
| "verbose_name_plural": "Week Day Slots", | ||
| "ordering": ["sort_order"], | ||
| }, | ||
| ), | ||
| migrations.CreateModel( | ||
| name="LocationHourSlot", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.AutoField( | ||
| auto_created=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| verbose_name="ID", | ||
| ), | ||
| ), | ||
| ( | ||
| "sort_order", | ||
| models.IntegerField(blank=True, editable=False, null=True), | ||
| ), | ||
| ("opening_time", models.TimeField(blank=True, null=True)), | ||
| ("closing_time", models.TimeField(blank=True, null=True)), | ||
| ( | ||
| "closed", | ||
| models.BooleanField( | ||
| blank=True, | ||
| default=False, | ||
| help_text="Tick if location is closed during this time slot", | ||
| verbose_name="Closed?", | ||
| ), | ||
| ), | ||
| ( | ||
| "week_day_slot", | ||
| modelcluster.fields.ParentalKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="hour_slots", | ||
| to="locations.locationweekdayslot", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "verbose_name": "Hour Slot", | ||
| "verbose_name_plural": "Hour Slots", | ||
| "ordering": ["sort_order"], | ||
| }, | ||
| ), | ||
| ] |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| #!/usr/bin/env python | ||
| """ | ||
| Test script to verify the nested InlinePanel implementation | ||
| """ | ||
| import os | ||
| import django | ||
|
|
||
| os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bakerydemo.settings.dev") | ||
| django.setup() | ||
|
|
||
| from bakerydemo.locations.models import ( | ||
| LocationPage, | ||
| LocationWeekDaySlot, | ||
| LocationHourSlot, | ||
| ) | ||
|
|
||
| def test_nested_inline_panel(): | ||
| """Test the nested InlinePanel structure""" | ||
|
|
||
| print("=" * 80) | ||
| print("NESTED INLINEPANEL DEMONSTRATION") | ||
| print("=" * 80) | ||
|
|
||
| # Get a location page | ||
| locations = LocationPage.objects.all() | ||
|
|
||
| if not locations.exists(): | ||
| print("\n❌ No location pages found in the database.") | ||
| print("Please visit the admin at http://localhost:8000/admin/ and create a location.") | ||
| return | ||
|
|
||
| location = locations.first() | ||
| print(f"\n📍 Testing with Location: {location.title}") | ||
| print(f" URL: http://localhost:8000/admin/pages/{location.id}/edit/") | ||
|
|
||
| # Check for week day slots | ||
| week_day_slots = location.week_day_slots.all() | ||
|
|
||
| if not week_day_slots.exists(): | ||
| print("\n📝 No nested week day slots found yet.") | ||
| print(" Go to the admin interface and add some!") | ||
| print(f"\n Steps:") | ||
| print(f" 1. Visit: http://localhost:8000/admin/pages/{location.id}/edit/") | ||
| print(f" 2. Scroll to 'Hours of Operation (Nested InlinePanel Demo)'") | ||
| print(f" 3. Click '+ Day' to add a week day slot") | ||
| print(f" 4. Select a day (e.g., Monday)") | ||
| print(f" 5. Within that day, click '+ Time Slot' to add hour slots") | ||
| print(f" 6. Add multiple time slots (e.g., 9:00-12:00, 13:00-17:00)") | ||
| print(f" 7. Save the page") | ||
| else: | ||
| print(f"\n✅ Found {week_day_slots.count()} nested week day slot(s):") | ||
| print("-" * 80) | ||
|
|
||
| for day_slot in week_day_slots: | ||
| print(f"\n 📅 {day_slot.get_day_display()}") | ||
| hour_slots = day_slot.hour_slots.all() | ||
|
|
||
| if hour_slots.exists(): | ||
| print(f" Time slots ({hour_slots.count()}):") | ||
| for hour_slot in hour_slots: | ||
| if hour_slot.closed: | ||
| print(f" 🚫 CLOSED") | ||
| else: | ||
| opening = hour_slot.opening_time.strftime("%H:%M") if hour_slot.opening_time else "--:--" | ||
| closing = hour_slot.closing_time.strftime("%H:%M") if hour_slot.closing_time else "--:--" | ||
| print(f" 🕒 {opening} - {closing}") | ||
| else: | ||
| print(f" (No hour slots defined)") | ||
|
|
||
| print("\n" + "-" * 80) | ||
| print("✅ Nested InlinePanel structure is working correctly!") | ||
|
|
||
| # Show comparison with flat structure | ||
| flat_hours = location.hours_of_operation.all() | ||
| if flat_hours.exists(): | ||
| print(f"\n📊 For comparison, flat structure has {flat_hours.count()} slot(s)") | ||
|
|
||
| print("\n" + "=" * 80) | ||
| print("TESTING SUMMARY:") | ||
| print("=" * 80) | ||
| print("✓ Models created successfully") | ||
| print("✓ Database migrations applied") | ||
| print("✓ Nested InlinePanel structure available in admin") | ||
| print(f"✓ Admin interface: http://localhost:8000/admin/") | ||
| print(f"✓ Location edit: http://localhost:8000/admin/pages/{location.id}/edit/") | ||
| print("\n🎯 This demonstrates nested InlinePanel for testing:") | ||
| print(" • Expand/collapse functionality per day") | ||
| print(" • Multiple time slots within each day") | ||
| print(" • Scroll behavior with nested panels") | ||
| print(" • Related to Wagtail issue #13352") | ||
|
||
| print("=" * 80) | ||
|
|
||
| if __name__ == "__main__": | ||
| test_nested_inline_panel() | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'LocationWeekDaySlot' is not used.
Import of 'LocationHourSlot' is not used.