Skip to content

Conversation

@hongquan
Copy link
Member

@hongquan hongquan commented Nov 21, 2025

Part of #1214

image

Summary by Sourcery

Add optional inclusion of Wikimedia usernames in order exports based on a new event setting.

New Features:

  • Allow events to enable inclusion of attendees' Wikimedia usernames in order export CSVs.
  • Introduce an event-level setting to control whether Wikimedia usernames are collected and shown, exposed in the event settings UI.

Enhancements:

  • Preload Wikimedia usernames on orders to support conditional export without impacting other order data handling.

@hongquan hongquan requested a review from Copilot November 21, 2025 11:38
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 21, 2025

Reviewer's Guide

Adds a configurable option to include Wikimedia usernames in order exports by annotating orders with the user’s Wikimedia username, conditionally adding a CSV column and values, and wiring the setting through event settings defaults, forms, and templates; also includes minor formatting/import cleanups.

Sequence diagram for exporting orders with Wikimedia username

sequenceDiagram
    actor Admin as "Admin"
    participant "Event Settings UI" as "Event Settings UI"
    participant "Server" as "Server"
    participant "EventSettingsForm" as "EventSettingsForm"
    participant "Database" as "Database"
    participant "Order Exporter" as "Order Exporter"

    Admin->>"Event Settings UI": "Open event settings"
    "Event Settings UI"->>"Server": "GET event settings form"
    "Server"->>"EventSettingsForm": "Instantiate with event settings"
    "EventSettingsForm"->>"Database": "Load setting key include_wikimedia_username"
    "Database"-->>"EventSettingsForm": "Return current value (default ""False"")"
    "EventSettingsForm"-->>"Server": "Rendered form including include_wikimedia_username checkbox"
    "Server"-->>"Event Settings UI": "HTML with Wikimedia username option"

    Admin->>"Event Settings UI": "Enable include_wikimedia_username and submit"
    "Event Settings UI"->>"Server": "POST updated settings (include_wikimedia_username = True)"
    "Server"->>"EventSettingsForm": "Validate and save settings"
    "EventSettingsForm"->>"Database": "Persist include_wikimedia_username = True for event"
    "Database"-->>"EventSettingsForm": "Settings saved"

    Admin->>"Order Exporter": "Request order CSV export"
    "Order Exporter"->>"Database": "Query events for export and their settings.include_wikimedia_username"
    "Database"-->>"Order Exporter": "Events with include_wikimedia_username flags"
    "Order Exporter"->>"Database": "Build wikimedia_query: User by email with wikimedia_username"
    "Order Exporter"->>"Database": "Query orders with Subquery wikimedia_username annotation"
    "Database"-->>"Order Exporter": "Annotated orders result set"
    "Order Exporter"->>"Order Exporter": "Check if any event has include_wikimedia_username = True"
    "Order Exporter"->>"Order Exporter": "If True, insert Wikimedia username column header before Phone number"
    "Order Exporter"->>"Order Exporter": "For each order, insert annotated wikimedia_username value into row"
    "Order Exporter"-->>Admin: "CSV file including Wikimedia username column when enabled"
Loading

Updated class diagram for order export and event settings with Wikimedia username

classDiagram
    class EventSettingsForm {
        +include_wikimedia_username: bool
        +__init__(*args, **kwargs)
    }

    class DefaultSettingRegistry {
        +"include_wikimedia_username": bool
        +get_default(key)
    }

    class Event {
        +settings: SettingsProxy
    }

    class SettingsProxy {
        +include_wikimedia_username: bool
        +get(key, default)
    }

    class OrderExporter {
        +events: list
        +event_object_cache: dict
        +iterate_orders(form_data: dict)
    }

    class Order {
        +email: str
        +wikimedia_username: str
    }

    class User {
        +email: str
        +wikimedia_username: str
    }

    EventSettingsForm --> DefaultSettingRegistry : "uses setting key 'include_wikimedia_username'"
    Event --> SettingsProxy : "has settings including 'include_wikimedia_username'"
    OrderExporter --> Event : "reads settings.include_wikimedia_username for each event"
    OrderExporter --> Order : "exports annotated orders"
    OrderExporter --> User : "subquery by email to annotate wikimedia_username"
    Order --> User : "linked logically via matching email for wikimedia_username lookup"
