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
1134f719
Commit
1134f719
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Fix bugs with wrong methods and missing unique constraints
parent
f592ebdf
No related branches found
No related tags found
1 merge request
!1
Resolve "Optimise query count"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
favicon/migrations/0004_faviconimg_favicon_size_rel_unique.py
+17
-0
17 additions, 0 deletions
...con/migrations/0004_faviconimg_favicon_size_rel_unique.py
favicon/models.py
+6
-5
6 additions, 5 deletions
favicon/models.py
favicon/templatetags/favtags.py
+1
-2
1 addition, 2 deletions
favicon/templatetags/favtags.py
with
24 additions
and
7 deletions
favicon/migrations/0004_faviconimg_favicon_size_rel_unique.py
0 → 100644
+
17
−
0
View file @
1134f719
# Generated by Django 3.2 on 2021-05-15 20:28
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'
favicon
'
,
'
0003_site_manager
'
),
]
operations
=
[
migrations
.
AddConstraint
(
model_name
=
'
faviconimg
'
,
constraint
=
models
.
UniqueConstraint
(
fields
=
(
'
faviconFK
'
,
'
size
'
,
'
rel
'
),
name
=
'
favicon_size_rel_unique
'
),
),
]
This diff is collapsed.
Click to expand it.
favicon/models.py
+
6
−
5
View file @
1134f719
...
@@ -81,7 +81,7 @@ class Favicon(models.Model):
...
@@ -81,7 +81,7 @@ class Favicon(models.Model):
# Delete all favicon images to update all
# Delete all favicon images to update all
if
update
:
if
update
:
favicons
.
delete
()
favicons
.
delete
()
favicons
=
FaviconImg
.
objects
.
empty
()
favicons
=
FaviconImg
.
objects
.
none
()
found
=
[]
found
=
[]
else
:
else
:
favicons
=
favicons
.
all
()
favicons
=
favicons
.
all
()
...
@@ -96,7 +96,7 @@ class Favicon(models.Model):
...
@@ -96,7 +96,7 @@ class Favicon(models.Model):
fav
.
generate_image
()
fav
.
generate_image
()
new_favicons
.
append
(
fav
)
new_favicons
.
append
(
fav
)
if
new_favicons
:
if
new_favicons
:
FaviconImg
.
objects
.
bulk_create
(
new_favicons
)
FaviconImg
.
objects
.
bulk_create
(
new_favicons
,
ignore_conflicts
=
True
)
return
list
(
favicons
)
+
new_favicons
return
list
(
favicons
)
+
new_favicons
...
@@ -117,8 +117,6 @@ class Favicon(models.Model):
...
@@ -117,8 +117,6 @@ class Favicon(models.Model):
return
html
return
html
def
save
(
self
,
*
args
,
**
kwargs
):
def
save
(
self
,
*
args
,
**
kwargs
):
update
=
False
if
self
.
isFavicon
:
if
self
.
isFavicon
:
Favicon
.
on_site
.
exclude
(
pk
=
self
.
pk
).
update
(
isFavicon
=
False
)
Favicon
.
on_site
.
exclude
(
pk
=
self
.
pk
).
update
(
isFavicon
=
False
)
...
@@ -127,7 +125,7 @@ class Favicon(models.Model):
...
@@ -127,7 +125,7 @@ class Favicon(models.Model):
cache
.
delete
(
config_cache_key
)
cache
.
delete
(
config_cache_key
)
if
self
.
faviconImage
:
if
self
.
faviconImage
:
html
=
self
.
get_favicons
(
update
=
updat
e
)
html
=
self
.
as_html
(
update
=
Tru
e
)
cache
.
set
(
config_cache_key
,
html
,
timeout
=
None
)
cache
.
set
(
config_cache_key
,
html
,
timeout
=
None
)
...
@@ -154,6 +152,9 @@ class FaviconImg(models.Model):
...
@@ -154,6 +152,9 @@ class FaviconImg(models.Model):
def
del_image
(
self
):
def
del_image
(
self
):
self
.
faviconImage
.
delete
()
self
.
faviconImage
.
delete
()
class
Meta
:
constraints
=
[
models
.
UniqueConstraint
(
fields
=
[
"
faviconFK
"
,
"
size
"
,
"
rel
"
],
name
=
"
favicon_size_rel_unique
"
)]
signals
.
pre_delete
.
connect
(
pre_delete_image
,
sender
=
Favicon
)
signals
.
pre_delete
.
connect
(
pre_delete_image
,
sender
=
Favicon
)
signals
.
pre_delete
.
connect
(
pre_delete_image
,
sender
=
FaviconImg
)
signals
.
pre_delete
.
connect
(
pre_delete_image
,
sender
=
FaviconImg
)
This diff is collapsed.
Click to expand it.
favicon/templatetags/favtags.py
+
1
−
2
View file @
1134f719
...
@@ -20,12 +20,11 @@ def place_favicon(context):
...
@@ -20,12 +20,11 @@ def place_favicon(context):
html
=
cache
.
get
(
config_cache_key
)
html
=
cache
.
get
(
config_cache_key
)
if
html
:
if
html
:
return
html
return
mark_safe
(
html
)
fav
=
Favicon
.
on_site
.
filter
(
isFavicon
=
True
).
first
()
fav
=
Favicon
.
on_site
.
filter
(
isFavicon
=
True
).
first
()
if
not
fav
:
if
not
fav
:
return
mark_safe
(
'
<!-- no favicon -->
'
)
return
mark_safe
(
'
<!-- no favicon -->
'
)
html
=
fav
.
as_html
()
html
=
fav
.
as_html
()
cache
.
set
(
config_cache_key
,
html
,
timeout
=
None
)
cache
.
set
(
config_cache_key
,
html
,
timeout
=
None
)
...
...
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