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

Update source file details on file change #1760

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
7 changes: 2 additions & 5 deletions peachjam/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,6 @@ def clean_content_html(self):
return self.instance.content_html
return self.cleaned_data["content_html"]

def _save_m2m(self):
super()._save_m2m()
# update document text
self.instance.update_text_content()

Comment on lines -325 to -329
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@longhotsummer this is getting called before the source file is saved and updated so we can move it to after the save_related method


class AttachedFilesInline(BaseAttachmentFileInline):
model = AttachedFiles
Expand Down Expand Up @@ -504,7 +499,9 @@ def save_related(self, request, form, formsets, change):
cp.queue_re_extract_citations(form.instance.date)

super().save_related(request, form, formsets, change)

form.instance.save()
form.instance.update_text_content()

def get_urls(self):
return [
Expand Down
11 changes: 4 additions & 7 deletions peachjam/models/core_document_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,13 +711,10 @@ class Meta:
abstract = True

def save(self, *args, **kwargs):
if not self.filename:
self.filename = self.file.name
if not self.size:
self.size = self.file.size
if not self.mimetype:
self.file.seek(0)
self.mimetype = magic.from_buffer(self.file.read(), mime=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this prevents us from updating the source file details

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This messes with setting these fields explicitly. Instead, clear them in the admin form so that they get reset here.

self.filename = self.file.name
self.size = self.file.size
self.file.seek(0)
self.mimetype = magic.from_buffer(self.file.read(), mime=True)
return super().save(*args, **kwargs)


Expand Down
Loading