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
cb9dc200
Commit
cb9dc200
authored
2 years ago
by
Jonathan Weth
Committed by
Hangzhi Yu
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Build Holiday model on top of CalendarEvent
parent
fa4600ee
No related branches found
No related tags found
1 merge request
!1148
Calendar events and iCal feeds
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/core/managers.py
+3
-3
3 additions, 3 deletions
aleksis/core/managers.py
aleksis/core/migrations/0052_holiday.py
+36
-0
36 additions, 0 deletions
aleksis/core/migrations/0052_holiday.py
aleksis/core/models.py
+3
-17
3 additions, 17 deletions
aleksis/core/models.py
with
42 additions
and
20 deletions
aleksis/core/managers.py
+
3
−
3
View file @
cb9dc200
...
...
@@ -8,7 +8,7 @@ from django.db.models.manager import Manager
from
calendarweek
import
CalendarWeek
from
django_cte
import
CTEManager
,
CTEQuerySet
from
polymorphic.managers
import
PolymorphicManager
from
polymorphic.managers
import
PolymorphicManager
,
PolymorphicQuerySet
class
CurrentSiteManagerWithoutMigrations
(
_CurrentSiteManager
):
...
...
@@ -123,11 +123,11 @@ class InstalledWidgetsDashboardWidgetOrderManager(Manager):
return
super
().
get_queryset
().
filter
(
widget_id__in
=
dashboard_widget_pks
)
class
PolymorphicCurrentSiteManager
(
_
CurrentSiteManager
,
PolymorphicManager
):
class
PolymorphicCurrentSiteManager
(
CurrentSiteManager
WithoutMigrations
,
PolymorphicManager
):
"""
Default manager for extensible, polymorphic models.
"""
class
HolidayQuerySet
(
QuerySet
,
DateRangeQuerySetMixin
):
class
HolidayQuerySet
(
DateRangeQuerySetMixin
,
PolymorphicQuerySet
):
"""
QuerySet with custom query methods for holidays.
"""
def
get_all_days
(
self
)
->
list
[
date
]:
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/migrations/005
1
_holiday.py
→
aleksis/core/migrations/005
2
_holiday.py
+
36
−
0
View file @
cb9dc200
# Generated by Django 4.1.
7
on 2023-0
2-27
14:
32
# Generated by Django 4.1.
8
on 2023-0
4-09
14:
09
import
aleksis.core.mixins
from
django.db
import
migrations
,
models
import
django.db.models.deletion
...
...
@@ -8,7 +7,7 @@ import django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
"
sites
"
,
"
0002_alter_domain_unique
"
),
(
"
core
"
,
"
005
0_fix_amend
s
"
),
(
"
core
"
,
"
005
1_calendarevent_date
s
"
),
]
operations
=
[
...
...
@@ -16,31 +15,22 @@ class Migration(migrations.Migration):
name
=
"
Holiday
"
,
fields
=
[
(
"
id
"
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
"
ID
"
),
),
(
"
extended_data
"
,
models
.
JSONField
(
default
=
dict
,
editable
=
False
)),
(
"
holiday_name
"
,
models
.
CharField
(
max_length
=
255
,
verbose_name
=
"
Name
"
)),
(
"
date_start
"
,
models
.
DateField
(
verbose_name
=
"
Start date
"
)),
(
"
date_end
"
,
models
.
DateField
(
verbose_name
=
"
End date
"
)),
(
"
site
"
,
models
.
ForeignKey
(
default
=
1
,
editable
=
False
,
"
calendarevent_ptr
"
,
models
.
OneToOneField
(
auto_created
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
"
+
"
,
to
=
"
sites.site
"
,
parent_link
=
True
,
primary_key
=
True
,
serialize
=
False
,
to
=
"
core.calendarevent
"
,
),
),
(
"
holiday_name
"
,
models
.
CharField
(
max_length
=
255
,
verbose_name
=
"
Name
"
)),
],
options
=
{
"
verbose_name
"
:
"
Holiday
"
,
"
verbose_name_plural
"
:
"
Holidays
"
,
"
ordering
"
:
[
"
date_start
"
],
},
bases
=
(
aleksis
.
core
.
mixins
.
C
alendar
E
vent
Mixin
,
models
.
Model
),
bases
=
(
"
core.c
alendar
e
vent
"
,
),
),
]
This diff is collapsed.
Click to expand it.
aleksis/core/models.py
+
3
−
17
View file @
cb9dc200
...
...
@@ -70,6 +70,7 @@ from .managers import (
GroupQuerySet
,
HolidayQuerySet
,
InstalledWidgetsDashboardWidgetOrderManager
,
PolymorphicCurrentSiteManager
,
SchoolTermQuerySet
,
UninstallRenitentPolymorphicManager
,
)
...
...
@@ -1588,7 +1589,7 @@ class BirthdayEvent(CalendarEventMixin):
return
qs
class
Holiday
(
CalendarEvent
Mixin
,
ExtensibleModel
):
class
Holiday
(
CalendarEvent
):
name
=
"
holidays
"
verbose_name
=
_
(
"
Holidays
"
)
...
...
@@ -1600,19 +1601,9 @@ class Holiday(CalendarEventMixin, ExtensibleModel):
def
value_description
(
cls
,
reference_object
):
return
""
@classmethod
def
value_start_datetime
(
cls
,
reference_object
):
return
reference_object
.
date_start
@classmethod
def
value_end_datetime
(
cls
,
reference_object
):
return
reference_object
.
date_end
+
timedelta
(
days
=
1
)
objects
=
CurrentSiteManagerWithoutMigrations
.
from_queryset
(
HolidayQuerySet
)()
objects
=
PolymorphicCurrentSiteManager
.
from_queryset
(
HolidayQuerySet
)()
holiday_name
=
models
.
CharField
(
verbose_name
=
_
(
"
Name
"
),
max_length
=
255
)
date_start
=
models
.
DateField
(
verbose_name
=
_
(
"
Start date
"
))
date_end
=
models
.
DateField
(
verbose_name
=
_
(
"
End date
"
))
def
get_days
(
self
)
->
Iterator
[
date
]:
delta
=
self
.
date_end
-
self
.
date_start
...
...
@@ -1645,14 +1636,9 @@ class Holiday(CalendarEventMixin, ExtensibleModel):
return
per_weekday
@classmethod
def
get_objects
(
cls
,
request
):
return
cls
.
objects
.
all
()
def
__str__
(
self
)
->
str
:
return
self
.
holiday_name
class
Meta
:
ordering
=
[
"
date_start
"
]
verbose_name
=
_
(
"
Holiday
"
)
verbose_name_plural
=
_
(
"
Holidays
"
)
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