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
0377e402
Verified
Commit
0377e402
authored
5 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Add ExtensibleModel to allow apps to patch new code into existing models.
parent
b35c00c5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
biscuit/core/mixins.py
+26
-0
26 additions, 0 deletions
biscuit/core/mixins.py
biscuit/core/models.py
+4
-4
4 additions, 4 deletions
biscuit/core/models.py
with
30 additions
and
4 deletions
biscuit/core/mixins.py
+
26
−
0
View file @
0377e402
from
typing
import
Any
,
Callable
,
Optional
from
django.contrib.contenttypes.models
import
ContentType
from
django.db
import
models
from
django.db.models
import
QuerySet
...
...
@@ -7,6 +9,30 @@ from easyaudit.models import CRUDEvent
from
.util.core_helpers
import
get_current_school
class
ExtensibleModel
(
object
):
"""
Mixin that adds class methods for glrofied monkey-patching.
"""
@classmethod
def
property
(
cls
,
func
:
Callable
[[],
Any
],
name
:
Optional
[
str
]
=
None
)
->
None
:
"""
Adds the passed callable as a property.
"""
# Decide the name for the property
if
name
is
None
:
prop_name
=
func
.
__name__
else
:
if
name
.
isidentifier
():
prop_name
=
name
else
:
raise
ValueError
(
'
%s is not a valid name.
'
%
name
)
# Verify that property name does not clash with other names in the class
if
hasattr
(
cls
,
prop_name
):
raise
ValueError
(
'
%s already used.
'
%
prop_name
)
# Add function wrapped in property decorator if we got here
setattr
(
cls
,
prop_name
,
property
(
func
))
class
SchoolRelated
(
models
.
Model
):
class
Meta
:
abstract
=
True
...
...
This diff is collapsed.
Click to expand it.
biscuit/core/models.py
+
4
−
4
View file @
0377e402
...
...
@@ -7,7 +7,7 @@ from django.utils.translation import ugettext_lazy as _
from
image_cropping
import
ImageCropField
,
ImageRatioField
from
phonenumber_field.modelfields
import
PhoneNumberField
from
.mixins
import
SchoolRelated
from
.mixins
import
ExtensibleModel
,
SchoolRelated
class
School
(
models
.
Model
):
...
...
@@ -42,9 +42,9 @@ class SchoolTerm(SchoolRelated):
'
Effective start date of term
'
),
null
=
True
)
date_end
=
models
.
DateField
(
verbose_name
=
_
(
'
Effective end date of term
'
),
null
=
True
)
class
Person
(
SchoolRelated
):
class
Person
(
SchoolRelated
,
ExtensibleModel
):
"""
A model describing any person related to a school, including, but not
limited to, students, teachers and guardians (parents).
"""
...
...
@@ -132,7 +132,7 @@ class Person(SchoolRelated):
return
self
.
full_name
class
Group
(
SchoolRelated
):
class
Group
(
SchoolRelated
,
ExtensibleModel
):
"""
Any kind of group of persons in a school, including, but not limited
classes, clubs, and the like.
"""
...
...
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