Skip to content

Commit d800701

Browse files
authored
Merge pull request #122 from UCL-ARC/fix/url_and_bib
Fix/url and bib
2 parents a0f51bc + d2b89ec commit d800701

13 files changed

+232
-25
lines changed

mod_app/admin/bibliography_admin.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@ class Meta:
1818
@admin.register(BibliographyItem)
1919
class BibliographyItemAdmin(admin.ModelAdmin):
2020
model = BibliographyItem
21-
list_display = ["safe_citation"]
21+
list_display = ["safe_citation", "safe_annotation"]
2222
form = BIAdminForm
23+
search_fields = ["full_citation", "annotation"]
2324

2425
def safe_citation(self, obj):
2526
return format_html(obj.full_citation)
2627

28+
def safe_annotation(self, obj):
29+
if obj.annotation is not None:
30+
return format_html(obj.annotation)
31+
else:
32+
return ""
33+
2734
safe_citation.allow_tags = True
2835
safe_citation.short_description = "Full Citation"
2936
safe_citation.admin_order_field = "full_citation"
37+
safe_annotation.allow_tags = True
38+
safe_annotation.short_description = "Annotations"
39+
safe_annotation.admin_order_field = "annotation"

mod_app/admin/film_admin.py

+30-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.db import models
44
from django.template.defaultfilters import truncatechars_html
55
from django.utils.html import format_html
6+
import html
67

78
from mod_app.admin.link_admin import (
89
DrawingInline,
@@ -29,6 +30,8 @@ class FilmAnalysisInline(admin.TabularInline):
2930
"grp-collapse",
3031
"grp-open",
3132
]
33+
verbose_name = "Analysis"
34+
verbose_name_plural = "Analyses"
3235

3336

3437
class TRInline(admin.TabularInline):
@@ -38,6 +41,8 @@ class TRInline(admin.TabularInline):
3841
"grp-collapse",
3942
"grp-open",
4043
]
44+
verbose_name = "Teaching Resources"
45+
verbose_name_plural = "Teaching Resources"
4146

4247

4348
@admin.register(Film)
@@ -49,7 +54,13 @@ class Media:
4954
js = ("admin/js/mentionsPluginConfig.js",)
5055

5156
autocomplete_fields = ["genre"]
52-
search_fields = ["title", "alt_titles"]
57+
search_fields = [
58+
"title",
59+
"alt_titles",
60+
"production_company",
61+
"production_country",
62+
"release_date",
63+
]
5364
formfield_overrides = {
5465
models.TextField: {
5566
"widget": CKEditorWidget(),
@@ -112,18 +123,30 @@ def safe_temporary_images(self, obj):
112123
safe_temporary_images.allow_tags = True
113124
safe_temporary_images.short_description = "List Images"
114125

126+
def safe_bibliography(self, obj):
127+
bib_items = obj.bibliography.all()
128+
formatted_items = [
129+
format_html(
130+
"<li>{}</li>", format_html(html.unescape(bib_item.full_citation))
131+
)
132+
for bib_item in bib_items
133+
]
134+
return format_html("<ul>{}</ul>", format_html("".join(formatted_items)))
135+
136+
safe_bibliography.short_description = "Bibliography"
137+
safe_bibliography.allow_tags = True
138+
115139
def preview_video(self, obj):
116140
if obj.videos.first():
117-
# format for working with mediacentral embeds
141+
# format for working with mediacentral embeds and youtube embeds
118142
return format_html(
119143
'<div"><iframe src="{}" frameborder="0" scrolling="no" allowfullscreen></iframe></div>',
120144
obj.videos.first(),
121145
)
122-
# previously tried to use youtube but that seems to be more tricky than expected and may not be used
123146
else:
124147
return "-"
125148

126-
readonly_fields = ("bibliography",)
149+
readonly_fields = ("safe_bibliography",)
127150
fieldsets = (
128151
(
129152
"Main Information (Filmic Section)",
@@ -140,7 +163,7 @@ def preview_video(self, obj):
140163
),
141164
},
142165
),
143-
(None, {"classes": ("placeholder sources-group",), "fields": ()}),
166+
(None, {"classes": ("placeholder Source_film-group",), "fields": ()}),
144167
(None, {"classes": ("placeholder videos-group",), "fields": ()}),
145168
(
146169
"Technical Section",
@@ -188,13 +211,14 @@ def preview_video(self, obj):
188211
"comments",
189212
"temporary_images",
190213
),
214+
"description": "Mentions are available here and will contibute to the bibliography.",
191215
},
192216
),
193217
(
194218
"Bibliography",
195219
{
196220
"classes": ("grp-collapse",),
197-
"fields": ("bibliography",),
221+
"fields": ("safe_bibliography",),
198222
"description": "Note: This section updates on save, and some items may not be visible immediately.",
199223
},
200224
),

