Skip to content
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

Upgrade django version from 4.2 to 5.1 #375

Merged
merged 4 commits into from
Oct 24, 2024

Conversation

lcduong
Copy link
Contributor

@lcduong lcduong commented Oct 9, 2024

This PR related to issue #372
Upgrade Django version from 4.2 to 5.1
Changes:

  • upgrade django 4.2 to 5.1
  • upgrade django-debug-toolbar from 4.0 to 4.4

Summary by Sourcery

Upgrade Django to version 5.1 and update django-debug-toolbar to version 4.4. Introduce a new JavaScript catalog template for internationalization. Refactor the EventPluginSignal class to enhance the management of live receivers.

New Features:

  • Add a new JavaScript catalog template for handling internationalization in the project.

Enhancements:

  • Refactor the EventPluginSignal class to improve the handling of live receivers by introducing a new method get_live_receivers.

Copy link

sourcery-ai bot commented Oct 9, 2024

Reviewer's Guide by Sourcery

This pull request upgrades Django from version 4.2 to 5.1 and django-debug-toolbar from 4.0 to 4.4. The changes primarily affect the EventPluginSignal class in the base signals module and introduce a new JavaScript catalog template.

Class diagram for EventPluginSignal changes

classDiagram
    class EventPluginSignal {
        +get_live_receivers(sender)
        +_is_active(sender, receiver)
        +send(sender: Event, **named) List~Tuple~Callable, Any~~
        +send_chained(sender: Event, chain_kwarg_name, **named) List~Tuple~Callable, Any~~
        +send_robust(sender: Event, **named) List~Tuple~Callable, Any~~
    }
    class GlobalSignal {
        +send_chained(sender: Event, chain_kwarg_name, **named) List~Tuple~Callable, Any~~
    }
Loading

JavaScript catalog template structure

classDiagram
    class JSCatalogTemplate {
        +pluralidx(n)
        +gettext(msgid)
        +ngettext(singular, plural, count)
        +gettext_noop(msgid)
        +pgettext(context, msgid)
        +npgettext(context, singular, plural, count)
        +interpolate(fmt, obj, named)
        +get_format(format_type)
    }
    JSCatalogTemplate : +catalog
    JSCatalogTemplate : +formats
    JSCatalogTemplate : +jsi18n_initialized
    JSCatalogTemplate : +globals
    JSCatalogTemplate : +django
Loading

File-Level Changes

Change Details Files
Refactored EventPluginSignal class to improve performance and compatibility with Django 5.1
  • Added a new method 'get_live_receivers' to replace '_sorted_receivers'
  • Updated 'send', 'send_chained', and 'send_robust' methods to use 'get_live_receivers'
  • Removed '_sorted_receivers' method
  • Fixed a typo in the class docstring ('it's' to 'its')
src/pretix/base/signals.py
Added a new JavaScript catalog template for internationalization
  • Introduced a new file with a JavaScript template for handling translations and formatting
  • Implemented functions for gettext, ngettext, pgettext, npgettext, and interpolation
  • Added support for plural forms and context-based translations
src/pretix/base/js_catalog_template.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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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

@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 @lcduong - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Could you provide some comments explaining the rationale behind the changes in signals.py, particularly the removal of _sorted_receivers and addition of get_live_receivers? This would be helpful for future maintenance.
  • The PR description mentions upgrading django-debug-toolbar, but there are no visible changes related to this in the diff. Could you clarify if this upgrade is part of this PR, and if so, include the relevant changes?
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

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.

@@ -0,0 +1,104 @@
js_catalog_template = r"""
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider refactoring the large template string into smaller, more manageable pieces.

While the internationalization functionality is crucial, the current implementation mixes Python and JavaScript in a way that could lead to maintainability issues. Consider the following improvements:

  1. Break down the large template string into smaller, more manageable pieces:
js_catalog_template = r"""
{% autoescape off %}
'use strict';
{{ django_object }}
{{ gettext_functions }}
{{ formatting_functions }}
{{ global_assignments }}
{% endautoescape %}
"""

django_object = r"""
const globals = this;
const django = globals.django || (globals.django = {});
"""

gettext_functions = r"""
django.gettext = function(msgid) {
    // ... (existing implementation)
};

django.ngettext = function(singular, plural, count) {
    // ... (existing implementation)
};

// ... (other gettext-related functions)
"""

formatting_functions = r"""
django.formats = {{ formats_str }};

django.get_format = function(format_type) {
    // ... (existing implementation)
};
"""

global_assignments = r"""
globals.pluralidx = django.pluralidx;
globals.gettext = django.gettext;
// ... (other global assignments)

django.jsi18n_initialized = true;
"""
  1. Use a template engine or string formatting to combine these pieces:
from string import Template

js_catalog_template = Template(js_catalog_template).safe_substitute(
    django_object=django_object,
    gettext_functions=gettext_functions,
    formatting_functions=formatting_functions,
    global_assignments=global_assignments
)

This approach maintains the benefits of keeping related logic together while significantly improving readability and maintainability. It allows for easier updates to specific parts of the internationalization logic and makes the code more modular without necessarily splitting it into separate files.

Copy link
Member

@mariobehling mariobehling left a comment

Choose a reason for hiding this comment

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

Tests should be passing as much as possible in major upgrade. Please fix

  • Code Style / isort (pull_request)
  • Tests / Tests (3.11, postgres)
  • Code Style / flake8

Opened an issue here #377

@mariobehling
Copy link
Member

mariobehling commented Oct 11, 2024

In order to keep things clearer could you separate the upgrade and the fix tests into separate PRs, please and match the PR for failing tests with #377 ?

@@ -429,7 +430,7 @@ def get(self, request, *args, **kwargs):
# Get all orders of customer which belong to this event
order_list = (Order.objects.filter(Q(event=event)
& (Q(customer=customer) | Q(
email__iexact=customer.email))).select_related('event').order_by('-datetime'))
email__iexact=customer.email))).select_related('event').order_by('-datetime'))
Copy link
Member

Choose a reason for hiding this comment

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

Why a redundant whitespace here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @hongquan, its was format to add more whitespace when I run black fix: black src/pretix/api/views/event.py

Copy link
Member

Choose a reason for hiding this comment

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

Why change from single quote to double quote?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @hongquan, single quote is replaced with double quote when I run black fix: black src/pretix/base/configurations/default_setting.py
Shouldn't we use single quote for this case?

from .sso_provider_view import SSOProviderListView
from .team_view import TeamListView, TeamUpdateView, TeamCreateView, TeamMemberView, TeamDeleteView
from .web_hook_view import WebHookCreateView, WebHookListView, WebHookUpdateView
from .customer_view import CustomerDetailView # noqa
Copy link
Member

Choose a reason for hiding this comment

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

Please be more specific with "noqa".

@odkhang
Copy link
Collaborator

odkhang commented Oct 14, 2024

In order to keep things clearer could you separate the upgrade and the fix tests into separate PRs, please and match the PR for failing tests with #377 ?

Hi @mariobehling, I have separated it as your request.
Upggrade django: #375
fix isort/black/flake8: #398

Copy link
Member

@mariobehling mariobehling left a comment

Choose a reason for hiding this comment

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

@lcduong After merging the dev branch here Docker and other tests are failing. Please check.

@mariobehling mariobehling merged commit 5e9f024 into fossasia:development Oct 24, 2024
3 of 5 checks 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.

4 participants