This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Implement file upload and display #53
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
20e0bee
Use django's FileField for file handling
Rubikium b588846
Show files in relevant polls and cms pages
Rubikium 5ce7de4
Add AWS S3 support
Rubikium bf796e6
Add TODOs on html templates for data render
Rubikium f962c6d
Fix __all__ format for utils import
Rubikium File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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
68 changes: 68 additions & 0 deletions
68
django_material_demo/polls/migrations/0012_add_temp_fields.py
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,68 @@ | ||
# Generated by Django 4.1 on 2022-09-22 11:17 | ||
|
||
from django.core.files.storage import get_storage_class | ||
from django.db import migrations, models | ||
|
||
|
||
STORAGE = get_storage_class()() | ||
# Should match with same variable in migration 0014 | ||
DUMMY_FILE_NAME = 'DUMMY_FILE_NAME' | ||
|
||
|
||
def copy_file_fk(apps, schema_editor): | ||
question_model = apps.get_model('polls', 'Question') | ||
attachment_model = apps.get_model('polls', 'Attachment') | ||
for question in question_model.objects.all(): | ||
if question.thumbnail: | ||
question.thumbnail_copy = question.thumbnail | ||
question.save() | ||
for attachment in attachment_model.objects.all(): | ||
attachment.file_copy = attachment.file | ||
attachment.save() | ||
pass | ||
|
||
|
||
def delete_dummy_file(name): | ||
STORAGE.delete(name) | ||
|
||
|
||
def restore_file_fk(apps, schema_editor): | ||
file_model = apps.get_model('polls', 'File') | ||
question_model = apps.get_model('polls', 'Question') | ||
attachment_model = apps.get_model('polls', 'Attachment') | ||
|
||
for question in question_model.objects.all(): | ||
delete_dummy_file(str(question.thumbnail_copy.pk)) | ||
if question.thumbnail_copy.file_name == DUMMY_FILE_NAME: | ||
question.thumbnail = None | ||
question.thumbnail_copy = None | ||
else: | ||
question.thumbnail = question.thumbnail_copy | ||
question.save() | ||
for attachment in attachment_model.objects.all(): | ||
delete_dummy_file(str(attachment.file_copy.pk)) | ||
attachment.file = attachment.file_copy | ||
attachment.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('polls', '0011_alter_attachment_options_alter_choice_options_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='attachment', | ||
name='file_copy', | ||
field=models.ForeignKey( | ||
'polls.file', on_delete=models.DO_NOTHING, null=True, blank=True), | ||
), | ||
migrations.AddField( | ||
model_name='question', | ||
name='thumbnail_copy', | ||
field=models.ForeignKey( | ||
'polls.file', on_delete=models.DO_NOTHING, null=True, blank=True), | ||
), | ||
migrations.RunPython(copy_file_fk, restore_file_fk), | ||
] |
23 changes: 23 additions & 0 deletions
23
django_material_demo/polls/migrations/0013_alter_attachment_file_alter_question_thumbnail.py
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,23 @@ | ||
# Generated by Django 4.1 on 2022-09-23 09:52 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('polls', '0012_add_temp_fields'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='attachment', | ||
name='file', | ||
field=models.FileField(blank=True, null=True, upload_to=''), | ||
), | ||
migrations.AlterField( | ||
model_name='question', | ||
name='thumbnail', | ||
field=models.FileField(blank=True, null=True, upload_to=''), | ||
), | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls render it in a separate html template file instead of inline html in python.