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

splitting vwis into vis and written #137

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def init_with_context(self, context):
"mod_app.models.support_models.OtherLink",
"mod_app.models.support_models.Tag",
"mod_app.models.feedback_model.Feedback",
"mod_app.models.visual_written_influences_model.VisualWrittenInfluences",
"mod_app.models.visual_written_influences_model.VisualInfluences",
"mod_app.models.visual_written_influences_model.WrittenInfluences",
),
),
],
Expand Down
18 changes: 15 additions & 3 deletions mod_app/admin/film_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
StillInline,
VideoInline,
)
from mod_app.admin.note_admin import VWIInline
from mod_app.admin.note_admin import VisInline, WritInline
from mod_app.utils.mixins import EmailMixin

from ..models import Analysis, TeachingResources, Film
Expand Down Expand Up @@ -72,7 +72,8 @@ class Media:
inlines = [
FilmAnalysisInline,
TRInline,
VWIInline,
VisInline,
WritInline,
SourceInline,
OtherLinkInline,
VideoInline,
Expand Down Expand Up @@ -210,10 +211,21 @@ def preview_video(self, obj):
None,
{"classes": ("placeholder TeachingResources_films-group",), "fields": ()},
),
(
"Visual & Written Influences",
{"fields": []},
),
(
None,
{
"classes": ("placeholder VisualInfluences_films-group",),
"fields": (),
},
),
(
None,
{
"classes": ("placeholder VisualWrittenInfluences_films-group",),
"classes": ("placeholder WrittenInfluences_films-group",),
"fields": (),
},
),
Expand Down
44 changes: 37 additions & 7 deletions mod_app/admin/note_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.utils.html import format_html


from mod_app.models import ProjectNote, Feedback, VisualWrittenInfluences
from mod_app.models import ProjectNote, Feedback, VisualInfluences, WrittenInfluences
from mod_app.utils.mixins import s3BrowserButtonMixin


Expand Down Expand Up @@ -43,19 +43,49 @@ def safe_content(self, obj):
safe_content.short_description = "Content"


class VWIInline(s3BrowserButtonMixin, admin.TabularInline):
model = VisualWrittenInfluences.films.through
class VisInline(s3BrowserButtonMixin, admin.TabularInline):
model = VisualInfluences.films.through
extra = 1
classes = [
"grp-collapse",
"grp-open",
]
verbose_name = "Visual & Written Influences"
verbose_name_plural = "Visual & Written Influences"
verbose_name = "Visual Influences"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
verbose_name = "Visual Influences"
verbose_name = "Visual Influence"

On the model you've defined verbose name as "Visual Influence" rather than "Visual Influences".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep, deliberate, since they're separate now I thought they might end up making new entries for each

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

worst case I'm wrong and we change it back

verbose_name_plural = "Visual Influences"


@admin.register(VisualWrittenInfluences)
class VWIAdmin(s3BrowserButtonMixin, admin.ModelAdmin):
class WritInline(s3BrowserButtonMixin, admin.TabularInline):
model = WrittenInfluences.films.through
extra = 1
classes = [
"grp-collapse",
"grp-open",
]
verbose_name = "Written Influences"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
verbose_name = "Written Influences"
verbose_name = "Written Influence"

As above. Unless this is deliberate?

verbose_name_plural = "Written Influences"


@admin.register(VisualInfluences)
class VisualInfluencesAdmin(s3BrowserButtonMixin, admin.ModelAdmin):
class Media:
js = ("admin/js/mentionsPluginConfig.js",)

search_fields = ["title"]
list_display = ["title", "safe_content"]
readonly_fields = ("bibliography",)
filter_horizontal = ("films",)

def safe_content(self, obj):
truncated_content = truncatechars_html(obj.content, 200)
modified_content = truncated_content.replace("{", "(").replace("}", ")")
return format_html(modified_content)

safe_content.allow_tags = True
safe_content.short_description = "Content"


