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
Compare revisions
a3b2c949aff0606a6449e3ab439be1afa980deda to c942479dd59fed7883396c38e8f9e70de9e8c1a5
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
AlekSIS/libs/django-iconify
Select target project
No results found
c942479dd59fed7883396c38e8f9e70de9e8c1a5
Select Git revision
Branches
1-add-management-command-to-retrieve-collections-json
master
Tags
0.1.0
0.1.0.post1
0.1.1
0.3
0.4
0.4.1
8 results
Swap
Target
AlekSIS/libs/django-iconify
Select target project
AlekSIS/libs/django-iconify
1 result
a3b2c949aff0606a6449e3ab439be1afa980deda
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (4)
Implement reading IconifyJSON from file
· d0cc4d4c
Nik | Klampfradler
authored
4 years ago
d0cc4d4c
Fix bugs in as_dict and add as_json
· f9a19ed3
Nik | Klampfradler
authored
4 years ago
f9a19ed3
Remove as_json API on type
· 00d3c94e
Nik | Klampfradler
authored
4 years ago
00d3c94e
Implement JSON view
· c942479d
Nik | Klampfradler
authored
4 years ago
c942479d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
dj_iconify/conf.py
+5
-0
5 additions, 0 deletions
dj_iconify/conf.py
dj_iconify/types.py
+29
-10
29 additions, 10 deletions
dj_iconify/types.py
dj_iconify/urls.py
+1
-1
1 addition, 1 deletion
dj_iconify/urls.py
dj_iconify/views.py
+41
-5
41 additions, 5 deletions
dj_iconify/views.py
with
76 additions
and
16 deletions
dj_iconify/conf.py
0 → 100644
View file @
c942479d
from
django.conf
import
settings
_prefix
=
"
ICONIFY_
"
JSON_ROOT
=
getattr
(
settings
,
f
"
{
_prefix
}
JSON_ROOT
"
)
This diff is collapsed.
Click to expand it.
dj_iconify/types.py
View file @
c942479d
...
...
@@ -2,7 +2,10 @@
Documentation: https://docs.iconify.design/types/
"""
from
typing
import
Collection
,
Dict
,
Optional
from
typing
import
Collection
,
Dict
,
Optional
,
Union
from
typing.io
import
TextIO
import
json
class
IconifyOptional
:
left
:
int
=
0
...
...
@@ -14,7 +17,7 @@ class IconifyOptional:
h_flip
:
bool
=
False
v_flip
:
bool
=
False
def
_as_dict_opt
o
inal
(
self
)
->
dict
:
def
_as_dict_opti
o
nal
(
self
)
->
dict
:
return
{
"
left
"
:
self
.
left
,
"
top
"
:
self
.
top
,
...
...
@@ -46,9 +49,11 @@ class IconifyIcon(IconifyOptional):
return
self
def
as_dict
(
self
)
->
dict
:
re
turn
{
re
s
=
{
"
body
"
:
self
.
body
,
}.
update
(
self
.
_as_dict_optional
())
}
res
.
update
(
self
.
_as_dict_optional
())
return
res
class
IconifyAlias
(
IconifyOptional
):
...
...
@@ -62,9 +67,11 @@ class IconifyAlias(IconifyOptional):
return
self
def
as_dict
(
self
)
->
dict
:
re
turn
{
re
s
=
{
"
parent
"
:
self
.
parent
,
}.
update
(
self
.
_as_dict_optional
())
}
res
.
update
(
self
.
_as_dict_optional
())
return
res
class
IconifyJSON
(
IconifyOptional
):
...
...
@@ -103,9 +110,21 @@ class IconifyJSON(IconifyOptional):
return
self
@classmethod
def
from_file
(
cls
,
src_file
:
Union
[
str
,
TextIO
]
=
None
,
**
kwargs
)
->
"
IconifyJSON
"
:
if
isinstance
(
src_file
,
str
):
with
open
(
src_file
,
"
r
"
)
as
in_file
:
src
=
json
.
load
(
in_file
)
else
:
src
=
json
.
load
(
src_file
)
return
cls
.
from_dict
(
src
,
**
kwargs
)
def
as_dict
(
self
)
->
dict
:
re
turn
{
re
s
=
{
"
prefix
"
:
self
.
prefix
,
"
icons
"
:
{
name
:
icon
.
as_dict
()
for
name
,
icon
in
self
.
icons
},
"
aliases
"
:
{
name
:
alias
.
as_dict
()
for
name
,
alias
in
self
.
aliases
},
}.
update
(
self
.
_as_dict_optional
())
"
icons
"
:
{
name
:
icon
.
as_dict
()
for
name
,
icon
in
self
.
icons
.
items
()},
"
aliases
"
:
{
name
:
alias
.
as_dict
()
for
name
,
alias
in
self
.
aliases
.
items
()},
}
res
.
update
(
self
.
_as_dict_optional
())
return
res
This diff is collapsed.
Click to expand it.
dj_iconify/urls.py
View file @
c942479d
...
...
@@ -3,5 +3,5 @@ from django.urls import re_path
from
.
import
views
urlpatterns
=
[
re_path
(
r
'
^(?P<collection>[A-Za-z0-9-]+).(?P<format>js
|js
on)
'
,
views
.
Iconify
API
View
.
as_view
(),
name
=
'
iconify_
api
'
),
re_path
(
r
'
^(?P<collection>[A-Za-z0-9-]+)
\
.(?P<format
_
>js
(
on)
?)
'
,
views
.
Iconify
JSON
View
.
as_view
(),
name
=
'
iconify_
json
'
),
]
This diff is collapsed.
Click to expand it.
dj_iconify/views.py
View file @
c942479d
from
django.http
import
HttpRequest
,
HttpResponse
import
json
import
os
from
django.http
import
Http404
,
HttpRequest
,
HttpResponse
,
HttpResponseBadRequest
from
django.views.generic
import
View
from
.conf
import
JSON_ROOT
from
.types
import
IconifyJSON
class
IconifyJSONView
(
View
):
"""
Serve the Iconify icon data retrieval API.
"""
def
get
(
self
,
request
:
HttpRequest
,
collection
:
str
,
format_
:
str
)
->
HttpResponse
:
"""
Retrieve a set of icons using a GET request.
The view supports both JSON and JSONP responses.
"""
# Icon names are passed as comma-separated list
icons
=
request
.
GET
.
get
(
"
icons
"
,
None
)
if
icons
is
not
None
:
icons
=
icons
.
split
(
"
,
"
)
# For JSONP, the callback name has to be passed
if
format_
==
"
js
"
:
callback
=
request
.
GET
.
get
(
"
callback
"
,
None
)
if
callback
is
None
:
return
HttpResponseBadRequest
(
"
The callback argument is mandatory for JSONP.
"
)
# Load icon set through Iconify types
collection_file
=
os
.
path
.
join
(
JSON_ROOT
,
"
json
"
,
f
"
{
collection
}
.json
"
)
try
:
print
(
icons
)
icon_set
=
IconifyJSON
.
from_file
(
collection_file
,
only
=
icons
)
except
FileNotFoundError
as
exc
:
raise
Http404
(
f
"
Icon collection
{
collection
}
not found
"
)
from
exc
except
KeyError
as
exc
:
raise
Http404
(
str
(
exc
))
from
exc
class
IconifyAPIView
(
View
):
"""
Serve the Iconify retrieval API.
"""
def
get
(
self
,
request
:
HttpRequest
,
collection
:
str
,
format
:
str
)
->
HttpResponse
:
pass
# Get result JSON and form response
res
=
json
.
dumps
(
icon_set
.
as_dict
())
if
format_
==
"
js
"
:
res
=
f
"
{
callback
}
(
{
res
}
)
"
return
HttpResponse
(
res
,
content_type
=
"
application/json
"
)
This diff is collapsed.
Click to expand it.