Skip to content

Commit a749829

Browse files
committed
first commit
0 parents  commit a749829

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+16700
-0
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"git.ignoreLimitWarning": true
3+
}

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2021, Dibyajyoti Mondal
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

MANIFEST.in

Whitespace-only changes.

README.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
===================
2+
django-cloudistatic
3+
===================
4+
5+
django-cloudistatic is a Django app to upload your staticfiles to Cloudinary and serve from there.
6+
Cloudinary serves files using CDN, which will reduce the load on django server and pages will load
7+
faster.
8+
9+
10+
Quick start
11+
-----------
12+
13+
1. Add "djangocloudistatic" to your INSTALLED_APPS setting like this::
14+
15+
INSTALLED_APPS = [
16+
...
17+
'djangocloudistatic',
18+
]
19+
20+
2. Declare the following settings variables (you will get them from Cloudinary dashboard) ::
21+
22+
CLOUDI_NAME = <Cloud name>
23+
CLOUDI_API_KEY = <API Key>
24+
CLOUDI_API_SECRET = <API Secret>
25+
26+
3. Include ``STATICFILES_DIRS`` and ``STATIC_ROOT`` in settings.py file (Should be included before ``STATIC_URL``)
27+
of your project. You may refer to https://docs.djangoproject.com/en/3.2/howto/static-files/ for details.
28+
29+
4. Modify the ``STATIC_URL`` like this::
30+
31+
STATIC_URL=f'https://res.cloudinary.com/{CLOUDI_NAME}/raw/upload/v1/{STATIC_ROOT}/'
32+
33+
5. Now run ``python manage.py collectstatic`` command to collect all staticfiles to STATIC_ROOT
34+
of your project.
35+
36+
6. Finally, run ``python manage.py cloudistatic`` to upload staticfiles to Cloudinary. Wait for a few minutes
37+
and your staticfiles will be ready to be served from there. If you want to delete your local STATIC_ROOT (staticfiles will not be served from here now) after
38+
uploading to cloud, then you should run ``python manage.py cloudistatic --deletelocal`` instead of
39+
``python manage.py cloudistatic``.
4.63 KB
Binary file not shown.

