Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
IDATT2900-072
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mattias Agentoft Eggen
IDATT2900-072
Commits
1c13c39e
Commit
1c13c39e
authored
3 years ago
by
magnus2142
Browse files
Options
Downloads
Patches
Plain Diff
Added a way to update content
parent
cb2a3756
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bbcli/cli.py
+2
-1
2 additions, 1 deletion
bbcli/cli.py
bbcli/commands/contents.py
+12
-0
12 additions, 0 deletions
bbcli/commands/contents.py
bbcli/services/contents_service.py
+31
-1
31 additions, 1 deletion
bbcli/services/contents_service.py
with
45 additions
and
2 deletions
bbcli/cli.py
+
2
−
1
View file @
1c13c39e
...
...
@@ -9,7 +9,7 @@ import click
from
bbcli.commands.courses
import
list_courses
from
bbcli.commands.announcements
import
list_announcements
,
create_announcement
,
delete_announcement
,
update_announcement
from
bbcli.commands.contents
import
create_assignment
,
create_courselink
,
create_folder
,
delete_content
,
list_contents
,
create_document
,
create_file
,
create_web_link
,
upload_attachment
from
bbcli.commands.contents
import
create_assignment
,
create_courselink
,
create_folder
,
delete_content
,
list_contents
,
create_document
,
create_file
,
create_web_link
,
update_content
,
upload_attachment
from
bbcli.services.authorization_service
import
login
load_dotenv
()
...
...
@@ -91,6 +91,7 @@ def contents(ctx):
contents
.
add_command
(
list_contents
)
contents
.
add_command
(
delete_content
)
contents
.
add_command
(
update_content
)
"""
CONTENTS CREATE COMMANDS ENTRY POINT
...
...
This diff is collapsed.
Click to expand it.
bbcli/commands/contents.py
+
12
−
0
View file @
1c13c39e
...
...
@@ -196,6 +196,18 @@ def delete_content(ctx, course_id: str, content_id: str, delete_grades: bool):
response
=
contents_service
.
delete_content
(
ctx
.
obj
[
'
SESSION
'
],
course_id
,
content_id
,
delete_grades
)
click
.
echo
(
response
)
@click.command
(
name
=
'
update
'
)
@click.argument
(
'
course_id
'
,
required
=
True
,
type
=
str
)
@click.argument
(
'
content_id
'
,
required
=
True
,
type
=
str
)
@click.pass_context
def
update_content
(
ctx
,
course_id
:
str
,
content_id
:
str
):
"""
Updates a given content
Editable content types: document, files, assignments, externallinks, courselinks
"""
response
=
contents_service
.
update_content
(
ctx
.
obj
[
'
SESSION
'
],
course_id
,
content_id
)
click
.
echo
(
response
)
"""
HELPER FUNCTIONS
"""
...
...
This diff is collapsed.
Click to expand it.
bbcli/services/contents_service.py
+
31
−
1
View file @
1c13c39e
...
...
@@ -8,6 +8,7 @@ from bbcli.utils.URL_builder import URLBuilder
from
bbcli.services.utils.content_builder
import
ContentBuilder
from
bbcli.entities.content_builder_entitites
import
DateInterval
,
FileContent
,
GradingOptions
,
StandardOptions
,
FileOptions
,
WeblinkOptions
from
bbcli.utils.utils
import
input_body
import
click
url_builder
=
URLBuilder
()
content_builder
=
ContentBuilder
()
...
...
@@ -182,6 +183,27 @@ def delete_content(session: requests.Session, course_id: str, content_id: str, d
return
response
.
text
def
update_content
(
session
:
requests
.
Session
,
course_id
:
str
,
content_id
:
str
):
url
=
url_builder
.
base_v1
().
add_courses
().
add_id
(
course_id
).
add_contents
().
add_id
(
content_id
).
create
()
content
=
session
.
get
(
url
)
content
=
json
.
loads
(
content
.
text
)
if
not
is_editable_content_type
(
content
[
'
contentHandler
'
][
'
id
'
]):
click
.
echo
(
'
This content type is not editable
'
)
raise
click
.
Abort
()
if
'
links
'
in
content
:
del
content
[
'
links
'
]
if
'
contentHandler
'
in
content
:
del
content
[
'
contentHandler
'
]
MARKER
=
'
# Everything below is ignored.
\n
'
editable_data
=
json
.
dumps
(
content
,
indent
=
2
)
print
(
editable_data
)
new_data
=
click
.
edit
(
editable_data
+
'
\n\n
'
+
MARKER
)
response
=
session
.
patch
(
url
,
data
=
new_data
)
return
response
.
text
"""
HELPER FUNCTIONS
...
...
@@ -216,4 +238,12 @@ def generate_create_content_url(course_id: str, content_id: str):
def
handle_attachments
(
session
:
requests
.
Session
,
course_id
:
str
,
content_id
:
str
,
attachments
:
tuple
or
None
):
if
attachments
:
for
attachment
in
attachments
:
upload_attachment
(
session
,
course_id
,
content_id
,
attachment
)
\ No newline at end of file
upload_attachment
(
session
,
course_id
,
content_id
,
attachment
)
def
is_editable_content_type
(
content_type
:
str
):
valid_content_types
=
[
'
resource/x-bb-assignment
'
,
'
resource/x-bb-externallink
'
,
'
resource/x-bb-courselink
'
,
'
resource/x-bb-file
'
,
'
resource/x-bb-document
'
]
for
type
in
valid_content_types
:
if
content_type
==
type
:
return
True
return
False
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment