Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
02378337
Unverified
Commit
02378337
authored
May 25, 2023
by
John Wang
Committed by
GitHub
May 25, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: explore support multi language (#202)
parent
1d06eba6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
65 deletions
+63
-65
commands.py
api/commands.py
+1
-25
admin.py
api/controllers/console/admin.py
+14
-17
recommended_app.py
api/controllers/console/explore/recommended_app.py
+10
-11
a45f4dfde53b_add_language_to_recommend_apps.py
...s/versions/a45f4dfde53b_add_language_to_recommend_apps.py
+36
-0
model.py
api/models/model.py
+2
-12
No files found.
api/commands.py
View file @
02378337
import
datetime
import
datetime
import
json
import
random
import
random
import
string
import
string
...
@@ -9,7 +8,7 @@ from libs.password import password_pattern, valid_password, hash_password
...
@@ -9,7 +8,7 @@ from libs.password import password_pattern, valid_password, hash_password
from
libs.helper
import
email
as
email_validate
from
libs.helper
import
email
as
email_validate
from
extensions.ext_database
import
db
from
extensions.ext_database
import
db
from
models.account
import
InvitationCode
from
models.account
import
InvitationCode
from
models.model
import
Account
,
AppModelConfig
,
ApiToken
,
Site
,
App
,
RecommendedApp
from
models.model
import
Account
import
secrets
import
secrets
import
base64
import
base64
...
@@ -131,30 +130,7 @@ def generate_upper_string():
...
@@ -131,30 +130,7 @@ def generate_upper_string():
return
result
return
result
@
click
.
command
(
'gen-recommended-apps'
,
help
=
'Number of records to generate'
)
def
generate_recommended_apps
():
print
(
'Generating recommended app data...'
)
apps
=
App
.
query
.
filter
(
App
.
is_public
==
True
)
.
all
()
for
app
in
apps
:
recommended_app
=
RecommendedApp
(
app_id
=
app
.
id
,
description
=
{
'en'
:
'Description for '
+
app
.
name
,
'zh'
:
'描述 '
+
app
.
name
},
copyright
=
'Copyright '
+
str
(
random
.
randint
(
1990
,
2020
)),
privacy_policy
=
'https://privacypolicy.example.com'
,
category
=
random
.
choice
([
'Games'
,
'News'
,
'Music'
,
'Sports'
]),
position
=
random
.
randint
(
1
,
100
),
install_count
=
random
.
randint
(
100
,
100000
)
)
db
.
session
.
add
(
recommended_app
)
db
.
session
.
commit
()
print
(
'Done!'
)
def
register_commands
(
app
):
def
register_commands
(
app
):
app
.
cli
.
add_command
(
reset_password
)
app
.
cli
.
add_command
(
reset_password
)
app
.
cli
.
add_command
(
reset_email
)
app
.
cli
.
add_command
(
reset_email
)
app
.
cli
.
add_command
(
generate_invitation_codes
)
app
.
cli
.
add_command
(
generate_invitation_codes
)
app
.
cli
.
add_command
(
generate_recommended_apps
)
api/controllers/console/admin.py
View file @
02378337
...
@@ -44,10 +44,11 @@ class InsertExploreAppListApi(Resource):
...
@@ -44,10 +44,11 @@ class InsertExploreAppListApi(Resource):
def
post
(
self
):
def
post
(
self
):
parser
=
reqparse
.
RequestParser
()
parser
=
reqparse
.
RequestParser
()
parser
.
add_argument
(
'app_id'
,
type
=
str
,
required
=
True
,
nullable
=
False
,
location
=
'json'
)
parser
.
add_argument
(
'app_id'
,
type
=
str
,
required
=
True
,
nullable
=
False
,
location
=
'json'
)
parser
.
add_argument
(
'desc_en'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'desc'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'desc_zh'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'copyright'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'copyright'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'privacy_policy'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'privacy_policy'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'language'
,
type
=
str
,
required
=
True
,
nullable
=
False
,
choices
=
[
'en-US'
,
'zh-Hans'
],
location
=
'json'
)
parser
.
add_argument
(
'category'
,
type
=
str
,
required
=
True
,
nullable
=
False
,
location
=
'json'
)
parser
.
add_argument
(
'category'
,
type
=
str
,
required
=
True
,
nullable
=
False
,
location
=
'json'
)
parser
.
add_argument
(
'position'
,
type
=
int
,
required
=
True
,
nullable
=
False
,
location
=
'json'
)
parser
.
add_argument
(
'position'
,
type
=
int
,
required
=
True
,
nullable
=
False
,
location
=
'json'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
...
@@ -58,25 +59,24 @@ class InsertExploreAppListApi(Resource):
...
@@ -58,25 +59,24 @@ class InsertExploreAppListApi(Resource):
site
=
app
.
site
site
=
app
.
site
if
not
site
:
if
not
site
:
desc
=
args
[
'desc
_en'
]
desc
=
args
[
'desc
'
]
if
args
[
'desc'
]
else
''
copy_right
=
args
[
'copyright'
]
copy_right
=
args
[
'copyright'
]
if
args
[
'copyright'
]
else
''
privacy_policy
=
args
[
'privacy_policy'
]
privacy_policy
=
args
[
'privacy_policy'
]
if
args
[
'privacy_policy'
]
else
''
else
:
else
:
desc
=
site
.
description
if
not
args
[
'desc_en'
]
else
args
[
'desc_en'
]
desc
=
site
.
description
if
(
site
.
description
if
not
args
[
'desc'
]
else
args
[
'desc'
])
else
''
copy_right
=
site
.
copyright
if
not
args
[
'copyright'
]
else
args
[
'copyright'
]
copy_right
=
site
.
copyright
if
(
site
.
copyright
if
not
args
[
'copyright'
]
else
args
[
'copyright'
])
else
''
privacy_policy
=
site
.
privacy_policy
if
not
args
[
'privacy_policy'
]
else
args
[
'privacy_policy'
]
privacy_policy
=
site
.
privacy_policy
\
if
(
site
.
privacy_policy
if
not
args
[
'privacy_policy'
]
else
args
[
'privacy_policy'
])
else
''
recommended_app
=
RecommendedApp
.
query
.
filter
(
RecommendedApp
.
app_id
==
args
[
'app_id'
])
.
first
()
recommended_app
=
RecommendedApp
.
query
.
filter
(
RecommendedApp
.
app_id
==
args
[
'app_id'
])
.
first
()
if
not
recommended_app
:
if
not
recommended_app
:
recommended_app
=
RecommendedApp
(
recommended_app
=
RecommendedApp
(
app_id
=
app
.
id
,
app_id
=
app
.
id
,
description
=
{
description
=
desc
,
'en'
:
desc
,
'zh'
:
desc
if
not
args
[
'desc_zh'
]
else
args
[
'desc_zh'
]
},
copyright
=
copy_right
,
copyright
=
copy_right
,
privacy_policy
=
privacy_policy
,
privacy_policy
=
privacy_policy
,
language
=
args
[
'language'
],
category
=
args
[
'category'
],
category
=
args
[
'category'
],
position
=
args
[
'position'
]
position
=
args
[
'position'
]
)
)
...
@@ -88,13 +88,10 @@ class InsertExploreAppListApi(Resource):
...
@@ -88,13 +88,10 @@ class InsertExploreAppListApi(Resource):
return
{
'result'
:
'success'
},
201
return
{
'result'
:
'success'
},
201
else
:
else
:
recommended_app
.
description
=
{
recommended_app
.
description
=
desc
'en'
:
desc
,
'zh'
:
desc
if
not
args
[
'desc_zh'
]
else
args
[
'desc_zh'
]
}
recommended_app
.
copyright
=
copy_right
recommended_app
.
copyright
=
copy_right
recommended_app
.
privacy_policy
=
privacy_policy
recommended_app
.
privacy_policy
=
privacy_policy
recommended_app
.
language
=
args
[
'language'
]
recommended_app
.
category
=
args
[
'category'
]
recommended_app
.
category
=
args
[
'category'
]
recommended_app
.
position
=
args
[
'position'
]
recommended_app
.
position
=
args
[
'position'
]
...
...
api/controllers/console/explore/recommended_app.py
View file @
02378337
...
@@ -43,8 +43,11 @@ class RecommendedAppListApi(Resource):
...
@@ -43,8 +43,11 @@ class RecommendedAppListApi(Resource):
@
account_initialization_required
@
account_initialization_required
@
marshal_with
(
recommended_app_list_fields
)
@
marshal_with
(
recommended_app_list_fields
)
def
get
(
self
):
def
get
(
self
):
language_prefix
=
current_user
.
interface_language
if
current_user
.
interface_language
else
'en-US'
recommended_apps
=
db
.
session
.
query
(
RecommendedApp
)
.
filter
(
recommended_apps
=
db
.
session
.
query
(
RecommendedApp
)
.
filter
(
RecommendedApp
.
is_listed
==
True
RecommendedApp
.
is_listed
==
True
,
RecommendedApp
.
language
==
language_prefix
)
.
all
()
)
.
all
()
categories
=
set
()
categories
=
set
()
...
@@ -62,21 +65,17 @@ class RecommendedAppListApi(Resource):
...
@@ -62,21 +65,17 @@ class RecommendedAppListApi(Resource):
if
not
app
or
not
app
.
is_public
:
if
not
app
or
not
app
.
is_public
:
continue
continue
language_prefix
=
current_user
.
interface_language
.
split
(
'-'
)[
0
]
site
=
app
.
site
desc
=
None
if
not
site
:
if
recommended_app
.
description
:
continue
if
language_prefix
in
recommended_app
.
description
:
desc
=
recommended_app
.
description
[
language_prefix
]
elif
'en'
in
recommended_app
.
description
:
desc
=
recommended_app
.
description
[
'en'
]
recommended_app_result
=
{
recommended_app_result
=
{
'id'
:
recommended_app
.
id
,
'id'
:
recommended_app
.
id
,
'app'
:
app
,
'app'
:
app
,
'app_id'
:
recommended_app
.
app_id
,
'app_id'
:
recommended_app
.
app_id
,
'description'
:
desc
,
'description'
:
site
.
description
,
'copyright'
:
recommended_app
.
copyright
,
'copyright'
:
site
.
copyright
,
'privacy_policy'
:
recommended_app
.
privacy_policy
,
'privacy_policy'
:
site
.
privacy_policy
,
'category'
:
recommended_app
.
category
,
'category'
:
recommended_app
.
category
,
'position'
:
recommended_app
.
position
,
'position'
:
recommended_app
.
position
,
'is_listed'
:
recommended_app
.
is_listed
,
'is_listed'
:
recommended_app
.
is_listed
,
...
...
api/migrations/versions/a45f4dfde53b_add_language_to_recommend_apps.py
0 → 100644
View file @
02378337
"""add language to recommend apps
Revision ID: a45f4dfde53b
Revises: 9f4e3427ea84
Create Date: 2023-05-25 17:50:32.052335
"""
from
alembic
import
op
import
sqlalchemy
as
sa
# revision identifiers, used by Alembic.
revision
=
'a45f4dfde53b'
down_revision
=
'9f4e3427ea84'
branch_labels
=
None
depends_on
=
None
def
upgrade
():
# ### commands auto generated by Alembic - please adjust! ###
with
op
.
batch_alter_table
(
'recommended_apps'
,
schema
=
None
)
as
batch_op
:
batch_op
.
add_column
(
sa
.
Column
(
'language'
,
sa
.
String
(
length
=
255
),
server_default
=
sa
.
text
(
"'en-US'::character varying"
),
nullable
=
False
))
batch_op
.
drop_index
(
'recommended_app_is_listed_idx'
)
batch_op
.
create_index
(
'recommended_app_is_listed_idx'
,
[
'is_listed'
,
'language'
],
unique
=
False
)
# ### end Alembic commands ###
def
downgrade
():
# ### commands auto generated by Alembic - please adjust! ###
with
op
.
batch_alter_table
(
'recommended_apps'
,
schema
=
None
)
as
batch_op
:
batch_op
.
drop_index
(
'recommended_app_is_listed_idx'
)
batch_op
.
create_index
(
'recommended_app_is_listed_idx'
,
[
'is_listed'
],
unique
=
False
)
batch_op
.
drop_column
(
'language'
)
# ### end Alembic commands ###
api/models/model.py
View file @
02378337
...
@@ -123,7 +123,7 @@ class RecommendedApp(db.Model):
...
@@ -123,7 +123,7 @@ class RecommendedApp(db.Model):
__table_args__
=
(
__table_args__
=
(
db
.
PrimaryKeyConstraint
(
'id'
,
name
=
'recommended_app_pkey'
),
db
.
PrimaryKeyConstraint
(
'id'
,
name
=
'recommended_app_pkey'
),
db
.
Index
(
'recommended_app_app_id_idx'
,
'app_id'
),
db
.
Index
(
'recommended_app_app_id_idx'
,
'app_id'
),
db
.
Index
(
'recommended_app_is_listed_idx'
,
'is_listed'
)
db
.
Index
(
'recommended_app_is_listed_idx'
,
'is_listed'
,
'language'
)
)
)
id
=
db
.
Column
(
UUID
,
primary_key
=
True
,
server_default
=
db
.
text
(
'uuid_generate_v4()'
))
id
=
db
.
Column
(
UUID
,
primary_key
=
True
,
server_default
=
db
.
text
(
'uuid_generate_v4()'
))
...
@@ -135,6 +135,7 @@ class RecommendedApp(db.Model):
...
@@ -135,6 +135,7 @@ class RecommendedApp(db.Model):
position
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
position
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
is_listed
=
db
.
Column
(
db
.
Boolean
,
nullable
=
False
,
default
=
True
)
is_listed
=
db
.
Column
(
db
.
Boolean
,
nullable
=
False
,
default
=
True
)
install_count
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
install_count
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
0
)
language
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
,
server_default
=
db
.
text
(
"'en-US'::character varying"
))
created_at
=
db
.
Column
(
db
.
DateTime
,
nullable
=
False
,
server_default
=
db
.
text
(
'CURRENT_TIMESTAMP(0)'
))
created_at
=
db
.
Column
(
db
.
DateTime
,
nullable
=
False
,
server_default
=
db
.
text
(
'CURRENT_TIMESTAMP(0)'
))
updated_at
=
db
.
Column
(
db
.
DateTime
,
nullable
=
False
,
server_default
=
db
.
text
(
'CURRENT_TIMESTAMP(0)'
))
updated_at
=
db
.
Column
(
db
.
DateTime
,
nullable
=
False
,
server_default
=
db
.
text
(
'CURRENT_TIMESTAMP(0)'
))
...
@@ -143,17 +144,6 @@ class RecommendedApp(db.Model):
...
@@ -143,17 +144,6 @@ class RecommendedApp(db.Model):
app
=
db
.
session
.
query
(
App
)
.
filter
(
App
.
id
==
self
.
app_id
)
.
first
()
app
=
db
.
session
.
query
(
App
)
.
filter
(
App
.
id
==
self
.
app_id
)
.
first
()
return
app
return
app
# def set_description(self, lang, desc):
# if self.description is None:
# self.description = {}
# self.description[lang] = desc
def
get_description
(
self
,
lang
):
if
self
.
description
and
lang
in
self
.
description
:
return
self
.
description
[
lang
]
else
:
return
self
.
description
.
get
(
'en'
)
class
InstalledApp
(
db
.
Model
):
class
InstalledApp
(
db
.
Model
):
__tablename__
=
'installed_apps'
__tablename__
=
'installed_apps'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment