Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
f82cf376
Verified
Commit
f82cf376
authored
5 years ago
by
Tom Teichler
Browse files
Options
Downloads
Patches
Plain Diff
Fix getting date
parent
30d0e737
No related branches found
No related tags found
1 merge request
!176
Resolve "DateTimeField Announcement.valid_from received a naive datetime"
Pipeline
#998
failed
5 years ago
Stage: test
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/core/forms.py
+3
-3
3 additions, 3 deletions
aleksis/core/forms.py
aleksis/core/models.py
+2
-2
2 additions, 2 deletions
aleksis/core/models.py
aleksis/core/util/core_helpers.py
+1
-1
1 addition, 1 deletion
aleksis/core/util/core_helpers.py
with
6 additions
and
6 deletions
aleksis/core/forms.py
+
3
−
3
View file @
f82cf376
...
...
@@ -166,9 +166,9 @@ class AnnouncementForm(forms.ModelForm):
def
__init__
(
self
,
*
args
,
**
kwargs
):
if
"
instance
"
not
in
kwargs
:
kwargs
[
"
initial
"
]
=
{
"
valid_from_date
"
:
timezone
.
datetime
.
now
(),
"
valid_from_date
"
:
timezone
.
now
(),
"
valid_from_time
"
:
time
(
0
,
0
),
"
valid_until_date
"
:
timezone
.
datetime
.
now
(),
"
valid_until_date
"
:
timezone
.
now
(),
"
valid_until_time
"
:
time
(
23
,
59
),
}
else
:
...
...
@@ -197,7 +197,7 @@ class AnnouncementForm(forms.ModelForm):
valid_from
=
timezone
.
datetime
.
combine
(
from_date
,
from_time
)
valid_until
=
timezone
.
datetime
.
combine
(
until_date
,
until_time
)
if
valid_until
<
timezone
.
datetime
.
now
():
if
valid_until
<
timezone
.
now
():
raise
ValidationError
(
_
(
"
You are not allowed to create announcements which are only valid in the past.
"
)
)
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/models.py
+
2
−
2
View file @
f82cf376
...
...
@@ -283,7 +283,7 @@ class Announcement(ExtensibleModel):
link
=
models
.
URLField
(
blank
=
True
,
verbose_name
=
_
(
"
Link
"
))
valid_from
=
models
.
DateTimeField
(
verbose_name
=
_
(
"
Date and time from when to show
"
),
default
=
timezone
.
datetime
.
now
verbose_name
=
_
(
"
Date and time from when to show
"
),
default
=
timezone
.
now
)
valid_until
=
models
.
DateTimeField
(
verbose_name
=
_
(
"
Date and time until when to show
"
),
...
...
@@ -308,7 +308,7 @@ class Announcement(ExtensibleModel):
@classmethod
def
for_person_at_time
(
cls
,
person
:
Person
,
when
:
Optional
[
datetime
]
=
None
)
->
List
:
"""
Get all announcements for one person at a certain time
"""
when
=
when
or
timezone
.
datetime
.
now
()
when
=
when
or
timezone
.
now
()
# Get announcements by time
announcements
=
cls
.
objects
.
filter
(
valid_from__lte
=
when
,
valid_until__gte
=
when
)
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/util/core_helpers.py
+
1
−
1
View file @
f82cf376
...
...
@@ -154,4 +154,4 @@ def school_information_processor(request: HttpRequest) -> dict:
def
now_tomorrow
()
->
datetime
:
"""
Return current time tomorrow
"""
return
timezone
.
datetime
.
now
()
+
timedelta
(
days
=
1
)
return
timezone
.
now
()
+
timedelta
(
days
=
1
)
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