-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0dbfe25
Showing
14 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
name: Upload Python Package | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.9' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install build | ||
- name: Build package | ||
run: python -m build --sdist | ||
- name: Publish package | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dist/ | ||
node_modules/ | ||
*.pyc | ||
*.egg-info/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <http://unlicense.org/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Django Filepond Widget | ||
|
||
|
||
## License | ||
|
||
You can freely use this project without limitations. | ||
More specificallly, this project is freely licenced under the "Unlicense". | ||
See the LICENSE file for more information. | ||
|
||
Note that django, django_drf_filepond, filepond and js-cookie are licensed under | ||
different licences. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "django_filepond_widget", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"dependencies": { | ||
"filepond": "^4.30.4", | ||
"js-cookie": "^3.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[project] | ||
name = "django-filepond-widget" | ||
version = "0.1.0" | ||
description = "" | ||
readme = "README.md" | ||
authors = [{ name = "Jelle Besseling", email = "[email protected]" }] | ||
license = {text = "Unlicense"} | ||
dependencies = [ | ||
"django>=3", | ||
"django-drf-filepond>=0.4.0", | ||
] | ||
requires-python = ">=3" | ||
|
||
[project.urls] | ||
homepage = "https://github.com/pingiun/django-filepond-widget" | ||
repository = "https://github.com/pingiun/django-filepond-widget" | ||
documentation = "https://github.com/pingiun/django-filepond-widget" | ||
|
||
[build-system] | ||
requires = ["setuptools>=61.0.0", "wheel"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.setuptools.packages.find] | ||
where = ["src"] | ||
|
||
[tool.setuptools.package-data] | ||
"*" = ["*.html", "*.css", "*.js"] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.apps import AppConfig | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class FilepondWidgetConfig(AppConfig): | ||
"""AppConfig class for Filepond Widget app.""" | ||
|
||
name = "filepond_widget" | ||
verbose_name = _("Filepond Wisdget") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import json | ||
from django import forms | ||
from django.core.files.base import File | ||
|
||
from django_drf_filepond.models import TemporaryUpload | ||
|
||
|
||
class FilePondWidget(forms.FileInput): | ||
needs_multipart_form = True | ||
template_name = "filepond_widget/widget.html" | ||
|
||
def __init__(self, attrs=None): | ||
super().__init__(attrs) | ||
self.filepond_options = {} | ||
|
||
def value_from_datadict(self, data, files, name): | ||
upload_id = data.get(name) | ||
if upload_id is None: | ||
return files.get(name) | ||
return upload_id | ||
|
||
def value_omitted_from_data(self, data, files, name): | ||
return name not in data and name not in files | ||
|
||
def get_context(self, name: str, value, attrs): | ||
context = super().get_context(name, value, attrs) | ||
context["filepond_options"] = json.dumps(self.filepond_options) | ||
return context | ||
|
||
|
||
class FilePondField(forms.FileField): | ||
widget = FilePondWidget | ||
|
||
def __init__( | ||
self, | ||
*, | ||
max_length=None, | ||
allow_empty_file=False, | ||
filepond_options=None, | ||
**kwargs | ||
): | ||
super().__init__( | ||
max_length=max_length, allow_empty_file=allow_empty_file, **kwargs | ||
) | ||
self.widget.filepond_options = filepond_options or {} | ||
|
||
def to_python(self, data): | ||
if isinstance(data, str): | ||
temp_upload = TemporaryUpload.objects.get(upload_id=data) | ||
return File(temp_upload.file, name=temp_upload.upload_name) | ||
return super().to_python(data) |
1 change: 1 addition & 0 deletions
1
src/django_filepond_widget/static/filepond_widget/css/filepond.min.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../../node_modules/filepond/dist/filepond.min.css |
1 change: 1 addition & 0 deletions
1
src/django_filepond_widget/static/filepond_widget/js/filepond.min.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../../node_modules/filepond/dist/filepond.min.js |
1 change: 1 addition & 0 deletions
1
src/django_filepond_widget/static/filepond_widget/js/js.cookie.min.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../../node_modules/js-cookie/dist/js.cookie.min.js |
53 changes: 53 additions & 0 deletions
53
src/django_filepond_widget/templates/filepond_widget/widget.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{% load static %} | ||
<style> | ||
.filepond--panel-root { | ||
background-color: var(--darkened-bg); | ||
} | ||
|
||
.filepond--credits { | ||
display: none; | ||
} | ||
.filepond { | ||
min-width: 200px; | ||
min-height: 76px; | ||
} | ||
</style> | ||
|
||
<input type="file" class="filepond"> | ||
|
||
<!-- Load FilePond library --> | ||
<script type="text/javascript" src="{% static "filepond_widget/js/filepond.min.js" %}"></script> | ||
<script type="text/javascript" src="{% static "filepond_widget/js/js.cookie.min.js" %}"></script> | ||
<link rel="stylesheet" href="{% static "filepond_widget/css/filepond.min.css" %}"> | ||
|
||
<!-- Turn all file input elements into ponds --> | ||
<script> | ||
FilePond.parse(document.body); | ||
FilePond.setOptions({ | ||
name: '{{ widget.name }}', | ||
chunkUploads: true, | ||
chunkSize: 500000, | ||
dropOnPage: true, | ||
allowMultiple: false, | ||
allowPaste: true, | ||
allowBrowse: true, | ||
allowDrop: true, | ||
server: { | ||
headers: { 'X-CSRFToken': Cookies.get('csrftoken') }, | ||
url: '/fp', | ||
process: { | ||
url: '/process/', | ||
method: 'POST', | ||
ondata: (formData) => { | ||
formData.append('fp_upload_field', "{{ widget.name }}"); | ||
return formData; | ||
}, | ||
}, | ||
patch: '/patch/', | ||
revert: '/revert/', | ||
fetch: '/fetch/?target=', | ||
load: '/load/' | ||
}, | ||
...JSON.parse('{{ filepond_options|safe }}') | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
filepond@^4.30.4: | ||
version "4.30.4" | ||
resolved "https://registry.yarnpkg.com/filepond/-/filepond-4.30.4.tgz#036d87d9b0ab27d19fb5e302eae799df90e094e4" | ||
integrity sha512-FCwsMvG9iiEs6uobdDrTaKsCgsqys0NuLgPPD8n37AYVYBiiDkrPkk9MSIU5rT2FahYcL1bScYI9huIPtlzqyA== | ||
|
||
js-cookie@^3.0.1: | ||
version "3.0.1" | ||
resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-3.0.1.tgz#9e39b4c6c2f56563708d7d31f6f5f21873a92414" | ||
integrity sha512-+0rgsUXZu4ncpPxRL+lNEptWMOWl9etvPHc/koSRp6MPwpRYAhmk0dUG00J4bxVV3r9uUzfo24wW0knS07SKSw== |