mod_app/admin/link_admin.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66

77
class SourceInline(PreviewMixin, admin.TabularInline):
8-
model = Source
8+
model = Film.sources.through
99
extra = 1
1010
classes = [
11-
"inline-inline",
1211
"grp-collapse",
1312
"grp-closed",
1413
]
14+
verbose_name = "Source"
15+
verbose_name_plural = "Sources"
1516

1617

1718
class VideoInline(PreviewMixin, admin.TabularInline):
@@ -123,9 +124,15 @@ class VideoAdmin(PreviewMixin, admin.ModelAdmin):
123124

124125
@admin.register(Source)
125126
class SourceAdmin(PreviewMixin, admin.ModelAdmin):
126-
search_fields = ["description", "url"]
127+
def list_films(self, obj):
128+
return ", ".join([film.title for film in obj.film.all()])
129+
130+
list_films.short_description = "Films"
131+
132+
search_fields = ["description", "url", "film__title"]
133+
filter_horizontal = ("film",)
127134
exclude = ["is_source"]
128-
list_display = ["description", "film", "url", "preview"]
135+
list_display = ["description", "list_films", "url", "preview"]
129136

130137

131138
@admin.register(OtherLink)

mod_app/admin/teaching_analysis_admin.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.contrib import admin
44
from django.template.defaultfilters import truncatechars_html
55
from django.utils.html import format_html
6+
import html
67

78
from ..models import Analysis, TeachingResources
89

@@ -23,6 +24,8 @@ class TRAnalysisInline(admin.TabularInline):
2324
"grp-collapse",
2425
"grp-open",
2526
]
27+
verbose_name = "Analysis"
28+
verbose_name_plural = "Analyses"
2629

2730

2831
class TRAdminForm(forms.ModelForm):
@@ -44,7 +47,8 @@ class Media:
4447