Loading

File-Level Changes

Change Details Files
Annotate orders with wikimedia_username and conditionally include it in the order export.
  • Add a Subquery to fetch wikimedia_username from User by matching email and annotate it onto the Order queryset used for exports
  • Compute a should_include_wikimedia flag based on event settings cache to decide whether to expose the Wikimedia username in exports
  • Insert a Wikimedia username column header before the phone number header when the setting is enabled
  • Insert the annotated wikimedia_username value into each export row at the correct position, with a safe empty-string fallback
app/eventyay/base/exporters/orderlist.py
Add an event-level setting to control whether Wikimedia username should be included and expose it in the event settings UI.
  • Register a new include_wikimedia_username boolean setting with default, form, and serializer metadata
  • Include include_wikimedia_username in EventSettingsForm settings fields so it is editable per event
  • Render the include_wikimedia_username checkbox in the event settings template under customer data settings
app/eventyay/base/configurations/default_setting.py
app/eventyay/control/forms/event.py
app/eventyay/control/templates/pretixcontrol/event/settings.html
Misc. code hygiene changes.
  • Normalize whitespace in Event form initialization around organizer and slug generation logic
  • Tidy imports in orders control view by reordering Product and ProductVariation imports
app/eventyay/control/forms/event.py
app/eventyay/control/views/orders.py

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 - here's some feedback:

  • When inserting the Wikimedia username into each CSV row, avoid using the hard-coded index 5 and instead compute the insertion index from the headers (e.g., based on the position of the phone number header) to keep columns aligned if the header structure changes.
  • You’re annotating wikimedia_username on all orders even if no event has the setting enabled; consider only adding this Subquery when should_include_wikimedia is true to avoid unnecessary DB work on exports where the field is not used.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When inserting the Wikimedia username into each CSV row, avoid using the hard-coded index 5 and instead compute the insertion index from the headers (e.g., based on the position of the phone number header) to keep columns aligned if the header structure changes.
- You’re annotating wikimedia_username on all orders even if no event has the setting enabled; consider only adding this Subquery when should_include_wikimedia is true to avoid unnecessary DB work on exports where the field is not used.

## Individual Comments

### Comment 1
<location> `app/eventyay/base/exporters/orderlist.py:421-424` </location>
<code_context>
                 order.datetime.astimezone(tz).strftime('%H:%M:%S %Z'),
             ]
+
+            # Add wikimedia_username if setting is enabled (insert before phone number)
+            if should_include_wikimedia:
+                wikimedia_username = getattr(order, 'wikimedia_username', '') or ''
+                row.insert(5, wikimedia_username)
+
             try:
</code_context>

<issue_to_address>
**issue (bug_risk):** Hard-coding the column index 5 for wikimedia_username risks misalignment with the headers.

This relies on column 5 always being the Wikimedia username position. If the header structure changes (e.g., different name formats or new fields), this index can become wrong and misalign data and headers. Instead, derive the insertion index dynamically (e.g., find the phone column index at runtime) or share the same column-ordering logic used when building the headers so rows always match the header definition.
</issue_to_address>

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.

Copilot finished reviewing on behalf of hongquan November 21, 2025 11:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds functionality to export Wikimedia usernames in order exports. The feature is controlled by a new event setting include_wikimedia_username that allows organizers to include Wikimedia IDs for users authenticated via Wikimedia in their order export files.

  • Adds a new boolean event setting include_wikimedia_username with UI controls
  • Modifies the order export logic to fetch and conditionally include Wikimedia username data
  • Updates imports ordering in affected files

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
app/eventyay/base/configurations/default_setting.py Defines the new include_wikimedia_username boolean setting with default value 'False'
app/eventyay/control/forms/event.py Adds the new setting to the event settings form and reorders imports alphabetically
app/eventyay/control/templates/pretixcontrol/event/settings.html Adds UI field for the Wikimedia username setting in the customer data section
app/eventyay/base/exporters/orderlist.py Implements logic to fetch Wikimedia username via subquery and conditionally include it in CSV exports
app/eventyay/control/views/orders.py Reorders imports alphabetically

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mariobehling mariobehling merged commit 67d2ac5 into fossasia:enext Nov 22, 2025
1 check passed
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.

2 participants