Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thomasDOTwtf
hub
Commits
af5a07cb
Commit
af5a07cb
authored
9 months ago
by
Roang
Browse files
Options
Downloads
Patches
Plain Diff
Add date validation for create_conference
parent
6ed61166
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/core/management/commands/create_conference.py
+18
-5
18 additions, 5 deletions
src/core/management/commands/create_conference.py
with
18 additions
and
5 deletions
src/core/management/commands/create_conference.py
+
18
−
5
View file @
af5a07cb
from
argparse
import
BooleanOptionalAction
from
argparse
import
ArgumentTypeError
,
BooleanOptionalAction
from
datetime
import
datetime
from
zoneinfo
import
ZoneInfo
...
...
@@ -331,6 +331,13 @@ def seed_conference(conf: Conference, year: int = 0, force: bool = False):
)
def
_validate_date
(
s
:
str
)
->
datetime
:
try
:
return
datetime
.
strptime
(
s
,
'
%Y
'
)
# noqa: DTZ007
except
ValueError
as
exc
:
raise
ArgumentTypeError
(
f
"
Not a valid date:
{
s
!r}
. Use format
'
YYYY
'"
)
from
exc
class
Command
(
BaseCommand
):
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
...
...
@@ -348,7 +355,7 @@ class Command(BaseCommand):
parser
.
add_argument
(
'
-y
'
,
'
--year
'
,
type
=
int
,
type
=
_validate_date
,
help
=
'
The year of the CCC congress. If not given, it will use the current year.
'
,
)
parser
.
add_argument
(
...
...
@@ -363,9 +370,15 @@ class Command(BaseCommand):
if
not
(
name
:
=
options
.
get
(
'
name
'
)):
name
=
input
(
'
NAME of the new conference (long title):
'
)
if
not
(
year
:
=
options
.
get
(
'
year
'
)):
year_valid
=
False
while
not
year_valid
:
year
=
input
(
"
YEAR of the CCC congress (leave empty if it
'
s something else):
"
)
year
=
int
(
year
or
'
0
'
)
try
:
year
=
datetime
.
strptime
(
year
,
'
%Y
'
)
# noqa: DTZ007
year_valid
=
True
except
ValueError
:
self
.
stderr
.
write
(
'
Invalid year format. Please use YYYY.
'
)
year
=
year
.
year
print
(
f
'
Creating conference
{
slug
}
(
{
name
}
) for year
{
year
}
'
)
# load our bootstrap fixtures
...
...
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