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
b9b5e277
Verified
Commit
b9b5e277
authored
5 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Add @Foo.method to add something as a method to a model.
parent
8eb9c2c9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
biscuit/core/mixins.py
+14
-4
14 additions, 4 deletions
biscuit/core/mixins.py
with
14 additions
and
4 deletions
biscuit/core/mixins.py
+
14
−
4
View file @
b9b5e277
...
...
@@ -13,9 +13,7 @@ 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.
"""
def
_safe_add
(
cls
,
obj
:
Any
,
name
:
Optional
[
str
])
->
None
:
# Decide the name for the property
if
name
is
None
:
prop_name
=
func
.
__name__
...
...
@@ -30,7 +28,19 @@ class ExtensibleModel(object):
raise
ValueError
(
'
%s already used.
'
%
prop_name
)
# Add function wrapped in property decorator if we got here
setattr
(
cls
,
prop_name
,
property
(
func
))
setattr
(
cls
,
prop_name
,
obj
)
@classmethod
def
property
(
cls
,
func
:
Callable
[[],
Any
],
name
:
Optional
[
str
]
=
None
)
->
None
:
"""
Adds the passed callable as a property.
"""
cls
.
_safe_add
(
property
(
func
),
name
)
@classmethod
def
method
(
cls
,
func
:
Callable
[[],
Any
],
name
:
Optional
[
str
]
=
None
)
->
None
:
"""
Adds the passed callable as a property.
"""
cls
.
_safe_add
(
func
,
name
)
class
SchoolRelated
(
models
.
Model
):
...
...
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