Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
AURA
steering
Commits
68a9cd40
Verified
Commit
68a9cd40
authored
8 months ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
feat: replace addnote management command with updatenote
parent
5723cc62
No related branches found
No related tags found
No related merge requests found
Pipeline
#8372
passed
8 months ago
Stage: check
Stage: test
Stage: build
Stage: deploy
Stage: release
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
program/management/commands/addnote.py
+0
-68
0 additions, 68 deletions
program/management/commands/addnote.py
program/management/commands/updatenote.py
+68
-0
68 additions, 0 deletions
program/management/commands/updatenote.py
with
68 additions
and
68 deletions
program/management/commands/addnote.py
deleted
100644 → 0
+
0
−
68
View file @
5723cc62
import
sys
from
django.core.exceptions
import
ValidationError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
program.models
import
Note
,
Show
,
TimeSlot
from
program.utils
import
parse_date
class
Command
(
BaseCommand
):
help
=
"
adds a note to a timeslot
"
args
=
"
<show_id> <start_date> <status> [index]
"
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
==
3
:
show_id
=
args
[
0
]
start_date
=
args
[
1
]
status
=
args
[
2
]
elif
len
(
args
)
==
4
:
show_id
=
args
[
0
]
start_date
=
args
[
1
]
status
=
args
[
2
]
index
=
args
[
3
]
else
:
raise
CommandError
(
"
you must provide the show_id, start_date, status [index]
"
)
try
:
show
=
Show
.
objects
.
get
(
id
=
show_id
)
except
Show
.
DoesNotExist
as
dne
:
raise
CommandError
(
dne
)
try
:
start
=
parse_date
(
start_date
)
except
ValueError
as
ve
:
raise
CommandError
(
ve
)
else
:
year
,
month
,
day
=
start
.
year
,
start
.
month
,
start
.
day
try
:
timeslot
=
TimeSlot
.
objects
.
get
(
show
=
show
,
start__year
=
year
,
start__month
=
month
,
start__day
=
day
)
except
TimeSlot
.
DoesNotExist
as
dne
:
raise
CommandError
(
dne
)
except
TimeSlot
.
MultipleObjectsReturned
:
if
not
index
:
raise
CommandError
(
"
you must provide the show_id, start_date, status index
"
)
try
:
timeslot
=
TimeSlot
.
objects
.
filter
(
show
=
show
,
start__year
=
year
,
start__month
=
month
,
start__day
=
day
).
order_by
(
"
start
"
)[
int
(
index
)]
except
IndexError
as
ie
:
raise
CommandError
(
ie
)
try
:
title
=
sys
.
stdin
.
readline
().
rstrip
()
lines
=
sys
.
stdin
.
readlines
()
except
Exception
as
e
:
raise
CommandError
(
e
)
note
=
Note
(
timeslot
=
timeslot
,
title
=
title
,
content
=
""
.
join
(
lines
),
status
=
status
)
try
:
note
.
validate_unique
()
except
ValidationError
as
ve
:
raise
CommandError
(
ve
.
messages
[
0
])
else
:
note
.
save
()
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
,
f
'
added note
"
{
title
}
"
to
"
{
timeslot
}
"'
)
This diff is collapsed.
Click to expand it.
program/management/commands/updatenote.py
0 → 100644
+
68
−
0
View file @
68a9cd40
import
sys
from
django.core.exceptions
import
MultipleObjectsReturned
,
ObjectDoesNotExist
from
django.core.management.base
import
BaseCommand
,
CommandError
from
program.models
import
Note
,
Show
from
program.utils
import
parse_date
class
Command
(
BaseCommand
):
help
=
"
updates title and content of a note for a timeslot by reading both from stdin.
"
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
"
show_id
"
,
help
=
"
ID of the show
"
,
type
=
int
)
parser
.
add_argument
(
"
date
"
,
help
=
"
date of the timeslot
"
,
type
=
str
)
parser
.
add_argument
(
"
index
"
,
default
=
None
,
help
=
"
index of the timeslot within the date. (default: 0)
"
,
nargs
=
"
?
"
,
type
=
int
,
)
def
handle
(
self
,
*
args
,
**
options
):
try
:
show
=
Show
.
objects
.
get
(
pk
=
options
[
"
show_id
"
])
except
ObjectDoesNotExist
as
e
:
raise
CommandError
(
e
)
try
:
date
=
parse_date
(
options
[
"
date
"
])
except
ValueError
as
e
:
raise
CommandError
(
e
)
else
:
year
,
month
,
day
=
date
.
year
,
date
.
month
,
date
.
day
try
:
note
=
Note
.
objects
.
get
(
timeslot__schedule__show
=
show
,
timeslot__start__day
=
day
,
timeslot__start__month
=
month
,
timeslot__start__year
=
year
,
)
except
ObjectDoesNotExist
as
e
:
raise
CommandError
(
e
)
except
MultipleObjectsReturned
:
if
not
options
[
"
index
"
]:
raise
CommandError
(
f
"
more than one note within
{
date
}
. Please provide an index.
"
)
try
:
note
=
Note
.
objects
.
filter
(
timeslot__schedule__show
=
show
,
timeslot__start__day
=
day
,
timeslot__start__month
=
month
,
timeslot__start__year
=
year
,
).
order_by
(
"
timeslot__start
"
)[
options
[
"
index
"
]]
except
IndexError
as
e
:
raise
CommandError
(
e
)
try
:
title
=
sys
.
stdin
.
readline
().
strip
()
content
=
sys
.
stdin
.
read
()
except
Exception
as
e
:
raise
CommandError
(
e
)
note
.
title
=
title
note
.
content
=
content
note
.
save
()
self
.
stdout
.
write
(
self
.
style
.
SUCCESS
(
f
'
updated note
"
{
title
}
"
for
{
note
.
timeslot
}
'
))
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