Skip to content

Commit

Permalink
Merge pull request #137 from UCL-ARC/split-vwi
Browse files Browse the repository at this point in the history
splitting vwis into vis and written
  • Loading branch information
acholyn authored Jan 14, 2025
2 parents d088c26 + fab1dfd commit 4742d33
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 18 deletions.
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"
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"
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

0 comments on commit 4742d33

Please sign in to comment.