Skip to content

Conversation

yaxit24
Copy link
Contributor

@yaxit24 yaxit24 commented Aug 15, 2025

Fixes #833

Summary by Sourcery

Introduce item category support for badge layouts and integrate category-based filtering and rendering throughout check-in and badge exports

New Features:

  • Allow assigning a category to badge layouts in the model, forms, API, and admin
  • Add a view to edit badge layout metadata including name and category
  • Enable filtering by item category in check-in interface and check-in list exporter
  • Automatically apply category-specific badge layouts during PDF export

Enhancements:

  • Display category column and separate edit/visual editor actions in badge layout list
  • Include event context in form kwargs for badge views

Build:

  • Set BASE_PATH to empty and enable CORS middleware with permissive origins in settings

Chores:

  • Add Django migration to include category field on BadgeLayout model

Copy link
Contributor

sourcery-ai bot commented Aug 15, 2025

Reviewer's Guide

This PR introduces category support for badge layouts, enabling automatic layout assignment per item category by extending the data model, forms, views, templates, exporters, and API, with the necessary migration and minor dev settings updates.

Sequence diagram for badge rendering with category-based layout assignment

sequenceDiagram
    participant System
    participant BadgeRenderer
    participant Item
    participant BadgeLayout
    participant ItemCategory
    System->>BadgeRenderer: Request badge for Item
    BadgeRenderer->>Item: Get item details
    BadgeRenderer->>BadgeLayout: Check for item-specific layout
    alt No item-specific layout
        BadgeRenderer->>ItemCategory: Get item's category
        BadgeRenderer->>BadgeLayout: Check for category-specific layout
        alt No category-specific layout
            BadgeRenderer->>BadgeLayout: Use default layout
        end
    end
    BadgeRenderer-->>System: Return rendered badge
Loading

Class diagram for updated BadgeLayout model

classDiagram
    class BadgeLayout {
        +id: int
        +name: str
        +default: bool
        +layout: str
        +category: ItemCategory
    }
    class ItemCategory {
        +id: int
        +name: str
    }
    BadgeLayout --> ItemCategory : category
Loading

File-Level Changes

Change Details Files
Add category field to BadgeLayout model and database schema
  • Introduce 'category' ForeignKey on BadgeLayout model with SET_NULL behavior
  • Add corresponding Django migration
  • Define help_text and verbose_name for the field
src/pretix/plugins/badges/models.py
src/pretix/plugins/badges/migrations/0005_add_category_to_badgelayout.py
Extend forms to handle category selection and filtering
  • Add 'category' ModelChoiceField to BadgeLayoutForm with event-scoped queryset and help_text
  • Include category field in CheckInFilterForm and initialize its queryset based on event items
  • Add category filter field in checkinlists exporter forms with proper queryset and filtering logic
src/pretix/plugins/badges/forms.py
src/pretix/control/forms/filter.py
src/pretix/plugins/checkinlists/exporters.py
Introduce new layout update view and wire category into form kwargs
  • Implement LayoutUpdate class to edit layout name & category with atomic save and messages
  • Inject 'event' into form kwargs for badge-related views
  • Register new update URL route for LayoutUpdate
src/pretix/plugins/badges/views.py
src/pretix/plugins/badges/urls.py
Update badges and check-in UIs to display and allow category filtering
  • Add category column and display badges' category labels in badges index template
  • Include category field in badge edit form template
  • Add category filter field to check-in control panel template
src/pretix/plugins/badges/templates/pretixplugins/badges/index.html
src/pretix/plugins/badges/templates/pretixplugins/badges/edit.html
src/pretix/control/templates/pretixcontrol/checkin/index.html
Leverage category-based mappings when rendering badges PDFs
  • Build category_renderermap for badge layouts per category
  • Adjust render_page logic to prioritize item-specific > category-based > default layout renderer
src/pretix/plugins/badges/exporters.py
Expose category in BadgeLayout API representations
  • Add 'category' field to BadgeLayout serializer's Meta.fields
src/pretix/plugins/badges/api.py
Adjust application base path and enable CORS for development/testing
  • Reset BASE_PATH to empty string
  • Insert 'corsheaders.middleware.CorsMiddleware' into MIDDLEWARE and configure CORS settings
src/pretix/settings.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/pretix/plugins/badges/exporters.py:184` </location>
<code_context>
         for bi in BadgeItem.objects.select_related('layout').filter(item__event=event)
     }
+    
+    # Build category-based renderer map
+    category_renderermap = {}
+    for layout in event.badge_layouts.filter(category__isnull=False).select_related('category'):
+        category_renderermap[layout.category_id] = _renderer(event, layout)
+    
</code_context>

<issue_to_address>
Consider handling duplicate category assignments for badge layouts.

Currently, assigning multiple layouts to the same category will result in only the last one being used. Consider adding validation or documenting which layout should take precedence.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    # Build category-based renderer map
    category_renderermap = {}
    for layout in event.badge_layouts.filter(category__isnull=False).select_related('category'):
        category_renderermap[layout.category_id] = _renderer(event, layout)
=======
    # Build category-based renderer map
    category_renderermap = {}
    for layout in event.badge_layouts.filter(category__isnull=False).select_related('category'):
        if layout.category_id in category_renderermap:
            # Validation: Multiple layouts assigned to the same category
            raise ValueError(
                f"Duplicate badge layout assignment for category ID {layout.category_id}. "
                "Each category should have only one badge layout assigned."
            )
        category_renderermap[layout.category_id] = _renderer(event, layout)
    # Note: If you want to allow duplicates and document precedence, comment out the raise and add a comment:
    # "If multiple layouts are assigned to the same category, the last one will take precedence."
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

yaxit24 and others added 3 commits August 15, 2025 23:48
The code changes for the CORS is reverted.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@yaxit24
Copy link
Contributor Author

yaxit24 commented Aug 15, 2025

Screen.Recording.2025-08-16.at.12.18.57.AM.mov

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.

Add Roles to Attendees and Matching Roles with Products & Badges
1 participant