Skip to content

Commit 0fc6052

Browse files
author
Two Dev
committed
init source code
0 parents  commit 0fc6052

Some content is hidden

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

50 files changed

+2553
-0
lines changed

.editorconfig

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.{py,rst,ini}]
12+
indent_style = space
13+
indent_size = 4
14+
15+
[*.{html,css,scss,json,yml,xml}]
16+
indent_style = space
17+
indent_size = 2
18+
19+
[*.md]
20+
trim_trailing_whitespace = false
21+
22+
[Makefile]
23+
indent_style = tab
24+
25+
[default.conf]
26+
indent_style = space
27+
indent_size = 2

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
*.py[cod]
2+
__pycache__
3+
4+
# C extensions
5+
*.so
6+
7+
# Packages
8+
*.egg
9+
*.egg-info
10+
build
11+
eggs
12+
parts
13+
bin
14+
var
15+
sdist
16+
develop-eggs
17+
.installed.cfg
18+
lib
19+
lib64
20+
.pypirc
21+
22+
# Installer logs
23+
pip-log.txt
24+
25+
# Unit test / coverage reports
26+
.coverage
27+
.tox
28+
nosetests.xml
29+
htmlcov
30+
31+
# Translations
32+
*.mo
33+
34+
# Mr Developer
35+
.mr.developer.cfg
36+
.project
37+
.pydevproject
38+
39+
# Pycharm/Intellij
40+
.idea
41+
42+
# Complexity
43+
output/*.html
44+
output/*/index.html
45+
46+
# Sphinx
47+
docs/_build
48+
/.tox/
49+
/dist/
50+
51+
# venv
52+
/.pypirc
53+
/examples/.python-version
54+
55+
# OS
56+
.DS_Store
57+
examples/.DS_Store
58+
examples/db.sqlite3

.pre-commit-config.yaml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
exclude: '^docs/|/migrations/'
2+
default_stages: [commit]
3+
4+
default_language_version:
5+
python: python3.11
6+
7+
repos:
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v4.5.0
10+
hooks:
11+
- id: trailing-whitespace
12+
- id: end-of-file-fixer
13+
- id: check-json
14+
- id: check-toml
15+
- id: check-xml
16+
- id: check-yaml
17+
- id: debug-statements
18+
- id: check-builtin-literals
19+
- id: check-case-conflict
20+
- id: check-docstring-first
21+
- id: detect-private-key
22+
exclude: |
23+
(?x)(
24+
^media/
25+
)
26+
27+
- repo: https://github.com/adamchainz/django-upgrade
28+
rev: '1.16.0'
29+
hooks:
30+
- id: django-upgrade
31+
args: ['--target-version', '4.2']
32+
33+
# run the black.
34+
- repo: https://github.com/psf/black
35+
rev: 24.2.0
36+
hooks:
37+
- id: black
38+
args: [--target-version=py311]
39+
40+
# run the isort.
41+
- repo: https://github.com/PyCQA/isort
42+
rev: 5.13.2
43+
hooks:
44+
- id: isort
45+
46+
# run the flake8.
47+
- repo: https://github.com/PyCQA/flake8
48+
rev: 7.0.0
49+
hooks:
50+
- id: flake8
51+
52+
- repo: https://github.com/Riverside-Healthcare/djLint
53+
rev: v1.34.1
54+
hooks:
55+
- id: djlint-reformat-django
56+
57+
# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
58+
ci:
59+
autoupdate_schedule: weekly
60+
skip: []
61+
submodules: false

AUTHORS

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=======
2+
Credits
3+
=======
4+
5+
Development Lead
6+
----------------
7+
8+
* Tu Pham (thewebscraping) <[email protected]>
9+
10+
Contributors
11+
------------

CHANGELOG.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. :changelog:
2+
3+
History
4+
-------
5+
6+
1.0.0 (2024-07-25)
7+
++++++++++++++++++
8+
9+
* First release.

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 thewebscraping
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include AUTHORS
2+
include LICENSE
3+
include README.md
4+
include ChangeLog.rst
5+
recursive-include django_chunk_file_upload *.html *.txt *.xml *.po *.mo *.css *.js
6+
recursive-include docs Makefile conf.py *.rst

