Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload support #189

Merged
merged 91 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
52c66e0
upload images to local storage
sinisaos Jul 13, 2022
4acd67a
empty static directory
sinisaos Jul 13, 2022
02a90b1
unnecessary console.log removed
sinisaos Jul 13, 2022
c42d59c
add docs
sinisaos Jul 19, 2022
698ad56
Merge branch 'master' into image_upload
sinisaos Jul 22, 2022
2aeadb0
fix upload test
sinisaos Jul 22, 2022
cc6b7b2
hide array add button for media columns
sinisaos Jul 22, 2022
fc1592d
media handler class
dantownsend Jul 23, 2022
7057d1b
flesh out local media storage
dantownsend Jul 26, 2022
39190f0
added tests for `generate_file_id`
dantownsend Jul 26, 2022
d386f68
fleshed out `LocalMediaStorage`
dantownsend Jul 28, 2022
9a90c1a
remove print statement
dantownsend Jul 28, 2022
fb9b192
media_columns is now a dict
dantownsend Jul 28, 2022
6a6a3a4
show error message is file posting fails
dantownsend Jul 29, 2022
be05dd8
return any `ValueError`s as `HTTPException`
dantownsend Jul 29, 2022
ed4c20f
add webp as an allowed file extension
dantownsend Jul 29, 2022
48af429
improve error message for disallowed file name characters
dantownsend Jul 29, 2022
95e6f0a
fix bug in file name truncation
dantownsend Jul 29, 2022
b3eeb43
fix tests
dantownsend Jul 29, 2022
7848d10
added `generate_file_url` endpoint
dantownsend Jul 30, 2022
3a53949
added test for generating file URL endpoint
dantownsend Jul 30, 2022
d862672
broke up `ALLOWED_EXTENSIONS`
dantownsend Jul 30, 2022
28b9343
added `MediaViewer` component
dantownsend Jul 30, 2022
1882a84
arrays of images now works in `RowListing`
dantownsend Jul 30, 2022
a7b571d
detect if media is an image in `MediaViewer`
dantownsend Jul 30, 2022
fc8a1ae
added support for video playback in `MediaViewer`
dantownsend Jul 30, 2022
324502f
add `example_media` folder to git - needed for tests
dantownsend Jul 30, 2022
6d318de
added audio playback support to `MediaViewer`
dantownsend Jul 31, 2022
26603b2
don't show media viewer content until URL has been fetched
dantownsend Jul 31, 2022
8d0b5b1
slightly smaller text for add button in array widget
dantownsend Jul 31, 2022
426494d
started integrating `MediaViewer` into row detail page
dantownsend Jul 31, 2022
396c932
add PDF support to `MediaViewer`
dantownsend Jul 31, 2022
41efa53
improve image and video containers on `MediaViewer`
dantownsend Jul 31, 2022
0a39eb9
improved loading indicator in `MediaViewer`
dantownsend Jul 31, 2022
3f95605
remove unused import
dantownsend Jul 31, 2022
cabe139
remove test files
dantownsend Aug 1, 2022
aeefdb4
don't allow double periods in the file name
dantownsend Aug 1, 2022
71fc1c1
add s3 as optional requirements
dantownsend Aug 1, 2022
b0ca360
add requirements file for faker
dantownsend Aug 1, 2022
d0d7aaa
removed `media_url` argument from `LocalMediaStorage`
dantownsend Aug 1, 2022
47a3fa8
add missing import
dantownsend Aug 1, 2022
77e8a61
added first version of `S3MediaStorage`
dantownsend Aug 1, 2022
d77cbd3
put `S3MediaStorage` and `LocalMediaStorage` in separate files
dantownsend Aug 1, 2022
8bad1a4
allow lower coverage for now
dantownsend Aug 1, 2022
236b4a5
moved files into new folder structure
dantownsend Aug 1, 2022
e784d48
added tests for S3
dantownsend Aug 2, 2022
11b61d3
use connection kwargs
dantownsend Aug 2, 2022
b288a92
S3 can optionally be used in the example app
dantownsend Aug 2, 2022
50ce8b3
mention that S3 usage in example.py is just for ``Movie.poster``
dantownsend Aug 2, 2022
7c94ce8
Merge branch 'master' into 109-media-handlers
dantownsend Aug 2, 2022
3f17007
`MediaStorage` now accepts a `column` arg
dantownsend Aug 2, 2022
4d35189
added helper methods to media storage classes
dantownsend Aug 2, 2022
a197c8a
fix lgtm warning
dantownsend Aug 2, 2022
6801ac0
reduce coverage required for now
dantownsend Aug 2, 2022
9b18574
ignore coverage for `TYPE_CHECKING` imports
dantownsend Aug 2, 2022
08631f2
add test to make sure `LocalMediaStorage` creates the media folder is…
dantownsend Aug 2, 2022
53f8084
add test for `LocalMediaStorage.get_file`
dantownsend Aug 2, 2022
2abafbd
remove unused import
dantownsend Aug 2, 2022
6470ea6
close file at end of test
dantownsend Aug 2, 2022
bd426e7
added test for `LocalMediaStorage.bulk_delete`
dantownsend Aug 2, 2022
4b59f09
make sure duplicate file names raises an error
dantownsend Aug 2, 2022
ee33479
improve coverage for `S3MediaStorage`
dantownsend Aug 2, 2022
4efd48d
more tests for `S3MediaStorate` - getting and listing files
dantownsend Aug 2, 2022
b9ca34f
added test for `S3MediaStorage.delete_file`
dantownsend Aug 2, 2022
62468aa
add tests for `S3MediaStorage.bulk_delete_files`
dantownsend Aug 2, 2022
f57b7bd
exclude abstract methods from code coverage
dantownsend Aug 2, 2022
c2a56de
fix nginx syntax error
dantownsend Aug 3, 2022
e768df1
added test for `MediaStorage.get_file_keys_from_db`
dantownsend Aug 3, 2022
4abedbb
add tests for allowed column types
dantownsend Aug 3, 2022
ce2805a
add test for files with no extension
dantownsend Aug 3, 2022
1fb60e2
added test for `MediaStorage.delete_unused_files`
dantownsend Aug 3, 2022
e8f1085
increase minimum coverage
dantownsend Aug 3, 2022
8824802
updated docs
dantownsend Aug 3, 2022
a7bb2ac
added images showing the UI for different file types
dantownsend Aug 3, 2022
3ac1f77
adds docs for `IMAGE_EXTENSIONS` etc
dantownsend Aug 3, 2022
da06fb1
fix typos in the docs
dantownsend Aug 3, 2022
eb63492
add links to 'cleaning up files'
dantownsend Aug 3, 2022
e098c31
`file_id` -> `file_key`
dantownsend Aug 3, 2022
9eae605
added support for S3 folders
dantownsend Aug 4, 2022
d0f60ee
update docs about keeping files in separate S3 buckets
dantownsend Aug 4, 2022
e2e51fb
fix error with unused variable
dantownsend Aug 4, 2022
9827a44
raise an error is media storage is misconfigured
dantownsend Aug 4, 2022
5ebfb0a
fix lgtm warnings
dantownsend Aug 4, 2022
bf459bd
moved logic for file name verification into separate method
dantownsend Aug 4, 2022
fa914f7
moved `MediaStorage` to api reference page
dantownsend Aug 4, 2022
fb42eea
add Sphinx viewcode extension
dantownsend Aug 4, 2022
7b86545
add extra features to homepage of docs
dantownsend Aug 4, 2022
b801edd
added `LoadingOverlay` component
dantownsend Aug 4, 2022
6c352fc
make code in `example.py` consistent with docs
dantownsend Aug 4, 2022
7a273f4
fix test
dantownsend Aug 4, 2022
60ce88e
make array widget work
dantownsend Aug 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements/requirements.txt
pip install -r requirements/extra/s3.txt
pip install -r requirements/test-requirements.txt
- name: Test with pytest, SQLite
run: ./scripts/run-tests.sh
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ htmlcov/
.env/
.venv/
docs/ebug
piccolo_admin/example_media/*
!piccolo_admin/example_media/.gitkeep
piccolo_admin/.env
73 changes: 67 additions & 6 deletions admin_ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions admin_ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@storybook/addon-essentials": "^6.4.9",
"@storybook/addon-links": "^6.4.9",
"@storybook/vue": "^6.4.9",
"@types/node": "^18.6.2",
"@vue/cli-plugin-babel": "~4.5.15",
"@vue/cli-plugin-typescript": "~4.5.15",
"@vue/cli-service": "^4.5.12",
Expand Down
82 changes: 72 additions & 10 deletions admin_ui/src/components/ArrayWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,106 @@
id="choice"
v-on:change="updateArray($event, index)"
/>
<a
href="#"
v-on:click.prevent="showMedia(index)"
:value="value"
v-if="isMediaColumn && !isFilter"
><font-awesome-icon icon="eye" title="View"
/></a>
<a href="#" v-on:click.prevent="removeArrayElement(index)">
<font-awesome-icon icon="times" />
<font-awesome-icon icon="times" title="Remove" />
</a>
</li>
<li>
<a href="#" v-on:click.prevent="addArrayElement">
<font-awesome-icon icon="plus" />{{ $t("Add") }}
<a
class="add"
href="#"
v-on:click.prevent="addArrayElement"
v-if="enableAddButton"
>
<font-awesome-icon icon="plus" title="Add" />{{ $t("Add") }}
</a>
</li>
</ul>
<MediaViewer
v-if="showMediaViewer"
:mediaViewerConfig="mediaViewerConfig"
@close="showMediaViewer = false"
/>
</div>
</template>

<script lang="ts">
export default {
import Vue, { PropType } from "vue"
import MediaViewer from "./MediaViewer.vue"
import { MediaViewerConfig } from "@/interfaces"

export default Vue.extend({
props: {
array: {
type: Array,
type: Array as PropType<string[]>,
default: () => []
},
inputType: {
type: String,
type: String as PropType<string>,
default: "text"
},
fieldName: {
type: String as PropType<string>,
default: ""
},
enableAddButton: {
type: Boolean as PropType<boolean>,
default: true
},
isFilter: {
type: Boolean as PropType<boolean>,
default: true
}
},
components: {
MediaViewer
},
data() {
return {
internalArray: []
internalArray: [],
showMediaViewer: false,
mediaViewerConfig: null as MediaViewerConfig
}
},
computed: {
schema() {
return this.$store.state.schema
},
currentTableName() {
return this.$store.state.currentTableName
},
isMediaColumn() {
return this.schema.media_columns.includes(this.fieldName)
}
},
methods: {
updateArray($event, index) {
updateArray($event, index: number) {
this.$set(this.internalArray, index, $event.target.value)
this.$emit("updateArray", this.internalArray)
},
addArrayElement() {
this.internalArray = [...this.internalArray, ""]
this.$emit("updateArray", this.internalArray)
},
removeArrayElement(index) {
removeArrayElement(index: number) {
this.$delete(this.internalArray, index)
this.$emit("updateArray", this.internalArray)
},
showMedia(index: number) {
const mediaViewerConfig: MediaViewerConfig = {
fileKey: this.internalArray[index],
columnName: this.fieldName,
tableName: this.currentTableName
}
this.mediaViewerConfig = mediaViewerConfig
this.showMediaViewer = true
}
},
watch: {
Expand All @@ -60,7 +118,7 @@ export default {
mounted() {
this.internalArray = [...this.array]
}
}
})
</script>

<style scoped lang="less">
Expand All @@ -77,6 +135,10 @@ ul.array_items {

a {
text-decoration: none;

&.add {
font-size: 0.9em;
}
}

input {
Expand Down
Loading