Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
django-iconify
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
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-iconify
Commits
dfc3b4e3
Verified
Commit
dfc3b4e3
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Implement allow/disallow list for collection names
Advances
#6
parent
e297b238
No related branches found
No related tags found
1 merge request
!6
Resolve "Export django model choices for icons"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dj_iconify/conf.py
+3
-0
3 additions, 0 deletions
dj_iconify/conf.py
dj_iconify/util.py
+14
-0
14 additions, 0 deletions
dj_iconify/util.py
dj_iconify/views.py
+13
-0
13 additions, 0 deletions
dj_iconify/views.py
with
30 additions
and
0 deletions
dj_iconify/conf.py
+
3
−
0
View file @
dfc3b4e3
...
@@ -4,3 +4,6 @@ from django.conf import settings
...
@@ -4,3 +4,6 @@ from django.conf import settings
_prefix
=
"
ICONIFY_
"
_prefix
=
"
ICONIFY_
"
JSON_ROOT
=
getattr
(
settings
,
f
"
{
_prefix
}
JSON_ROOT
"
)
JSON_ROOT
=
getattr
(
settings
,
f
"
{
_prefix
}
JSON_ROOT
"
)
COLLECTIONS_ALLOWED
=
getattr
(
settings
,
f
"
{
_prefix
}
COLLECTIONS_ALLOWED
"
,
[])
COLLECTIONS_DISALLOWED
=
getattr
(
settings
,
f
"
{
_prefix
}
COLLECTIONS_DISALLOWED
"
,
[])
This diff is collapsed.
Click to expand it.
dj_iconify/util.py
+
14
−
0
View file @
dfc3b4e3
"""
Utility code used by other parts of django-iconify.
"""
"""
Utility code used by other parts of django-iconify.
"""
import
re
import
re
from
.conf
import
COLLECTIONS_ALLOWED
,
COLLECTIONS_DISALLOWED
def
split_css_unit
(
string
:
str
):
def
split_css_unit
(
string
:
str
):
"""
Split string into value and unit.
"""
Split string into value and unit.
...
@@ -19,3 +21,15 @@ def split_css_unit(string: str):
...
@@ -19,3 +21,15 @@ def split_css_unit(string: str):
unit
=
string
[
len
(
_value
[
0
])
:]
unit
=
string
[
len
(
_value
[
0
])
:]
return
value
,
unit
return
value
,
unit
def
collection_allowed
(
collection
:
str
)
->
bool
:
"""
Determine whether a collection is allowed by settings.
"""
if
collection
in
COLLECTIONS_DISALLOWED
:
return
False
if
COLLECTIONS_ALLOWED
and
collection
not
in
COLLECTIONS_DISALLOWED
:
return
False
return
True
This diff is collapsed.
Click to expand it.
dj_iconify/views.py
+
13
−
0
View file @
dfc3b4e3
...
@@ -12,6 +12,7 @@ from django.views.generic import View
...
@@ -12,6 +12,7 @@ from django.views.generic import View
from
.conf
import
JSON_ROOT
from
.conf
import
JSON_ROOT
from
.types
import
IconifyJSON
from
.types
import
IconifyJSON
from
.util
import
collection_allowed
class
BaseJSONView
(
View
):
class
BaseJSONView
(
View
):
...
@@ -89,6 +90,10 @@ class CollectionView(BaseJSONView):
...
@@ -89,6 +90,10 @@ class CollectionView(BaseJSONView):
if
collection
is
None
or
not
re
.
match
(
r
"
[A-Za-z0-9-]+
"
,
collection
):
if
collection
is
None
or
not
re
.
match
(
r
"
[A-Za-z0-9-]+
"
,
collection
):
return
HttpResponseBadRequest
(
"
You must provide a valid prefix name.
"
)
return
HttpResponseBadRequest
(
"
You must provide a valid prefix name.
"
)
# Check whether this collection is allowed
if
not
collection_allowed
(
collection
):
raise
Http404
(
f
"
Collection
{
collection
}
not allowed
"
)
# Load icon set through Iconify types
# Load icon set through Iconify types
collection_file
=
os
.
path
.
join
(
JSON_ROOT
,
"
json
"
,
f
"
{
collection
}
.json
"
)
collection_file
=
os
.
path
.
join
(
JSON_ROOT
,
"
json
"
,
f
"
{
collection
}
.json
"
)
try
:
try
:
...
@@ -123,6 +128,10 @@ class IconifyJSONView(BaseJSONView):
...
@@ -123,6 +128,10 @@ class IconifyJSONView(BaseJSONView):
if
icons
is
not
None
:
if
icons
is
not
None
:
icons
=
icons
.
split
(
"
,
"
)
icons
=
icons
.
split
(
"
,
"
)
# Check whether this collection is allowed
if
not
collection_allowed
(
collection
):
raise
Http404
(
f
"
Collection
{
collection
}
not allowed
"
)
# Load icon set through Iconify types
# Load icon set through Iconify types
collection_file
=
os
.
path
.
join
(
JSON_ROOT
,
"
json
"
,
f
"
{
collection
}
.json
"
)
collection_file
=
os
.
path
.
join
(
JSON_ROOT
,
"
json
"
,
f
"
{
collection
}
.json
"
)
try
:
try
:
...
@@ -151,6 +160,10 @@ class IconifySVGView(View):
...
@@ -151,6 +160,10 @@ class IconifySVGView(View):
rotate
=
request
.
GET
.
get
(
"
rotate
"
,
None
)
rotate
=
request
.
GET
.
get
(
"
rotate
"
,
None
)
flip
=
request
.
GET
.
get
(
"
flip
"
,
None
)
flip
=
request
.
GET
.
get
(
"
flip
"
,
None
)
# Check whether this collection is allowed
if
not
collection_allowed
(
collection
):
raise
Http404
(
f
"
Collection
{
collection
}
not allowed
"
)
# Load icon set through Iconify types
# Load icon set through Iconify types
collection_file
=
os
.
path
.
join
(
JSON_ROOT
,
"
json
"
,
f
"
{
collection
}
.json
"
)
collection_file
=
os
.
path
.
join
(
JSON_ROOT
,
"
json
"
,
f
"
{
collection
}
.json
"
)
try
:
try
:
...
...
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