django_cloudistatic.egg-info/PKG-INFO

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Metadata-Version: 2.1
2+
Name: django-cloudistatic
3+
Version: 0.1.dev1
4+
Summary: A Django app to serve staticfiles using cloudinary
5+
Home-page: https://djm-1.github.io/
6+
Author: Dibyajyoti Mondal
7+
Author-email: dibyajyoti.bhs@gmail.com
8+
License: BSD-3-Clause
9+
Platform: UNKNOWN
10+
Classifier: Environment :: Web Environment
11+
Classifier: Framework :: Django
12+
Classifier: Framework :: Django :: 3.2
13+
Classifier: Intended Audience :: Developers
14+
Classifier: License :: OSI Approved :: BSD License
15+
Classifier: Operating System :: OS Independent
16+
Classifier: Programming Language :: Python
17+
Classifier: Programming Language :: Python :: 3
18+
Classifier: Programming Language :: Python :: 3 :: Only
19+
Classifier: Programming Language :: Python :: 3.6
20+
Classifier: Programming Language :: Python :: 3.7
21+
Classifier: Programming Language :: Python :: 3.8
22+
Classifier: Topic :: Internet :: WWW/HTTP
23+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
24+
Requires-Python: >=3.6
25+
License-File: LICENSE
26+
27+
===================
28+
django-cloudistatic
29+
===================
30+
31+
django-cloudistatic is a Django app to upload your staticfiles to Cloudinary and serve from there.
32+
Cloudinary serves files using CDN, which will reduce the load on django server and pages will load
33+
faster.
34+
35+
36+
Quick start
37+
-----------
38+
39+
1. Add "djangocloudistatic" to your INSTALLED_APPS setting like this::
40+
41+
INSTALLED_APPS = [
42+
...
43+
'djangocloudistatic',
44+
]
45+
46+
2. Declare the following settings variables (you will get them from Cloudinary dashboard) ::
47+
48+
CLOUDI_NAME = <Cloud name>
49+
CLOUDI_API_KEY = <API Key>
50+
CLOUDI_API_SECRET = <API Secret>
51+
52+
3. Include ``STATICFILES_DIRS`` and ``STATIC_ROOT`` in settings.py file (Should be included before ``STATIC_URL``)
53+
of your project. You may refer to https://docs.djangoproject.com/en/3.2/howto/static-files/ for details.
54+
55+
4. Modify the ``STATIC_URL`` like this::
56+
57+
STATIC_URL=f'https://res.cloudinary.com/{CLOUDI_NAME}/raw/upload/v1/{STATIC_ROOT}/'
58+
59+
5. Now run ``python manage.py collectstatic`` command to collect all staticfiles to STATIC_ROOT
60+
of your project.
61+
62+
6. Finally, run ``python manage.py cloudistatic`` to upload staticfiles to Cloudinary. Wait for a few minutes
63+
and your staticfiles will be ready to be served from there. If you want to delete your local STATIC_ROOT (staticfiles will not be served from here now) after
64+
uploading to cloud, then you should run ``python manage.py cloudistatic --deletelocal`` instead of
65+
``python manage.py cloudistatic``.
66+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
LICENSE
2+
MANIFEST.in
3+
README.rst
4+
setup.cfg
5+
setup.py
6+
django_cloudistatic.egg-info/PKG-INFO
7+
django_cloudistatic.egg-info/SOURCES.txt
8+
django_cloudistatic.egg-info/dependency_links.txt
9+
django_cloudistatic.egg-info/requires.txt
10+
django_cloudistatic.egg-info/top_level.txt
11+
djangocloudistatic/__init__.py
12+
djangocloudistatic/admin.py
13+
djangocloudistatic/apps.py
14+
djangocloudistatic/models.py
15+
djangocloudistatic/tests.py
16+
djangocloudistatic/views.py
17+
djangocloudistatic/management/__init__.py
18+
djangocloudistatic/management/commands/__init__.py
19+
djangocloudistatic/management/commands/cloudistatic.py
20+
djangocloudistatic/migrations/__init__.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
django
2+
cloudinary
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
djangocloudistatic

djangocloudistatic/__init__.py

Whitespace-only changes.
Binary file not shown.
191 Bytes
Binary file not shown.
451 Bytes
Binary file not shown.
Binary file not shown.

djangocloudistatic/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

djangocloudistatic/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class DjangocloudistaticConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'djangocloudistatic'

djangocloudistatic/management/__init__.py

Whitespace-only changes.
Binary file not shown.

djangocloudistatic/management/commands/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
'''
2+
==============================================
3+
django-cloudistatic library
4+
Author: Dibyajyoti Mondal
5+
Github Profile : https://github.com/djm-1
6+
==============================================
7+
'''
8+
from django.core.management.base import BaseCommand, CommandError
9+
import cloudinary
10+
import cloudinary.uploader
11+
import cloudinary.api
12+
from django.conf import settings
13+
import os
14+
import shutil
15+
16+
17+
class Command(BaseCommand):
18+
help='Uploads the static files to cloudinary'
19+
20+
'''
21+
Additional arguments for cloudistatic
22+
'''
23+
def add_arguments(self, parser):
24+
25+
'''
26+
Named (optional) arguments to delete
27+
existing STATIC_ROOT in the current django project
28+
29+
Usage => python manage.py cloudistatic --deletelocal
30+
'''
31+
32+
parser.add_argument(
33+
'--deletelocal',
34+
action='store_true',
35+
help='Delete local STATIC_ROOT after uploading contents to Cloudinary',
36+
)
37+
38+
39+
40+
def handle(self,*args,**options):
41+
42+
'''
43+
Referring to Cloudinary credentials
44+
mentioned in settings.py file
45+
'''
46+
47+
cloud_name = settings.CLOUDI_NAME
48+
api_key = settings.CLOUDI_API_KEY
49+
api_secret = settings.CLOUDI_API_SECRET
50+
51+
'''
52+
configuring Cloudinary upload
53+
'''
54+
55+
cloudinary.config(
56+
cloud_name = cloud_name,
57+
api_key = api_key,
58+
api_secret = api_secret,
59+
secure = True
60+
)
61+
62+
'''
63+
file upload count
64+
'''
65+
66+
upload_count=0
67+
68+
69+
'''
70+
Uploading all files from STATIC_ROOT to Cloudinary
71+
'''
72+
73+
for dirpath, dirnames, filenames in os.walk(settings.STATIC_ROOT):
74+
for filename in [f for f in filenames]:
75+
file_to_upload=os.path.join(dirpath, filename)
76+
response=cloudinary.uploader.upload(file_to_upload,
77+
folder = dirpath.replace('\\','/'),
78+
public_id = os.path.splitext(filename)[0],
79+
invalidate=True,
80+
overwrite = True,
81+
resource_type = "raw",
82+
)
83+
84+
85+
print (file_to_upload+' uploaded...')
86+
upload_count+=1
87+
print(f'\n{upload_count} files staticfiles uploaded successfully !!!')
88+
89+
90+
'''
91+
if delete argument given
92+
'''
93+
94+
if options['deletelocal']:
95+
static_root=settings.STATIC_ROOT
96+
shutil.rmtree(settings.STATIC_ROOT)
97+
print(f'Local STATIC_ROOT directory {static_root} removed')

