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
8d735e52
Verified
Commit
8d735e52
authored
5 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Plain Diff
Merge
parents
4d1a68bb
a724328f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!155
Add way for dashboard widgets to add custom CSS/JS files which will be added in the html head
Pipeline
#870
failed
5 years ago
Stage: test
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitlab-ci.yml
+1
-1
1 addition, 1 deletion
.gitlab-ci.yml
aleksis/core/migrations/0012_announcement.py
+29
-0
29 additions, 0 deletions
aleksis/core/migrations/0012_announcement.py
aleksis/core/models.py
+55
-2
55 additions, 2 deletions
aleksis/core/models.py
with
85 additions
and
3 deletions
.gitlab-ci.yml
+
1
−
1
View file @
8d735e52
image
:
registry.edugit.org/teckids/docker-images/python-pimped:master
image
:
registry.edugit.org/teckids/
team-sysadmin/
docker-images/python-pimped:master
stages
:
-
test
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/migrations/0012_announcement.py
0 → 100644
+
29
−
0
View file @
8d735e52
# Generated by Django 3.0.3 on 2020-02-10 14:22
import
datetime
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
contenttypes
'
,
'
0002_remove_content_type_name
'
),
(
'
core
'
,
'
0011_make_primary_group_optional
'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'
Announcement
'
,
fields
=
[
(
'
id
'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'
ID
'
)),
(
'
title
'
,
models
.
CharField
(
max_length
=
150
,
verbose_name
=
'
Title
'
)),
(
'
description
'
,
models
.
TextField
(
max_length
=
500
,
verbose_name
=
'
Description
'
)),
(
'
link
'
,
models
.
URLField
(
blank
=
True
,
verbose_name
=
'
Link
'
)),
(
'
valid_from
'
,
models
.
DateTimeField
(
default
=
datetime
.
datetime
.
now
,
verbose_name
=
'
Date and time from when to show
'
)),
(
'
valid_until
'
,
models
.
DateTimeField
(
blank
=
True
,
null
=
True
,
verbose_name
=
'
Date and time until when to show
'
)),
(
'
recipient_id
'
,
models
.
PositiveIntegerField
()),
(
'
content_type
'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'
contenttypes.ContentType
'
)),
],
),
]
This diff is collapsed.
Click to expand it.
aleksis/core/models.py
+
55
−
2
View file @
8d735e52
from
datetime
import
date
from
typing
import
Optional
,
Iterable
,
Union
from
datetime
import
date
,
datetime
from
typing
import
Optional
,
Iterable
,
Union
,
Sequence
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth.models
import
User
from
django.contrib.contenttypes.fields
import
GenericForeignKey
from
django.contrib.contenttypes.models
import
ContentType
from
django.db
import
models
from
django.db.models
import
QuerySet
from
django.forms.widgets
import
Media
...
...
@@ -225,6 +227,10 @@ class Group(ExtensibleModel):
blank
=
True
,
)
@property
def
announcement_recipients
(
self
):
return
list
(
self
.
members
)
+
list
(
self
.
owners
)
def
__str__
(
self
)
->
str
:
return
"
%s (%s)
"
%
(
self
.
name
,
self
.
short_name
)
...
...
@@ -273,6 +279,53 @@ class Notification(models.Model):
verbose_name_plural
=
_
(
"
Notifications
"
)
class
Announcement
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
150
,
verbose_name
=
_
(
"
Title
"
))
description
=
models
.
TextField
(
max_length
=
500
,
verbose_name
=
_
(
"
Description
"
))
link
=
models
.
URLField
(
blank
=
True
,
verbose_name
=
_
(
"
Link
"
))
valid_from
=
models
.
DateTimeField
(
verbose_name
=
_
(
"
Date and time from when to show
"
),
default
=
datetime
.
now
)
valid_until
=
models
.
DateTimeField
(
verbose_name
=
_
(
"
Date and time until when to show
"
),
null
=
True
,
blank
=
True
)
content_type
=
models
.
ForeignKey
(
ContentType
,
on_delete
=
models
.
CASCADE
)
recipient_id
=
models
.
PositiveIntegerField
()
recipient
=
GenericForeignKey
(
"
content_type
"
,
"
recipient_id
"
)
@classmethod
def
relevant_for
(
cls
,
obj
:
Union
[
models
.
Model
,
models
.
QuerySet
])
->
models
.
QuerySet
:
"""
Get a QuerySet with all announcements relevant for a certain Model (e.g. a Group)
or a set of models in a QuerySet.
"""
if
isinstance
(
obj
,
models
.
QuerySet
):
ct
=
ContentType
.
objects
.
get_for_model
(
obj
.
model
)
pks
=
list
(
obj
.
values_list
(
'
pk
'
,
flat
=
True
))
else
:
ct
=
ContentType
.
objects
.
get_for_model
(
obj
)
pks
=
[
obj
.
pk
]
return
cls
.
objects
.
filter
(
content_type
=
ct
,
recipient_id__in
=
pks
)
@property
def
recipient_persons
(
self
)
->
Union
[
models
.
QuerySet
,
Sequence
[
models
.
Model
]]:
"""
Return a list of Persons this announcement is relevant for
If the recipient is a Person, return that object. If not, it returns the QUerySet
from the announcement_recipients field on the target model.
"""
if
isinstance
(
self
.
recipient
,
Person
):
return
[
self
.
recipient
]
else
:
return
getattr
(
self
.
recipient
,
"
announcement_recipients
"
,
[])
def
save
(
self
,
**
kwargs
):
if
not
self
.
valid_until
:
self
.
valid_until
=
self
.
valid_from
super
().
save
(
**
kwargs
)
class
DashboardWidget
(
PolymorphicModel
):
"""
Base class for dashboard widgets on the index page
...
...
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