Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Django Favicon Plus Reloaded
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository 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®
Libraries
Django Favicon Plus Reloaded
Commits
939d0de2
Verified
Commit
939d0de2
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Cache generated HTML
parent
d3321f06
No related branches found
No related tags found
1 merge request
!1
Resolve "Optimise query count"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
favicon/models.py
+7
-0
7 additions, 0 deletions
favicon/models.py
favicon/templatetags/favtags.py
+8
-1
8 additions, 1 deletion
favicon/templatetags/favtags.py
with
15 additions
and
1 deletion
favicon/models.py
+
7
−
0
View file @
939d0de2
from
io
import
BytesIO
import
hashlib
import
json
import
sys
from
PIL
import
Image
from
django.conf
import
settings
from
django.core.cache
import
cache
from
django.core.files.storage
import
default_storage
as
storage
from
django.core.files.uploadedfile
import
InMemoryUploadedFile
from
django.db
import
models
...
...
@@ -26,6 +29,8 @@ config = getattr(settings, 'FAVICON_CONFIG', config)
if
"
shortcut icon
"
not
in
config
or
32
not
in
config
[
"
shortcut icon
"
]:
config
.
setdefault
(
"
shortcut_icon
"
,
[]).
append
(
32
)
config_cache_key
=
"
favicons_
"
+
hashlib
.
sha1
(
json
.
dumps
(
config
,
sort_keys
=
True
).
encode
()).
hexdigest
()
image_path
=
getattr
(
settings
,
"
FAVICON_PATH
"
,
"
favicon
"
)
...
...
@@ -112,6 +117,8 @@ class Favicon(models.Model):
if
self
.
faviconImage
:
self
.
get_favicons
(
update
=
update
)
cache
.
delete
(
config_cache_key
)
class
FaviconImg
(
models
.
Model
):
faviconFK
=
models
.
ForeignKey
(
Favicon
,
on_delete
=
models
.
CASCADE
)
...
...
This diff is collapsed.
Click to expand it.
favicon/templatetags/favtags.py
+
8
−
1
View file @
939d0de2
from
django
import
template
from
django.core.cache
import
cache
from
django.utils.safestring
import
mark_safe
from
favicon.models
import
Favicon
,
config
from
favicon.models
import
Favicon
,
config
_cache_key
register
=
template
.
Library
()
...
...
@@ -16,6 +17,11 @@ def place_favicon(context):
{% place_favicon %}
"""
html
=
cache
.
get
(
config_cache_key
)
if
html
:
return
html
fav
=
Favicon
.
on_site
.
filter
(
isFavicon
=
True
).
first
()
if
not
fav
:
return
mark_safe
(
'
<!-- no favicon -->
'
)
...
...
@@ -23,4 +29,5 @@ def place_favicon(context):
for
n
in
fav
.
get_favicons
():
html
+=
f
'
<link rel=
"
{
n
.
rel
}
"
sizes=
"
{
n
.
size
}
x
{
n
.
size
}
"
href=
"
{
n
.
faviconImage
.
url
}
"
/>
'
cache
.
set
(
config_cache_key
,
html
,
timeout
=
None
)
return
mark_safe
(
html
)
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