djangocloudistatic/migrations/__init__.py

Whitespace-only changes.
Binary file not shown.

djangocloudistatic/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

djangocloudistatic/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

djangocloudistatic/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
11.9 KB
Binary file not shown.

docs/_build/doctrees/index.doctree

12.8 KB
Binary file not shown.

docs/_build/html/.buildinfo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: b122112dfe1fdb9cfdff8c2647762ab5
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.. django-cloudistatic documentation master file, created by
2+
sphinx-quickstart on Fri Jul 30 20:42:07 2021.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to django-cloudistatic's documentation!
7+
===============================================
8+
9+
.. toctree::
10+
:maxdepth: 2
11+
:caption: Contents:
12+
13+
14+
15+
Indices and tables
16+
==================
17+
18+
* :ref:`genindex`
19+
* :ref:`modindex`
20+
* :ref:`search`
21+
22+
===================
23+
django-cloudistatic
24+
===================
25+
26+
django-cloudistatic is a Django app to upload your staticfiles to Cloudinary and serve from there.
27+
Cloudinary serves files using CDN, which will reduce the load on django server and pages will load
28+
faster.
29+
30+
31+
Quick start
32+
-----------
33+
34+
1. Add "djangocloudistatic" to your INSTALLED_APPS setting like this::
35+
36+
INSTALLED_APPS = [
37+
...
38+
'djangocloudistatic',
39+
]
40+
41+
2. Declare the following settings variables (you will get them from Cloudinary dashboard) ::
42+
43+
CLOUDI_NAME = <Cloud name>
44+
CLOUDI_API_KEY = <API Key>
45+
CLOUDI_API_SECRET = <API Secret>
46+
47+
3. Include ``STATICFILES_DIRS`` and ``STATIC_ROOT`` in settings.py file (Should be included before ``STATIC_URL``)
48+
of your project. You may refer to https://docs.djangoproject.com/en/3.2/howto/static-files/ for details.
49+
50+
4. Modify the ``STATIC_URL`` like this::
51+
52+
STATIC_URL=f'https://res.cloudinary.com/{CLOUDI_NAME}/raw/upload/v1/{STATIC_ROOT}/'
53+
54+
5. Now run ``python manage.py collectstatic`` command to collect all staticfiles to STATIC_ROOT
55+
of your project.
56+
57+
6. Finally, run ``python manage.py cloudistatic`` to upload staticfiles to Cloudinary. Wait for a few minutes
58+
and your staticfiles will be ready to be served from there. If you want to delete your local STATIC_ROOT (staticfiles will not be served from here now) after
59+
uploading to cloud, then you should run ``python manage.py cloudistatic --deletelocal`` instead of
60+
``python manage.py cloudistatic``.

0 commit comments

Comments
 (0)