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
a4bb3da9
Verified
Commit
a4bb3da9
authored
4 years ago
by
Tom Teichler
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of edugit.org:AlekSIS/official/AlekSIS
parents
1fc2c3bc
95bb9aa0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#1956
failed
4 years ago
Stage: test
Stage: build
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/core/mixins.py
+26
-1
26 additions, 1 deletion
aleksis/core/mixins.py
aleksis/core/models.py
+6
-3
6 additions, 3 deletions
aleksis/core/models.py
aleksis/core/preferences.py
+13
-0
13 additions, 0 deletions
aleksis/core/preferences.py
with
45 additions
and
4 deletions
aleksis/core/mixins.py
+
26
−
1
View file @
a4bb3da9
from
datetime
import
datetime
from
typing
import
Any
,
Callable
,
Optional
,
Union
from
typing
import
Any
,
Callable
,
List
,
Optional
,
Tuple
,
Union
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.sites.managers
import
CurrentSiteManager
...
...
@@ -7,6 +7,7 @@ from django.contrib.sites.models import Site
from
django.db
import
models
from
django.db.models
import
QuerySet
from
django.forms.models
import
ModelForm
,
ModelFormMetaclass
from
django.utils.functional
import
lazy
import
reversion
from
easyaudit.models
import
CRUDEvent
...
...
@@ -176,6 +177,30 @@ class ExtensibleModel(models.Model):
cls
.
_safe_add
(
field
,
name
)
@classmethod
def
syncable_fields
(
cls
)
->
List
[
models
.
Field
]:
"""
Collect all fields that can be synced on a model
"""
return
[
field
for
field
in
cls
.
_meta
.
fields
if
(
field
.
editable
and
not
field
.
auto_created
and
not
field
.
is_relation
)
]
@classmethod
def
syncable_fields_choices
(
cls
)
->
Tuple
[
Tuple
[
str
,
str
]]:
"""
Collect all fields that can be synced on a model
"""
return
tuple
(
[(
field
.
name
,
field
.
verbose_name
or
field
.
name
)
for
field
in
cls
.
syncable_fields
()]
)
@classmethod
def
syncable_fields_choices_lazy
(
cls
)
->
Callable
[[],
Tuple
[
Tuple
[
str
,
str
]]]:
"""
Collect all fields that can be synced on a model
"""
return
lazy
(
cls
.
syncable_fields_choices
,
tuple
)
class
Meta
:
abstract
=
True
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/models.py
+
6
−
3
View file @
a4bb3da9
...
...
@@ -192,7 +192,9 @@ class Person(ExtensibleModel):
)
admin
.
save
()
def
auto_select_primary_group
(
self
,
pattern
:
Optional
[
str
]
=
None
,
force
:
bool
=
False
)
->
None
:
def
auto_select_primary_group
(
self
,
pattern
:
Optional
[
str
]
=
None
,
field
:
Optional
[
str
]
=
None
,
force
:
bool
=
False
)
->
None
:
"""
Auto-select the primary group among the groups the person is member of.
Uses either the pattern passed as argument, or the pattern configured system-wide.
...
...
@@ -201,10 +203,11 @@ class Person(ExtensibleModel):
a primary group, unless force is True.
"""
pattern
=
pattern
or
get_site_preferences
()[
"
account__primary_group_pattern
"
]
field
=
field
or
get_site_preferences
()[
"
account__primary_group_field
"
]
if
pattern
:
if
force
or
not
self
.
primary_group
:
self
.
primary_group
=
self
.
member_of
.
filter
(
name
__regex
=
pattern
).
first
()
self
.
primary_group
=
self
.
member_of
.
filter
(
**
{
f
"
{
field
}
__regex
"
:
pattern
}
).
first
()
class
DummyPerson
(
Person
):
...
...
@@ -325,7 +328,7 @@ class PersonGroupThrough(ExtensibleModel):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
for
field
in
self
.
group
.
additional_fields
:
for
field
in
self
.
group
.
additional_fields
.
all
()
:
field_class
=
getattr
(
jsonstore
,
field
.
field_type
)
field_name
=
slugify
(
field
.
title
).
replace
(
"
-
"
,
"
_
"
)
field_instance
=
field_class
(
verbose_name
=
field
.
title
)
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/preferences.py
+
13
−
0
View file @
a4bb3da9
...
...
@@ -5,6 +5,7 @@ from django.utils.translation import gettext_lazy as _
from
dynamic_preferences.preferences
import
Section
from
dynamic_preferences.types
import
ChoicePreference
,
FilePreference
,
StringPreference
from
.models
import
Person
from
.registries
import
person_preferences_registry
,
site_preferences_registry
from
.util.notifications
import
get_notification_choices_lazy
...
...
@@ -149,6 +150,18 @@ class PrimaryGroupPattern(StringPreference):
verbose_name
=
_
(
"
Regular expression to match primary group, e.g.
'
^Class .*
'"
)
@site_preferences_registry.register
class
PrimaryGroupField
(
ChoicePreference
):
section
=
account
name
=
"
primary_group_field
"
default
=
"
name
"
required
=
False
verbose_name
=
_
(
"
Field on person to match primary group against
"
)
def
get_choices
(
self
):
return
Person
.
syncable_fields_choices
()
@site_preferences_registry.register
class
SchoolName
(
StringPreference
):
section
=
school
...
...
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