README.md

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Django Chunk File Upload
2+
3+
Django Chunk File Upload is an alternative utility that helps you easily edit Django's chunked, drag and drop file uploads.
4+
5+
<img src="https://i.ibb.co/9y2SgmS/f-P5-Or-Gkxk0-Ynj00ct-G.webp" alt="f-P5-Or-Gkxk0-Ynj00ct-G" border="0">
6+
7+
Features
8+
----------
9+
- Multiple file uploads.
10+
- Drag and Drop UI.
11+
- MD5 checksum file.
12+
- Chunked uploads: optimizing large file transfers.
13+
- Prevent uploading existing files with MD5 checksum.
14+
- Easy to use any models.
15+
16+
17+
Quickstart
18+
----------
19+
20+
Install Django Chunk File Upload:
21+
```shell
22+
pip install git+https://github.com/thewebscraping/django-chunk-file-upload.git
23+
```
24+
25+
26+
Add it to your `settings.py`:
27+
28+
```python
29+
INSTALLED_APPS = [
30+
'django_chunk_file_upload',
31+
]
32+
```
33+
34+
Add it to your `urls.py`:
35+
36+
37+
```python
38+
from django.urls import path, include
39+
40+
urlpatterns = [
41+
path("file-manager/", include("django_chunk_file_upload.urls")),
42+
]
43+
```
44+
45+
Run Demo
46+
47+
Demo URL: http://127.0.0.1:8000/file-manager/uploads/
48+
```shell
49+
cd examples
50+
python manage.py migrate
51+
python manage.py runserver
52+
```
53+
54+
Change default config: `settings.py`
55+
56+
```python
57+
DJANGO_CHUNK_FILE_UPLOAD = {
58+
"chunk_size": 1024 * 1024 * 2, # # custom chunk size upload (default: 2MB).
59+
"upload_to": "custom_folder/%Y/%m/%d", # custom upload folder.
60+
"is_metadata_storage": True, # save file metadata
61+
"js": (
62+
"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js",
63+
"https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.2/spark-md5.min.js",
64+
"https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js",
65+
), # use cdn.
66+
"css": (
67+
"custom.css"
68+
) # custom css path.
69+
}
70+
71+
```
72+
73+
Custom Your Models
74+
----------
75+
76+
models.py
77+
78+
```python
79+
from django.db import models
80+
from django_chunk_file_upload.models import FileManager
81+
82+
83+
class Tag(models.Model):
84+
name = models.CharField(max_length=255)
85+
86+
87+
class YourModel(FileManager):
88+
tags = models.ManyToManyField(Tag)
89+
custom_field = models.CharField(max_length=255)
90+
91+
```
92+
93+
forms.py
94+
95+
```python
96+
from django_chunk_file_upload.forms import ChunkedUploadFileForm
97+
from .models import YourModel
98+
99+
100+
class YourForm(ChunkedUploadFileForm):
101+
class Meta:
102+
model = YourModel
103+
fields = "__all__"
104+
```
105+
106+
views.py
107+
108+
```python
109+
from django_chunk_file_upload.views import ChunkedUploadView
110+
from .forms import YourForm
111+
112+
113+
class CustomChunkedUploadView(ChunkedUploadView):
114+
form_class = YourForm
115+
# chunk_size = 1024 * 1024 * 2 # custom chunk size upload (default: 2MB).
116+
# upload_to = "custom_folder/%Y/%m/%d" # custom upload folder.
117+
# template_name = "custom_template.html" # custom template
118+
```
119+
120+
custom_template.html
121+
```html
122+
<form action="."
123+
method="post"
124+
id="chunk-upload-form">
125+
{{ form.media }}
126+
{{ form }}
127+
</form>
128+
```
129+
130+
urls.py
131+
132+
```pyhon
133+
from django.urls import path
134+
135+
from .views import CustomChunkedUploadView
136+
137+
urlpatterns = [
138+
path("uploads/", CustomChunkedUploadView.as_view(), name="custom-uploads"),
139+
]
140+
```
141+
142+
This package is under development, only supports create view. There are also no features related to image optimization. Use at your own risk.

django_chunk_file_upload/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
__title__ = "django-chunk-file-upload"
2+
__version__ = "1.0.0"
3+
__author__ = "Tu Pham"
4+
__license__ = "MIT"
5+
__copyright__ = "Copyright 2024 Tu Pham and contributors"

django_chunk_file_upload/admin.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import annotations
2+
3+
from django.contrib import admin
4+
5+
from .forms import ChunkedUploadFileAdminForm
6+
from .models import FileManager
7+
8+
9+
@admin.register(FileManager)
10+
class FileManagerModelAdmin(admin.ModelAdmin):
11+
form = ChunkedUploadFileAdminForm
12+
search_fields = ("name",)
13+
list_display = (
14+
"name",
15+
"status",
16+
"created_at",
17+
"updated_at",
18+
)
19+
20+
add_form_template = "django_chunk_file_upload/admin/add_form.html"
21+
change_form_template = "django_chunk_file_upload/admin/change_form.html"

0 commit comments

Comments
 (0)