Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Chronos
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
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-Chronos
Commits
4a199dc9
Verified
Commit
4a199dc9
authored
5 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Move TimetableWidget to models.py
parent
a7eb4dc1
No related branches found
No related tags found
1 merge request
!36
Dashboard widget for SMART PLAN
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/apps/chronos/admin.py
+1
-1
1 addition, 1 deletion
aleksis/apps/chronos/admin.py
aleksis/apps/chronos/dashboard.py
+0
-66
0 additions, 66 deletions
aleksis/apps/chronos/dashboard.py
aleksis/apps/chronos/models.py
+60
-2
60 additions, 2 deletions
aleksis/apps/chronos/models.py
with
61 additions
and
69 deletions
aleksis/apps/chronos/admin.py
+
1
−
1
View file @
4a199dc9
from
django.contrib
import
admin
from
.
dashboard
import
TimetableWidget
from
.
models
import
TimetableWidget
admin
.
site
.
register
(
TimetableWidget
)
This diff is collapsed.
Click to expand it.
aleksis/apps/chronos/dashboard.py
deleted
100644 → 0
+
0
−
66
View file @
a7eb4dc1
from
datetime
import
datetime
from
collections
import
OrderedDict
from
django.forms.widgets
import
Media
from
django.utils
import
timezone
from
django.utils.translation
import
gettext_lazy
as
_
from
django_global_request.middleware
import
get_request
from
aleksis.apps.chronos.models
import
TimePeriod
from
aleksis.apps.chronos.util.date
import
get_name_for_day_from_today
from
aleksis.core.models
import
DashboardWidget
from
aleksis.core.util.core_helpers
import
has_person
class
TimetableWidget
(
DashboardWidget
):
template
=
"
chronos/widget.html
"
def
get_context
(
self
):
request
=
get_request
()
context
=
{
"
has_plan
"
:
True
}
wanted_day
=
TimePeriod
.
get_next_relevant_day
(
timezone
.
now
().
date
(),
datetime
.
now
().
time
())
if
has_person
(
request
.
user
):
person
=
request
.
user
.
person
if
person
.
is_teacher
:
# Teacher
type_
=
"
teacher
"
lesson_periods_person
=
person
.
lesson_periods_as_teacher
elif
person
.
primary_group
:
# Student
type_
=
"
group
"
lesson_periods_person
=
person
.
lesson_periods_as_participant
else
:
# If no student or teacher, redirect to all timetables
context
[
"
has_plan
"
]
=
False
lesson_periods
=
lesson_periods_person
.
on_day
(
wanted_day
)
# Build dictionary with lessons
per_period
=
{}
for
lesson_period
in
lesson_periods
:
if
lesson_period
.
period
.
period
in
per_period
:
per_period
[
lesson_period
.
period
.
period
].
append
(
lesson_period
)
else
:
per_period
[
lesson_period
.
period
.
period
]
=
[
lesson_period
]
context
[
"
lesson_periods
"
]
=
OrderedDict
(
sorted
(
per_period
.
items
()))
context
[
"
type
"
]
=
type_
context
[
"
day
"
]
=
wanted_day
context
[
"
day_label
"
]
=
get_name_for_day_from_today
(
wanted_day
)
context
[
"
periods
"
]
=
TimePeriod
.
get_times_dict
()
context
[
"
smart
"
]
=
True
return
context
media
=
Media
(
css
=
{
"
all
"
:
(
"
css/chronos/timetable.css
"
,)
})
class
Meta
:
proxy
=
True
verbose_name
=
_
(
"
Timetable widget
"
)
This diff is collapsed.
Click to expand it.
aleksis/apps/chronos/models.py
+
60
−
2
View file @
4a199dc9
from
__future__
import
annotations
from
collections
import
OrderedDict
from
datetime
import
date
,
datetime
,
timedelta
,
time
from
typing
import
Dict
,
Optional
,
Tuple
,
Union
...
...
@@ -8,6 +9,7 @@ from django.core.exceptions import ValidationError
from
django.db
import
models
from
django.db.models
import
F
,
Max
,
Min
,
Q
from
django.db.models.functions
import
Coalesce
from
django.forms
import
Media
from
django.http.request
import
QueryDict
from
django.urls
import
reverse
from
django.utils
import
timezone
...
...
@@ -15,11 +17,13 @@ from django.utils.decorators import classproperty
from
django.utils.translation
import
ugettext_lazy
as
_
from
calendarweek.django
import
CalendarWeek
,
i18n_day_names_lazy
,
i18n_day_abbrs_lazy
from
django_global_request.middleware
import
get_request
from
aleksis.core.mixins
import
ExtensibleModel
from
aleksis.core.models
import
Group
,
Person
from
aleksis.core.models
import
Group
,
Person
,
DashboardWidget
from
aleksis.apps.chronos.util.date
import
week_weekday_from_date
from
aleksis.apps.chronos.util.date
import
week_weekday_from_date
,
get_name_for_day_from_today
from
aleksis.core.util.core_helpers
import
has_person
class
LessonPeriodManager
(
models
.
Manager
):
...
...
@@ -505,3 +509,57 @@ class LessonPeriod(ExtensibleModel):
class
Meta
:
ordering
=
[
"
lesson__date_start
"
,
"
period__weekday
"
,
"
period__period
"
]
indexes
=
[
models
.
Index
(
fields
=
[
"
lesson
"
,
"
period
"
])]
class
TimetableWidget
(
DashboardWidget
):
template
=
"
chronos/widget.html
"
def
get_context
(
self
):
request
=
get_request
()
context
=
{
"
has_plan
"
:
True
}
wanted_day
=
TimePeriod
.
get_next_relevant_day
(
timezone
.
now
().
date
(),
datetime
.
now
().
time
())
if
has_person
(
request
.
user
):
person
=
request
.
user
.
person
if
person
.
is_teacher
:
# Teacher
type_
=
"
teacher
"
lesson_periods_person
=
person
.
lesson_periods_as_teacher
elif
person
.
primary_group
:
# Student
type_
=
"
group
"
lesson_periods_person
=
person
.
lesson_periods_as_participant
else
:
# If no student or teacher, redirect to all timetables
context
[
"
has_plan
"
]
=
False
lesson_periods
=
lesson_periods_person
.
on_day
(
wanted_day
)
# Build dictionary with lessons
per_period
=
{}
for
lesson_period
in
lesson_periods
:
if
lesson_period
.
period
.
period
in
per_period
:
per_period
[
lesson_period
.
period
.
period
].
append
(
lesson_period
)
else
:
per_period
[
lesson_period
.
period
.
period
]
=
[
lesson_period
]
context
[
"
lesson_periods
"
]
=
OrderedDict
(
sorted
(
per_period
.
items
()))
context
[
"
type
"
]
=
type_
context
[
"
day
"
]
=
wanted_day
context
[
"
day_label
"
]
=
get_name_for_day_from_today
(
wanted_day
)
context
[
"
periods
"
]
=
TimePeriod
.
get_times_dict
()
context
[
"
smart
"
]
=
True
return
context
media
=
Media
(
css
=
{
"
all
"
:
(
"
css/chronos/timetable.css
"
,)
})
class
Meta
:
proxy
=
True
verbose_name
=
_
(
"
Timetable widget
"
)
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