Skip to content

Commit abdba1e

Browse files
committed
Path more flexible now
1 parent ff59945 commit abdba1e

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ INSTALLED_APPS = (
2727
In your templates add depending on the library and how you named the folder:
2828
```html
2929
{% load static %}
30-
<script src="{% static 'latest_auto_static_libs/jquery/jquery.min.js' %}" type="text/javascript"></script>
30+
<script src="{% static 'latest-auto-static-libs/jquery/jquery.min.js' %}" type="text/javascript"></script>
3131
```
3232

3333
You must run the downloading at the beginning (or to update). It will run automatically at migration:
@@ -48,7 +48,7 @@ Currently it supports the following libraries (bold is the name of the correspon
4848
* **fomantic_ui**: [Fomantic-UI](https://fomantic-ui.com/) from github (fork of semantic UI)
4949
* **semantic_ui**: [Semantic-UI](https://semantic-ui.com/) from github
5050
* **masonry**: [Masonry](https://masonry.desandro.com/) from github
51-
* **pygal_js**: [pygal.js](https://github.com/Kozea/pygal.js/)Javascript helper functions for pygal from github
51+
* **pygal_js**: [pygal.js](https://github.com/Kozea/pygal.js/) Javascript helper functions for pygal from github
5252

5353

5454
In your settings.py:
@@ -57,17 +57,17 @@ In your settings.py:
5757
from django_static_libs.libraries import jquery
5858
DJANGO_AUTO_STATIC_LIBS = {
5959
#The default is the jquery library. If you add other or custom libraries it will replace the default. it need always to be a dict, the key represents your folder and will be needed for the static import
60-
'libraries': {
61-
'jquery':jquery,
62-
'custom_full':
63-
{
64-
'provider' : GithubProvider("jquery/jquery"),
65-
'suffix_ignore': [".json"],
66-
'files_include': r"jquery-[\d\.]+/dist/(.*\.(js|map))",
67-
#auto creates in your static root a folder "latest_static_libs". If you change this default path be careful in the templates
68-
'destination':"auto",
69-
}
70-
}
60+
'libraries': {
61+
'jquery': jquery,
62+
'custom_full': {
63+
'provider' : GithubProvider("jquery/jquery"),
64+
'suffix_ignore': [".json"],
65+
'files_include': r"jquery-[\d\.]+/dist/(.*\.(js|map))",
66+
#auto creates in your static root a folder "latest_static_libs". If you change this default path be careful in the templates
67+
'destination': "auto",
68+
}
69+
},
70+
'destination_folder': 'django-auto-static-libs'
7171
}
7272
```
7373
## Add your custom library
@@ -89,4 +89,5 @@ You can add your own library as a dict into the config. Please submit your confi
8989
* add more libraries for downloading
9090
* new command: list of all libraries
9191
* remember the currently installed version
92+
* improve logging / no prints
9293
* testing

django_auto_static_libs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Version code adopted from Django development version.
44
https://github.com/django/django
55
"""
6-
VERSION = (0, 4,1, 'final', 0)
6+
VERSION = (0, 4,2, 'final', 0)
77

88
def get_version(version=None):
99
"""

django_auto_static_libs/management/commands/static-libs-download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def handle(self, *args, **kwargs):
5050
print("Could not find type of library")
5151
continue
5252
if not "destination" in lib or lib["destination"] == "auto":
53-
lib["destination"] = os.path.join(settings.STATIC_ROOT, "latest_auto_static_libs")
53+
lib["destination"] = settings.DESTINATION_ROOT
5454
else:
5555
print("Currently only auto path is support as destination")
5656
#>> > variables = {"publication": "article", "author": "Me"}
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
from django.conf import settings as django_settings
22
from django.core.exceptions import ImproperlyConfigured
33
from django_auto_static_libs.libraries import jquery
4+
import os
45

5-
if not hasattr(django_settings,"STATIC_ROOT"):
6-
raise ImproperlyConfigured("Django-auto-static-libs needs STATIC_ROOT in settings.py")
7-
STATIC_ROOT=getattr(django_settings,"STATIC_ROOT")
6+
DJANGO_AUTO_STATIC_LIBS = dict(libraries={
7+
'jquery': jquery
8+
}, destination_folder='django-auto-static-libs')
89

9-
DJANGO_AUTO_STATIC_LIBS=getattr(django_settings,"DJANGO_AUTO_STATIC_LIBS",{"libraries": {
10-
'jquery': jquery
11-
}
12-
})
10+
if hasattr(django_settings, "DJANGO_AUTO_STATIC_LIBS"):
11+
if 'libraries' in getattr(django_settings, "DJANGO_AUTO_STATIC_LIBS"):
12+
DJANGO_AUTO_STATIC_LIBS['libraries'] = getattr(django_settings, "DJANGO_AUTO_STATIC_LIBS")['libraries']
13+
DJANGO_AUTO_STATIC_LIBS = {**DJANGO_AUTO_STATIC_LIBS, **getattr(django_settings, "DJANGO_AUTO_STATIC_LIBS")}
14+
15+
# check whether the folder is a proper path
16+
if not os.path.isabs(DJANGO_AUTO_STATIC_LIBS['destination_folder']):
17+
if not hasattr(django_settings, "STATIC_ROOT"):
18+
raise ImproperlyConfigured("Django-auto-static-libs needs STATIC_ROOT in settings.py")
19+
STATIC_ROOT = getattr(django_settings, "STATIC_ROOT")
20+
DESTINATION_ROOT=os.path.join(STATIC_ROOT,DJANGO_AUTO_STATIC_LIBS['destination_folder'])
21+
else:
22+
DESTINATION_ROOT=DJANGO_AUTO_STATIC_LIBS['destination_folder']

0 commit comments

Comments
 (0)