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
4d1a68bb
Verified
Commit
4d1a68bb
authored
5 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add way for dashboard widgets to add custom CSS/JS files which will be added in the html head
parent
cc459120
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
#869
failed
5 years ago
Stage: test
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/core/models.py
+25
-2
25 additions, 2 deletions
aleksis/core/models.py
aleksis/core/templates/core/index.html
+4
-0
4 additions, 0 deletions
aleksis/core/templates/core/index.html
aleksis/core/views.py
+5
-1
5 additions, 1 deletion
aleksis/core/views.py
with
34 additions
and
3 deletions
aleksis/core/models.py
+
25
−
2
View file @
4d1a68bb
from
datetime
import
date
from
typing
import
Optional
from
typing
import
Optional
,
Iterable
,
Union
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth.models
import
User
from
django.db
import
models
from
django.db.models
import
QuerySet
from
django.forms.widgets
import
Media
from
django.utils.translation
import
ugettext_lazy
as
_
from
image_cropping
import
ImageCropField
,
ImageRatioField
from
phonenumber_field.modelfields
import
PhoneNumberField
...
...
@@ -280,8 +282,13 @@ class DashboardWidget(PolymorphicModel):
If your widget does not add any database fields, you should mark it as a proxy model.
You can provide a Media meta class with custom JS and CSS files which will be added to html head.
For further information on media definition see https://docs.djangoproject.com/en/3.0/topics/forms/media/
Example::
from django.forms.widgets import Media
from aleksis.core.models import DashboardWidget
class MyWidget(DhasboardWIdget):
...
...
@@ -293,9 +300,25 @@ class DashboardWidget(PolymorphicModel):
class Meta:
proxy = True
media = Media(css={
'
all
'
: (
'
pretty.css
'
,)
},
js=(
'
animations.js
'
,
'
actions.js
'
)
)
"""
@staticmethod
def
get_media
(
widgets
:
Union
[
QuerySet
,
Iterable
]):
"""
Return all media required to render the selected widgets.
"""
media
=
Media
()
for
widget
in
widgets
:
media
=
media
+
widget
.
media
return
media
template
=
None
media
=
Media
()
title
=
models
.
CharField
(
max_length
=
150
,
verbose_name
=
_
(
"
Widget Title
"
))
active
=
models
.
BooleanField
(
blank
=
True
,
verbose_name
=
_
(
"
Activate Widget
"
))
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/templates/core/index.html
+
4
−
0
View file @
4d1a68bb
...
...
@@ -3,6 +3,10 @@
{% block browser_title %}{% blocktrans %}Home{% endblocktrans %}{% endblock %}
{% block extra_head %}
{{ media }}
{% endblock %}
{% block content %}
<p
class=
"flow-text"
>
{% blocktrans %}AlekSIS (School Information System){% endblocktrans %}
</p>
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/views.py
+
5
−
1
View file @
4d1a68bb
...
...
@@ -33,7 +33,11 @@ def index(request: HttpRequest) -> HttpResponse:
context
[
"
notifications
"
]
=
notifications
context
[
"
unread_notifications
"
]
=
unread_notifications
context
[
"
widgets
"
]
=
DashboardWidget
.
objects
.
filter
(
active
=
True
)
widgets
=
DashboardWidget
.
objects
.
filter
(
active
=
True
)
media
=
DashboardWidget
.
get_media
(
widgets
)
context
[
"
widgets
"
]
=
widgets
context
[
"
media
"
]
=
media
return
render
(
request
,
"
core/index.html
"
,
context
)
...
...
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