Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Kolego
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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-Kolego
Commits
46bcbee0
Commit
46bcbee0
authored
1 year ago
by
Jonathan Weth
Committed by
magicfelix
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add more attributes to models
parent
d12b6b13
No related branches found
No related tags found
1 merge request
!7
Resolve "Implement Absence model based on FreeBusy"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/apps/kolego/migrations/0003_refactor_absence.py
+61
-0
61 additions, 0 deletions
aleksis/apps/kolego/migrations/0003_refactor_absence.py
aleksis/apps/kolego/models/absence.py
+39
-3
39 additions, 3 deletions
aleksis/apps/kolego/models/absence.py
pyproject.toml
+1
-1
1 addition, 1 deletion
pyproject.toml
with
101 additions
and
4 deletions
aleksis/apps/kolego/migrations/0003_refactor_absence.py
0 → 100644
+
61
−
0
View file @
46bcbee0
# Generated by Django 4.2.9 on 2024-01-11 20:37
import
colorfield.fields
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
"
kolego
"
,
"
0002_drop_site
"
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
"
absencereason
"
,
name
=
"
colour
"
,
field
=
colorfield
.
fields
.
ColorField
(
blank
=
True
,
default
=
""
,
image_field
=
None
,
max_length
=
25
,
samples
=
None
,
verbose_name
=
"
Colour
"
,
),
),
migrations
.
AddField
(
model_name
=
"
absencereason
"
,
name
=
"
count_as_absent
"
,
field
=
models
.
BooleanField
(
default
=
True
,
help_text
=
"
If checked, this excuse type will be counted as absent. If not checked,it won
'
t show up in absence reports.
"
,
verbose_name
=
"
Count as absent
"
,
),
),
migrations
.
AddField
(
model_name
=
"
absencereason
"
,
name
=
"
default
"
,
field
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
"
Default Reason
"
),
),
migrations
.
AlterField
(
model_name
=
"
absence
"
,
name
=
"
reason
"
,
field
=
models
.
ForeignKey
(
default
=
1
,
on_delete
=
django
.
db
.
models
.
deletion
.
PROTECT
,
related_name
=
"
absences
"
,
to
=
"
kolego.absencereason
"
,
verbose_name
=
"
Absence reason
"
,
),
preserve_default
=
False
,
),
migrations
.
AddConstraint
(
model_name
=
"
absencereason
"
,
constraint
=
models
.
UniqueConstraint
(
condition
=
models
.
Q
((
"
default
"
,
True
)),
fields
=
(
"
default
"
,),
name
=
"
only_one_default_absence_reason
"
,
),
),
]
This diff is collapsed.
Click to expand it.
aleksis/apps/kolego/models/absence.py
+
39
−
3
View file @
46bcbee0
from
django.db
import
models
from
django.utils.translation
import
gettext_lazy
as
_
from
colorfield.fields
import
ColorField
from
aleksis.core.managers
import
PolymorphicBaseManager
from
aleksis.core.mixins
import
ExtensibleModel
from
aleksis.core.models
import
FreeBusy
...
...
@@ -12,15 +14,51 @@ class AbsenceReason(ExtensibleModel):
short_name
=
models
.
CharField
(
verbose_name
=
_
(
"
Short name
"
),
max_length
=
255
,
unique
=
True
)
name
=
models
.
CharField
(
verbose_name
=
_
(
"
Name
"
),
max_length
=
255
)
colour
=
ColorField
(
verbose_name
=
_
(
"
Colour
"
),
blank
=
True
)
count_as_absent
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
_
(
"
Count as absent
"
),
help_text
=
_
(
"
If checked, this excuse type will be counted as absent. If not checked,
"
"
it won
'
t show up in absence reports.
"
),
)
default
=
models
.
BooleanField
(
verbose_name
=
_
(
"
Default Reason
"
),
default
=
False
)
def
__str__
(
self
):
if
self
.
name
:
return
f
"
{
self
.
short_name
}
(
{
self
.
name
}
)
"
else
:
return
self
.
short_name
def
save
(
self
,
*
args
,
**
kwargs
):
# Ensure that there is only one default absence reason
if
self
.
default
:
reasons
=
AbsenceReason
.
objects
.
filter
(
default
=
True
)
if
self
.
pk
:
reasons
.
exclude
(
pk
=
self
.
pk
)
reasons
.
update
(
default
=
False
)
super
().
save
(
*
args
,
**
kwargs
)
@classmethod
def
get_default
(
cls
)
->
"
AbsenceReason
"
:
try
:
return
cls
.
objects
.
get
(
default
=
True
)
except
cls
.
ObjectDoesNotExist
:
return
cls
.
objects
.
create
(
default
=
True
,
short_name
=
"
u
"
,
name
=
_
(
"
Unexcused
"
))
class
Meta
:
verbose_name
=
_
(
"
Absence reason
"
)
verbose_name_plural
=
_
(
"
Absence reasons
"
)
constraints
=
[
models
.
UniqueConstraint
(
fields
=
[
"
default
"
],
condition
=
models
.
Q
(
default
=
True
),
name
=
"
only_one_default_absence_reason
"
,
)
]
class
Absence
(
FreeBusy
):
...
...
@@ -28,10 +66,8 @@ class Absence(FreeBusy):
reason
=
models
.
ForeignKey
(
"
AbsenceReason
"
,
on_delete
=
models
.
SET_NULL
,
on_delete
=
models
.
PROTECT
,
related_name
=
"
absences
"
,
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
"
Absence reason
"
),
)
...
...
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
1
View file @
46bcbee0
...
...
@@ -34,7 +34,7 @@ url = "https://edugit.org/api/v4/projects/461/packages/pypi/simple"
priority
=
"supplemental"
[tool.poetry.dependencies]
python
=
"^3.10"
aleksis-core
=
"^4.0.0.dev
0
"
aleksis-core
=
"^4.0.0.dev
2
"
[tool.poetry.plugins."aleksis.app"]
kolego
=
"aleksis.apps.kolego.apps:DefaultConfig"
...
...
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