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
e96f8a23
Unverified
Commit
e96f8a23
authored
5 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Add type hints. Advances BiscuIT-ng#20.
parent
5e8efdcb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
biscuit/apps/chronos/models.py
+14
-9
14 additions, 9 deletions
biscuit/apps/chronos/models.py
biscuit/apps/chronos/util.py
+5
-2
5 additions, 2 deletions
biscuit/apps/chronos/util.py
biscuit/apps/chronos/views.py
+2
-1
2 additions, 1 deletion
biscuit/apps/chronos/views.py
with
21 additions
and
12 deletions
biscuit/apps/chronos/models.py
+
14
−
9
View file @
e96f8a23
from
datetime
import
datetime
from
typing
import
List
,
Tuple
,
Optional
from
django.core
import
validators
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
.util
import
current_week
from
biscuit.core.models
import
Person
class
TimePeriod
(
models
.
Model
):
WEEKDAY_CHOICES
=
[
...
...
@@ -24,11 +29,11 @@ class TimePeriod(models.Model):
time_start
=
models
.
TimeField
(
verbose_name
=
_
(
'
Time the period starts
'
))
time_end
=
models
.
TimeField
(
verbose_name
=
_
(
'
Time the period ends
'
))
def
__str__
(
self
):
def
__str__
(
self
):
str
:
return
'
%s, %d. period (%s - %s)
'
%
(
self
.
weekday
,
self
.
period
,
self
.
time_start
,
self
.
time_end
)
@classmethod
def
get_times_dict
(
cls
):
def
get_times_dict
(
cls
)
->
Dict
[
int
,
Tuple
[
datetime
,
datetime
]]
:
periods
=
{}
for
period
in
cls
.
objects
.
all
():
periods
[
period
.
period
]
=
(
period
.
time_start
,
period
.
time_end
)
...
...
@@ -50,7 +55,7 @@ class Subject(models.Model):
colour_bg
=
models
.
CharField
(
verbose_name
=
_
(
'
Background colour in timetable
'
),
blank
=
True
,
validators
=
[
validators
.
RegexValidator
(
r
'
#[0-9A-F]{6}
'
)],
max_length
=
7
)
def
__str__
(
self
):
def
__str__
(
self
)
->
str
:
return
'
%s - %s
'
%
(
self
.
abbrev
,
self
.
name
)
...
...
@@ -60,7 +65,7 @@ class Room(models.Model):
name
=
models
.
CharField
(
verbose_name
=
_
(
'
Long name
'
),
max_length
=
30
,
unique
=
True
)
def
__str__
(
self
):
def
__str__
(
self
)
->
str
:
return
'
%s (%s)
'
%
(
self
.
name
,
self
.
short_name
)
...
...
@@ -84,29 +89,29 @@ class LessonPeriod(models.Model):
room
=
models
.
ForeignKey
(
'
Room
'
,
models
.
CASCADE
,
null
=
True
)
def
get_substitution
(
self
,
week
=
None
)
:
def
get_substitution
(
self
,
week
:
Optional
[
int
]
=
None
)
->
LessonSubstitution
:
wanted_week
=
week
or
current_week
()
return
self
.
substitutions
.
filter
(
week
=
wanted_week
).
first
()
def
get_subject
(
self
):
def
get_subject
(
self
)
->
Optional
[
Subject
]
:
if
self
.
get_substitution
():
return
self
.
get_substitution
().
subject
else
:
return
self
.
lesson
.
subject
def
get_teachers
(
self
):
def
get_teachers
(
self
)
->
models
.
query
.
QuerySet
:
if
self
.
get_substitution
():
return
self
.
get_substitution
().
teachers
else
:
return
self
.
lesson
.
teachers
def
get_room
(
self
):
def
get_room
(
self
)
->
Optional
[
Room
]
:
if
self
.
get_substitution
():
return
self
.
get_substitution
().
room
else
:
return
self
.
room
def
get_groups
(
self
):
def
get_groups
(
self
)
->
models
.
query
.
QuerySet
:
return
self
.
lesson
.
groups
...
...
This diff is collapsed.
Click to expand it.
biscuit/apps/chronos/util.py
+
5
−
2
View file @
e96f8a23
from
datetime
import
datetime
from
typing
import
Optional
from
django.db
import
models
from
.models
import
LessonPeriod
def
current_week
():
def
current_week
()
->
int
:
return
int
(
datetime
.
now
().
strftime
(
'
%V
'
))
def
current_lesson_periods
(
when
=
None
)
:
def
current_lesson_periods
(
when
:
Optional
[
datetime
]
=
None
)
->
models
.
query
.
QuerySet
:
now
=
when
or
datetime
.
now
()
return
LessonPeriod
.
objects
.
filter
(
lesson__date_start__lte
=
now
.
date
(),
...
...
This diff is collapsed.
Click to expand it.
biscuit/apps/chronos/views.py
+
2
−
1
View file @
e96f8a23
from
collections
import
OrderedDict
from
django.contrib.auth.decorators
import
login_required
from
django.http
import
HttpRequest
,
HttpResponse
from
django.shortcuts
import
redirect
,
render
from
django.urls
import
reverse
from
django.utils.translation
import
gettext_lazy
as
_
...
...
@@ -14,7 +15,7 @@ from .util import current_week
@login_required
@admin_required
def
timetable
(
request
)
:
def
timetable
(
request
:
HttpRequest
)
->
HttpResponse
:
context
=
{}
lesson_periods
=
LessonPeriod
.
objects
.
all
()
...
...
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