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
e6b4ce1f
Verified
Commit
e6b4ce1f
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Pre-generate HTML on save
parent
939d0de2
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
+15
-3
15 additions, 3 deletions
favicon/models.py
favicon/templatetags/favtags.py
+2
-3
2 additions, 3 deletions
favicon/templatetags/favtags.py
with
17 additions
and
6 deletions
favicon/models.py
+
15
−
3
View file @
e6b4ce1f
...
...
@@ -106,6 +106,13 @@ class Favicon(models.Model):
def
del_image
(
self
):
self
.
faviconImage
.
delete
()
def
as_html
(
self
,
update
=
False
):
"""
Return <link> html tags for this favicon set.
"""
html
=
''
for
favicon
in
self
.
get_favicons
(
update
=
update
):
html
+=
favicon
.
as_html
()
return
html
def
save
(
self
,
*
args
,
**
kwargs
):
update
=
False
...
...
@@ -114,11 +121,12 @@ class Favicon(models.Model):
super
(
Favicon
,
self
).
save
(
*
args
,
**
kwargs
)
if
self
.
faviconImage
:
self
.
get_favicons
(
update
=
update
)
cache
.
delete
(
config_cache_key
)
if
self
.
faviconImage
:
html
=
self
.
get_favicons
(
update
=
update
)
cache
.
set
(
config_cache_key
,
html
,
timeout
=
None
)
class
FaviconImg
(
models
.
Model
):
faviconFK
=
models
.
ForeignKey
(
Favicon
,
on_delete
=
models
.
CASCADE
)
...
...
@@ -126,6 +134,10 @@ class FaviconImg(models.Model):
rel
=
models
.
CharField
(
max_length
=
250
,
null
=
True
)
faviconImage
=
models
.
ImageField
(
upload_to
=
image_path
)
def
as_html
(
self
):
"""
Return a <link> tag forthis favicon image.
"""
return
f
'
<link rel=
"
{
self
.
rel
}
"
sizes=
"
{
self
.
size
}
x
{
self
.
size
}
"
href=
"
{
self
.
faviconImage
.
url
}
"
/>
'
def
generate_image
(
self
):
tmp
=
Image
.
open
(
storage
.
open
(
self
.
faviconFK
.
faviconImage
.
name
))
tmp
.
thumbnail
((
self
.
size
,
self
.
size
),
Image
.
ANTIALIAS
)
...
...
This diff is collapsed.
Click to expand it.
favicon/templatetags/favtags.py
+
2
−
3
View file @
e6b4ce1f
...
...
@@ -25,9 +25,8 @@ def place_favicon(context):
fav
=
Favicon
.
on_site
.
filter
(
isFavicon
=
True
).
first
()
if
not
fav
:
return
mark_safe
(
'
<!-- no favicon -->
'
)
html
=
''
for
n
in
fav
.
get_favicons
():
html
+=
f
'
<link rel=
"
{
n
.
rel
}
"
sizes=
"
{
n
.
size
}
x
{
n
.
size
}
"
href=
"
{
n
.
faviconImage
.
url
}
"
/>
'
html
=
fav
.
as_html
()
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