@admin.register(WrittenInfluences)
class WrittenInfluencesAdmin(s3BrowserButtonMixin, admin.ModelAdmin):
class Media:
js = ("admin/js/mentionsPluginConfig.js",)

Expand Down
96 changes: 96 additions & 0 deletions mod_app/migrations/0031_splitting_vwis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Generated by Django 4.2.5 on 2025-01-08 13:14

import ckeditor_uploader.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("mod_app", "0030_add_films_to_vwi"),
]

operations = [
migrations.CreateModel(
name="VisualInfluences",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=255)),
(
"content",
ckeditor_uploader.fields.RichTextUploadingField(
blank=True, help_text="Mentions are available here.", null=True
),
),
(
"bibliography",
models.ManyToManyField(
blank=True,
help_text="This field updates on save, and some items may not be visible immediately",
related_name="visual_influences",
to="mod_app.bibliographyitem",
),
),
(
"films",
models.ManyToManyField(
blank=True, related_name="visual_influences", to="mod_app.film"
),
),
],
options={
"verbose_name": "Visual Influence",
"verbose_name_plural": "Visual Influences",
},
),
migrations.CreateModel(
name="WrittenInfluences",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=255)),
(
"content",
ckeditor_uploader.fields.RichTextUploadingField(
blank=True, help_text="Mentions are available here.", null=True
),
),
(
"bibliography",
models.ManyToManyField(
blank=True,
help_text="This field updates on save, and some items may not be visible immediately",
related_name="written_influences",
to="mod_app.bibliographyitem",
),
),
(
"films",
models.ManyToManyField(
blank=True, related_name="written_influences", to="mod_app.film"
),
),
],
options={
"verbose_name": "Written Influence",
"verbose_name_plural": "Written Influences",
},
),
migrations.DeleteModel(
name="VisualWrittenInfluences",
),
]
5 changes: 3 additions & 2 deletions mod_app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Analysis,
TeachingResources,
)
from .visual_written_influences_model import VisualWrittenInfluences
from .visual_written_influences_model import VisualInfluences, WrittenInfluences

__all__ = [
"Analysis",
Expand All @@ -47,5 +47,6 @@
"Video",
"ProjectNote",
"Feedback",
"VisualWrittenInfluences",
"VisualInfluences",
"WrittenInfluences",
]
42 changes: 37 additions & 5 deletions mod_app/models/visual_written_influences_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
from ..utils.extract_citations import update_bibliography


class VisualWrittenInfluences(models.Model):
class VisualInfluences(models.Model):
class Meta:
verbose_name = "Visual and Written Influences"
verbose_name_plural = "Visual and Written Influences"
verbose_name = "Visual Influence"
verbose_name_plural = "Visual Influences"

def __str__(self):
return self.title

title = models.CharField(max_length=255, null=False)
films = models.ManyToManyField("Film", related_name="vwis", blank=True)
films = models.ManyToManyField("Film", related_name="visual_influences", blank=True)

content = RichTextUploadingField(
null=True,
Expand All @@ -25,7 +25,39 @@ def __str__(self):
bibliography = models.ManyToManyField(
BibliographyItem,
blank=True,
related_name="vwis",
related_name="visual_influences",
help_text="This field updates on save, and some items may not be visible immediately",
)

def save(self, *args, **kwargs):
super().save(*args, **kwargs)

update_bibliography(self, [self.content])


class WrittenInfluences(models.Model):
class Meta:
verbose_name = "Written Influence"
verbose_name_plural = "Written Influences"

def __str__(self):
return self.title

title = models.CharField(max_length=255, null=False)
films = models.ManyToManyField(
"Film", related_name="written_influences", blank=True
)

content = RichTextUploadingField(
null=True,
blank=True,
help_text="Mentions are available here.",
)

bibliography = models.ManyToManyField(
BibliographyItem,
blank=True,
related_name="written_influences",
help_text="This field updates on save, and some items may not be visible immediately",
)

Expand Down
Loading