-
Notifications
You must be signed in to change notification settings - Fork 10
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
More server i18n #30
More server i18n #30
Changes from all commits
7f36919
26790a1
b8caf10
7c5665f
5cfe87e
8d2bcc9
ebb17cc
c3cf40a
51e5952
21139f8
86e8cf1
d51ad33
3760c93
3cab663
cbc024b
c8edc8f
ab05174
fe5b2eb
dbce567
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1221,8 +1221,8 @@ class Source(Document): | |
meta = {"indexes": ["file", "blank", "rank"]} | ||
|
||
@classmethod | ||
def by_id(cls, id) -> "Source": | ||
source = cls.objects(id=id).first() | ||
def by_id(cls, id_: str | ObjectId) -> "Source": | ||
source = cls.objects(id=id_).first() | ||
Comment on lines
+1224
to
+1225
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure compatibility with Python versions when using union type annotations with The use of Apply this diff to ensure compatibility: +from typing import Union
...
@classmethod
- def by_id(cls, id_: str | ObjectId) -> "Source":
+ def by_id(cls, id_: Union[str, ObjectId]) -> "Source":
source = cls.objects(id=id_).first()
if source is None:
raise SourceNotExistError
|
||
if source is None: | ||
raise SourceNotExistError | ||
return source | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -310,11 +310,11 @@ | |||||||||||||||||||||||
self.delete() | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
@classmethod | ||||||||||||||||||||||||
def by_id(cls, id): | ||||||||||||||||||||||||
set = cls.objects(id=id).first() | ||||||||||||||||||||||||
if set is None: | ||||||||||||||||||||||||
def by_id(cls, id: ObjectId): | ||||||||||||||||||||||||
project_set = cls.objects(id=id).first() | ||||||||||||||||||||||||
if project_set is None: | ||||||||||||||||||||||||
raise ProjectSetNotExistError() | ||||||||||||||||||||||||
return set | ||||||||||||||||||||||||
return project_set | ||||||||||||||||||||||||
Comment on lines
+313
to
+317
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid using Using Apply this diff to rename the parameter and its usage: @classmethod
-def by_id(cls, id: ObjectId):
- project_set = cls.objects(id=id).first()
+def by_id(cls, id_: ObjectId):
+ project_set = cls.objects(id=id_).first()
if project_set is None:
raise ProjectSetNotExistError()
return project_set 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
def to_api(self): | ||||||||||||||||||||||||
""" | ||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
from typing import List | ||
|
||
from flask import current_app | ||
from flask_babel import lazy_gettext, gettext | ||
from app.translations import lazy_gettext, gettext | ||
from mongoengine import ( | ||
CASCADE, | ||
DENY, | ||
|
@@ -470,7 +470,7 @@ def to_api(self, user=None): | |
# 如果给了 role 则获取用户相关信息(角色等) | ||
role = None | ||
if user: | ||
role = user.get_role(self) | ||
role: TeamRole | None = user.get_role(self) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid Using Union Operator in Type Annotations for Python Versions Below 3.10 The type hint Apply this diff to fix the type hinting: - role: TeamRole | None = user.get_role(self)
+ role: Optional[TeamRole] = user.get_role(self) Also, import from typing import Optional |
||
if role: | ||
role = role.to_api() | ||
return { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -56,35 +56,32 @@ def import_from_labelplus_task(project_id): | |||||||||||||||||||||
) | ||||||||||||||||||||||
return f"失败:创建者不存在,Project {project_id}" | ||||||||||||||||||||||
try: | ||||||||||||||||||||||
with app.app_context(): | ||||||||||||||||||||||
if target and creator: | ||||||||||||||||||||||
if target and creator: | ||||||||||||||||||||||
project.update( | ||||||||||||||||||||||
import_from_labelplus_percent=0, | ||||||||||||||||||||||
import_from_labelplus_status=ImportFromLabelplusStatus.RUNNING, | ||||||||||||||||||||||
) | ||||||||||||||||||||||
labelplus_data = load_from_labelplus(project.import_from_labelplus_txt) | ||||||||||||||||||||||
file_count = len(labelplus_data) | ||||||||||||||||||||||
Comment on lines
+64
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle empty data to prevent division by zero If Apply this diff to handle the zero files case: labelplus_data = load_from_labelplus(project.import_from_labelplus_txt)
file_count = len(labelplus_data)
+ if file_count == 0:
+ project.update(
+ import_from_labelplus_status=ImportFromLabelplusStatus.ERROR,
+ import_from_labelplus_error_type=ImportFromLabelplusErrorType.NO_FILES,
+ )
+ return f"失败:没有文件可导入,Project {project_id}" 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
for file_index, labelplus_file in enumerate(labelplus_data): | ||||||||||||||||||||||
file = project.create_file(labelplus_file["file_name"]) | ||||||||||||||||||||||
for labelplus_label in labelplus_file["labels"]: | ||||||||||||||||||||||
source = file.create_source( | ||||||||||||||||||||||
content="", | ||||||||||||||||||||||
x=labelplus_label["x"], | ||||||||||||||||||||||
y=labelplus_label["y"], | ||||||||||||||||||||||
position_type=SourcePositionType.IN | ||||||||||||||||||||||
if labelplus_label["position_type"] == SourcePositionType.IN | ||||||||||||||||||||||
else SourcePositionType.OUT, | ||||||||||||||||||||||
) | ||||||||||||||||||||||
source.create_translation( | ||||||||||||||||||||||
content=labelplus_label["translation"], | ||||||||||||||||||||||
target=target, | ||||||||||||||||||||||
user=creator, | ||||||||||||||||||||||
) | ||||||||||||||||||||||
project.update( | ||||||||||||||||||||||
import_from_labelplus_percent=0, | ||||||||||||||||||||||
import_from_labelplus_status=ImportFromLabelplusStatus.RUNNING, | ||||||||||||||||||||||
import_from_labelplus_percent=int((file_index / file_count) * 100) | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct progress percentage calculation The calculation Apply this diff to fix the progress percentage calculation: import_from_labelplus_percent=int((file_index / file_count) * 100)
+ import_from_labelplus_percent=int(((file_index + 1) / file_count) * 100) This change ensures that the progress reaches 100% upon completion. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
) | ||||||||||||||||||||||
labelplus_data = load_from_labelplus(project.import_from_labelplus_txt) | ||||||||||||||||||||||
file_count = len(labelplus_data) | ||||||||||||||||||||||
for file_index, labelplus_file in enumerate(labelplus_data): | ||||||||||||||||||||||
file = project.create_file(labelplus_file["file_name"]) | ||||||||||||||||||||||
for labelplus_label in labelplus_file["labels"]: | ||||||||||||||||||||||
source = file.create_source( | ||||||||||||||||||||||
content="", | ||||||||||||||||||||||
x=labelplus_label["x"], | ||||||||||||||||||||||
y=labelplus_label["y"], | ||||||||||||||||||||||
position_type=SourcePositionType.IN | ||||||||||||||||||||||
if labelplus_label["position_type"] == SourcePositionType.IN | ||||||||||||||||||||||
else SourcePositionType.OUT, | ||||||||||||||||||||||
) | ||||||||||||||||||||||
source.create_translation( | ||||||||||||||||||||||
content=labelplus_label["translation"], | ||||||||||||||||||||||
target=target, | ||||||||||||||||||||||
user=creator, | ||||||||||||||||||||||
) | ||||||||||||||||||||||
project.update( | ||||||||||||||||||||||
import_from_labelplus_percent=int( | ||||||||||||||||||||||
(file_index / file_count) * 100 | ||||||||||||||||||||||
) | ||||||||||||||||||||||
) | ||||||||||||||||||||||
except Exception: | ||||||||||||||||||||||
logger.exception(Exception) | ||||||||||||||||||||||
project.update( | ||||||||||||||||||||||
|
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.
Ensure Type Hint Compatibility with Python Versions Below 3.9
The use of
list[TeamUserRelation]
as a type hint requires Python 3.9 or above. If your project supports earlier Python versions, consider usingList[TeamUserRelation]
from thetyping
module for compatibility.Apply this diff to fix the type hinting:
Additionally, import
List
from thetyping
module at the beginning of the file: