Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sebastian Gottschalk
bmdl-expert-modeler
Commits
fc014701
Commit
fc014701
authored
Nov 15, 2021
by
Alexander Philipp Nowosad
Browse files
Fix load docs only one time
parent
71e1b7aa
Pipeline
#139482
passed with stages
in 10 minutes and 13 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
group-management/group_management/commands.py
View file @
fc014701
...
...
@@ -54,7 +54,7 @@ def db(ctx, server, name):
@
click
.
argument
(
'initdata'
,
type
=
click
.
File
(
'rb'
),
nargs
=-
1
)
@
click
.
make_pass_decorator
(
Database
)
def
init
(
database
,
initdata
):
management
.
init_db
(
database
,
initdata
)
management
.
init_db
(
database
,
initdata
=
initdata
)
click
.
secho
(
'Sucessfully initialized database {}.'
.
format
(
database
.
name
),
fg
=
'green'
...
...
group-management/group_management/management.py
View file @
fc014701
...
...
@@ -21,14 +21,16 @@ def check_server_maintenance_mode(server):
def
set_server_maintenance
(
server
,
value
):
server
.
maintenance
(
value
)
def
init_db
(
database
,
initdata
):
def
init_db
(
database
,
initdata
=
None
,
docs
=
None
):
if
not
Expressions
.
GROUP
.
match
(
database
.
name
):
raise
ManagementException
(
'Database for group should have the form "group[0-9]+"'
)
database
.
create_if_not_exists
()
if
len
(
initdata
)
>
0
:
if
initdata
is
not
None
and
len
(
initdata
)
>
0
:
database
.
bulk_create
(
utils
.
import_docs
(
initdata
))
if
docs
is
not
None
:
database
.
bulk_create
(
docs
)
database
.
security
({
'members'
:
{
'roles'
:
[
'_admin'
,
database
.
name
,
'mgmt_backup'
]
},
'admins'
:
{
'roles'
:
[
'_admin'
]
}
...
...
@@ -81,6 +83,7 @@ def init_server(server, usersfile, passwordsfile, initdata):
writer
=
utils
.
csv_writer
(
passwordsfile
)
users
=
utils
.
import_csv
(
usersfile
)
groups
=
defaultdict
(
list
)
docs
=
utils
.
import_docs
(
initdata
)
for
i
,
(
username
,
group
)
in
enumerate
(
users
):
if
not
Expressions
.
GROUP
.
match
(
group
):
raise
ManagementException
(
...
...
@@ -94,7 +97,7 @@ def init_server(server, usersfile, passwordsfile, initdata):
database
.
server
=
server
database
.
name
=
group
if
not
database
.
exists
():
init_db
(
database
,
initdata
)
init_db
(
database
,
docs
=
docs
)
for
username
in
users
:
user
=
User
()
user
.
server
=
server
...
...
Write
Preview
Supports
Markdown
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