SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
SciPost
SciPost
Commits
a51b1b3f
Commit
a51b1b3f
authored
1 year ago
by
George Katsikas
Browse files
Options
Downloads
Patches
Plain Diff
add errors and prefilled dates to round start
parent
f46cdf25
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!58
[Fellowship Nominations] Rework the fellowship nomination system and UI
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scipost_django/colleges/forms.py
+47
-28
47 additions, 28 deletions
scipost_django/colleges/forms.py
scipost_django/colleges/views.py
+13
-20
13 additions, 20 deletions
scipost_django/colleges/views.py
with
60 additions
and
48 deletions
scipost_django/colleges/forms.py
+
47
−
28
View file @
a51b1b3f
...
...
@@ -3,7 +3,7 @@ __license__ = "AGPL v3"
import
datetime
from
typing
import
Dict
from
typing
import
Any
,
Dict
from
django
import
forms
from
django.contrib.sessions.backends.db
import
SessionStore
...
...
@@ -15,6 +15,7 @@ from crispy_bootstrap5.bootstrap5 import FloatingField
from
dal
import
autocomplete
from
django.urls
import
reverse
from
django.utils
import
timezone
from
django.utils.timezone
import
timedelta
from
ontology.models
import
Specialty
from
proceedings.models
import
Proceedings
...
...
@@ -918,20 +919,32 @@ class FellowshipNominationVotingRoundStartForm(forms.ModelForm):
fields
=
[
"
voting_opens
"
,
"
voting_deadline
"
]
widgets
=
{
"
voting_opens
"
:
forms
.
DateInput
(
attrs
=
{
"
type
"
:
"
date
"
,
"
min
"
:
date
.
today
()}
),
"
voting_deadline
"
:
forms
.
DateInput
(
attrs
=
{
"
type
"
:
"
date
"
,
"
min
"
:
date
.
today
()}
),
"
voting_opens
"
:
forms
.
DateInput
(
attrs
=
{
"
type
"
:
"
date
"
}),
"
voting_deadline
"
:
forms
.
DateInput
(
attrs
=
{
"
type
"
:
"
date
"
}),
}
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
today
=
date
.
today
()
self
.
fields
[
"
voting_opens
"
].
widget
.
attrs
.
update
(
{
"
min
"
:
today
.
strftime
(
"
%Y-%m-%d
"
),
"
value
"
:
today
.
strftime
(
"
%Y-%m-%d
"
),
}
)
in_two_weeks
=
today
+
timedelta
(
days
=
14
)
self
.
fields
[
"
voting_deadline
"
].
widget
.
attrs
.
update
(
{
"
min
"
:
today
.
strftime
(
"
%Y-%m-%d
"
),
"
value
"
:
in_two_weeks
.
strftime
(
"
%Y-%m-%d
"
),
}
)
self
.
helper
=
FormHelper
()
self
.
helper
.
attrs
=
{
"
hx-target
"
:
f
"
nomination-
{
self
.
instance
.
nomination
.
id
}
-round-tab-holder
"
,
"
hx-target
"
:
f
"
#
nomination-
{
self
.
instance
.
nomination
.
id
}
-round-tab-holder
"
,
"
hx-swap
"
:
"
outerHTML
"
,
"
hx-post
"
:
reverse
(
"
colleges:_hx_nomination_voting_rounds_tab
"
,
...
...
@@ -954,28 +967,34 @@ class FellowshipNominationVotingRoundStartForm(forms.ModelForm):
)
def
clean
(
self
):
if
self
.
is_valid
():
# Check that the voting deadline is after the voting opens
if
(
self
.
cleaned_data
[
"
voting_deadline
"
]
<=
self
.
cleaned_data
[
"
voting_opens
"
]
):
self
.
add_error
(
"
voting_deadline
"
,
"
The voting deadline must be after the voting opens.
"
,
)
open_date
=
self
.
cleaned_data
.
get
(
"
voting_opens
"
,
None
)
deadline_date
=
self
.
cleaned_data
.
get
(
"
voting_deadline
"
,
None
)
# Check that the voting opens is after today
if
self
.
cleaned_data
[
"
voting_opens
"
]
<
date
.
today
():
self
.
add_error
(
"
voting
_
opens
"
,
"
The
voting
opens dat
e must be
after today
.
"
)
if
open_date
is
None
or
deadline_date
is
None
:
self
.
add_error
(
None
,
"
Both the
voting
opens
and
voting
deadlin
e must be
set
.
"
,
)
def
save
(
self
):
voting_round
=
super
().
save
(
commit
=
False
)
voting_round
.
save
()
print
(
self
.
fields
[
"
voting_opens
"
])
return
voting_round
# Check that the voting deadline is after the voting opens
if
deadline_date
<=
open_date
:
self
.
add_error
(
"
voting_deadline
"
,
"
The voting deadline must be after the voting opens.
"
,
)
# Check that the voting opens after today
if
open_date
.
date
()
<
date
.
today
():
self
.
add_error
(
"
voting_opens
"
,
"
The voting opening date may not be in the past.
"
)
if
self
.
instance
.
eligible_to_vote
.
count
()
==
0
:
self
.
add_error
(
None
,
"
There must be at least one eligible voter to start the round.
"
"
Please add voters to the round before setting the dates.
"
,
)
###############
...
...
This diff is collapsed.
Click to expand it.
scipost_django/colleges/views.py
+
13
−
20
View file @
a51b1b3f
...
...
@@ -921,27 +921,19 @@ def _hx_nomination_voting_rounds_tab(request, nomination_id, round_id):
selected_round
=
voting_rounds
.
get
(
id
=
round_id
)
context
[
"
selected_round
"
]
=
selected_round
print
(
request
.
POST
)
if
selected_round
.
voting_opens
is
None
:
today
=
datetime
.
date
.
today
()
round_start_form
=
FellowshipNominationVotingRoundStartForm
(
request
.
POST
or
None
,
instance
=
selected_round
,
initial
=
{
"
voting_opens
"
:
today
,
"
voting_deadline
"
:
today
+
datetime
.
timedelta
(
days
=
14
),
}
if
(
request
.
POST
is
None
)
and
(
selected_round
.
voting_opens
is
None
)
else
None
,
round_start_form
=
FellowshipNominationVotingRoundStartForm
(
request
.
POST
or
None
,
instance
=
selected_round
,
)
if
round_start_form
.
is_valid
():
round_start_form
.
save
()
messages
.
success
(
request
,
f
"
Voting round for
{
nomination
.
profile
}
started
"
f
"
from
{
selected_round
.
voting_opens
}
until
{
selected_round
.
voting_deadline
}
.
"
,
)
if
round_start_form
.
is_valid
():
round_start_form
.
save
()
messages
.
success
(
request
,
f
"
Voting round for
{
nomination
.
profile
}
started from now until
{
selected_round
.
voting_deadline
}
.
"
,
)
context
[
"
round_start_form
"
]
=
round_start_form
context
[
"
round_start_form
"
]
=
round_start_form
return
render
(
request
,
"
colleges/_hx_nomination_voting_rounds_tab.html
"
,
context
)
...
...
@@ -1259,5 +1251,6 @@ def _hx_nomination_voter_table(request, round_id):
context
=
{
"
voters
"
:
voters
,
"
round
"
:
round
,
}
return
render
(
request
,
"
colleges/_hx_nomination_voter_table.html
"
,
context
)
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