4548
form = AnalysisAdminForm
4649
autocomplete_fields = ["films", "topics", "tags", "teaching_resources"]
47-
readonly_fields = ("bibliography",)
50+
readonly_fields = ("safe_bibliography",)
51+
exclude = ["bibliography"]
4852
list_display = [
4953
"dynamic_title",
5054
"related_films",
@@ -85,6 +89,19 @@ def safe_content(self, obj):
8589
safe_content.allow_tags = True
8690
safe_content.short_description = "Content"
8791

92+
def safe_bibliography(self, obj):
93+
bib_items = obj.bibliography.all()
94+
formatted_items = [
95+
format_html(
96+
"<li>{}</li>", format_html(html.unescape(bib_item.full_citation))
97+
)
98+
for bib_item in bib_items
99+
]
100+
return format_html("<ul>{}</ul>", format_html("".join(formatted_items)))
101+
102+
safe_bibliography.short_description = "Bibliography"
103+
safe_bibliography.allow_tags = True
104+
88105

89106
@admin.register(TeachingResources)
90107
class TeachingResourcesAdmin(AnalysisAdmin):
@@ -97,7 +114,8 @@ class Media:
97114
form = TRAdminForm
98115
inlines = [TRAnalysisInline]
99116
autocomplete_fields = ["films", "topics", "tags", "clips"]
100-
readonly_fields = ("bibliography",)
117+
readonly_fields = ("safe_bibliography",)
118+
exclude = ["bibliography"]
101119

102120
list_display = [
103121
"dynamic_title",
@@ -106,3 +124,16 @@ class Media:
106124
"list_tags",
107125
]
108126
search_fields = ["title", "tags", "topics"]
127+
128+
def safe_bibliography(self, obj):
129+
bib_items = obj.bibliography.all()
130+
formatted_items = [
131+
format_html(
132+
"<li>{}</li>", format_html(html.unescape(bib_item.full_citation))
133+
)
134+
for bib_item in bib_items
135+
]
136+
return format_html("<ul>{}</ul>", format_html("".join(formatted_items)))
137+
138+
safe_bibliography.short_description = "Bibliography"
139+
safe_bibliography.allow_tags = True
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Generated by Django 4.2.5 on 2024-10-04 11:35
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("mod_app", "0024_fix_migrations"),
9+
]
10+
11+
operations = [
12+
migrations.AlterField(
13+
model_name="drawing",
14+
name="url",
15+
field=models.URLField(
16+
blank=True,
17+
help_text="url to the item you'd like to link",
18+
max_length=500,
19+
),
20+
),
21+
migrations.AlterField(
22+
model_name="otherlink",
23+
name="url",
24+
field=models.URLField(
25+
blank=True,
26+
help_text="url to the item you'd like to link",
27+
max_length=500,
28+
),
29+
),
30+
migrations.AlterField(
31+
model_name="postcard",
32+
name="url",
33+
field=models.URLField(
34+
blank=True,
35+
help_text="url to the item you'd like to link",
36+
max_length=500,
37+
),
38+
),
39+
migrations.AlterField(
40+
model_name="poster",
41+
name="url",
42+
field=models.URLField(
43+
blank=True,
44+
help_text="url to the item you'd like to link",
45+
max_length=500,
46+
),
47+
),
48+
migrations.AlterField(
49+
model_name="pressbook",
50+
name="url",
51+
field=models.URLField(
52+
blank=True,
53+
help_text="url to the item you'd like to link",
54+
max_length=500,
55+
),
56+
),
57+
migrations.AlterField(
58+
model_name="programme",
59+
name="url",
60+
field=models.URLField(
61+
blank=True,
62+
help_text="url to the item you'd like to link",
63+
max_length=500,
64+
),
65+
),
66+
migrations.AlterField(
67+
model_name="publicity",
68+
name="url",
69+
field=models.URLField(
70+
blank=True,
71+
help_text="url to the item you'd like to link",
72+
max_length=500,
73+
),
74+
),
75+
migrations.AlterField(
76+
model_name="script",
77+
name="url",
78+
field=models.URLField(
79+
blank=True,
80+
help_text="url to the item you'd like to link",
81+
max_length=500,
82+
),
83+
),
84+
migrations.RemoveField(
85+
model_name="source",
86+
name="film",
87+
),
88+
migrations.AlterField(
89+
model_name="source",
90+
name="url",
91+
field=models.URLField(
92+
blank=True,
93+
help_text="url to the item you'd like to link",
94+
max_length=500,
95+
),
96+
),
97+
migrations.AlterField(
98+
model_name="still",
99+
name="url",
100+
field=models.URLField(
101+
blank=True,
102+
help_text="url to the item you'd like to link",
103+
max_length=500,
104+
),
105+
),
106+
migrations.AlterField(
107+
model_name="video",
108+
name="url",
109+
field=models.URLField(
110+
blank=True,
111+
help_text="url to the item you'd like to link",
112+
max_length=500,
113+
),
114+
),
115+
migrations.AddField(
116+
model_name="source",
117+
name="film",
118+
field=models.ManyToManyField(
119+
blank=True, related_name="sources", to="mod_app.film"
120+
),
121+
),
122+
]

mod_app/models/feedback_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def __str__(self):
3030
def save(self, *args, **kwargs):
3131
super().save(*args, **kwargs)
3232

33-
update_bibliography(self, self.content)
33+
update_bibliography(self, [self.content])

mod_app/models/film_model.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,6 @@ def clean(self, *args, **kwargs):
148148

149149
def save(self, *args, **kwargs):
150150
super().save(*args, **kwargs)
151+
fields = [self.print_comments, self.comments, self.temporary_images]
151152

152-
update_bibliography(self, self.print_comments)
153+
update_bibliography(self, fields)

mod_app/models/project_note_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def __str__(self):
3030
def save(self, *args, **kwargs):
3131
super().save(*args, **kwargs)
3232

33-
update_bibliography(self, self.content)
33+
update_bibliography(self, [self.content])

mod_app/models/support_models.py

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def __str__(self):
2222
url = models.URLField(
2323
blank=True,
2424
help_text="url to the item you'd like to link",
25+
max_length=500,
2526
)
2627
description = models.CharField(
2728
max_length=250,
@@ -43,6 +44,8 @@ class Source(BaseLinkModel):
4344
class Meta:
4445
verbose_name = "Source"
4546

47+
film = models.ManyToManyField("Film", blank=True, related_name="sources")
48+
4649

4750
class FileLink(BaseLinkModel):
4851
class Meta:

0 commit comments

Comments
 (0)