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

fix: User default language based on browser language #2201

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

shaohuzhang1
Copy link
Contributor

fix: User default language based on browser language

Copy link

f2c-ci-robot bot commented Feb 10, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

f2c-ci-robot bot commented Feb 10, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

name='language',
field=models.CharField(default=None, max_length=10, null=True, verbose_name='语言'),
),
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your migration looks generally correct, but there are a few things you might consider:

  1. Default Value for null: The default value of None can be ambiguous because in Python, many types cannot be determined from just None. If you want to explicitly indicate that null is allowed, it's better to use models.TextField(null=True) instead.

  2. Verbose Name: In Django, you typically only need to specify the verbose name if you're not using the default translation system, which is common these days. You could remove it entirely:

    field=models.CharField(max_length=10, null=True),
  3. Consistent Field Definition: It would also make sense to have all fields defined consistently (e.g., whether they're required or optional). For example, blank=True could be added for any non-required string fields:

    field=models.CharField(max_length=10, blank=True, null=True),

Here's an optimized version based on these suggestions:

@@ -0,0 +1,18 @@
+# Generated by Django 4.2.18 on 2025-02-10 06:01

+from django.db import migrations, models


+class Migration(migrations.Migration):

+    dependencies = [
+        ('application', '0025_alter_application_prologue'),
+    ]

+    operations = [
+        migrations.AlterField(
+            model_name='applicationaccesstoken',
+            name='language',
+            field=models.CharField(max_length=10, blank=True, null=True),
+        ),
+    ]

This version simplifies the model definition while maintaining clarity.

name='language',
field=models.CharField(default=None, max_length=10, null=True, verbose_name='语言'),
),
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No issues found in your migration script. The structure is correct and follows best practices for altering fields in Django database migrations.

@@ -50,7 +50,7 @@ class ApplicationAccessToken(AppModelMixin):
, default=list)
show_source = models.BooleanField(default=False, verbose_name="是否显示知识来源")

language = models.CharField(max_length=10, verbose_name="语言", default=get_language)
language = models.CharField(max_length=10, verbose_name="语言", default=None, null=True)

class Meta:
db_table = "application_access_token"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code has some minor adjustments to improve clarity and functionality:

  1. Null Check: The language field is now set to accept null=True, which allows for the possibility that it could be left empty.
    language = models.CharField(max_length=10, verbose_name="语言", default=None, null=True)
  1. Default Value Removal: Removed the call to get_language in the default value of the language field since it no longer returns an object (it used to return either 'zh_CN' or 'en_US'). Instead, simply set it to None.

  2. Minor Typographical Correction:

    • Changed verbose_name("是否显示知识来源") to verbose_name='是否显示知识来源'.

This should make the function more robust and handle edge cases like when the default option needs to be None.

@shaohuzhang1 shaohuzhang1 merged commit 3e90a9f into main Feb 10, 2025
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_language branch February 10, 2025 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant