From c5bb49967393ecde96d42f08cde0943f50dffb35 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Thu, 27 Jun 2024 14:55:34 +0100 Subject: [PATCH 1/8] Add Feedback model --- mod_app/models/__init__.py | 2 ++ mod_app/models/feedback_model.py | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 mod_app/models/feedback_model.py diff --git a/mod_app/models/__init__.py b/mod_app/models/__init__.py index 485cc488..c9ed884d 100644 --- a/mod_app/models/__init__.py +++ b/mod_app/models/__init__.py @@ -1,6 +1,7 @@ from .film_model import Film from .bibliography_model import BibliographyItem from .project_note_model import ProjectNote +from .feedback_model import Feedback from .support_models import ( BaseLinkModel, FileLink, @@ -44,4 +45,5 @@ "OtherLink", "Video", "ProjectNote", + "Feedback", ] diff --git a/mod_app/models/feedback_model.py b/mod_app/models/feedback_model.py new file mode 100644 index 00000000..a63c7369 --- /dev/null +++ b/mod_app/models/feedback_model.py @@ -0,0 +1,33 @@ +from ckeditor_uploader.fields import RichTextUploadingField +from django.db import models + +from .bibliography_model import BibliographyItem +from ..utils.extract_citations import update_bibliography + + +class Feedback(models.Model): + class Meta: + verbose_name = "Feedback" + + def __str__(self): + return self.title + + title = models.CharField(max_length=255, null=False) + + content = RichTextUploadingField( + null=True, + blank=True, + help_text="Mentions are available here.", + ) + + bibliography = models.ManyToManyField( + BibliographyItem, + blank=True, + related_name="feedback", + 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) From cf6935e6732e585daad2651ba78cd4eba8300dad Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Thu, 27 Jun 2024 14:59:06 +0100 Subject: [PATCH 2/8] Add migrations for Feedback model Migrations for 'mod_app': mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py - Alter field full_citation on bibliographyitem - Alter field short_citation on bibliographyitem - Alter field format_type on film - Alter field bibliography on projectnote - Create model Feedback --- ...bibliographyitem_full_citation_and_more.py | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py diff --git a/mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py b/mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py new file mode 100644 index 00000000..e29e6c56 --- /dev/null +++ b/mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py @@ -0,0 +1,90 @@ +# Generated by Django 4.2.5 on 2024-06-27 13:55 + +import ckeditor.fields +import ckeditor_uploader.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("mod_app", "0022_bibliographyitem_annotation"), + ] + + operations = [ + migrations.AlterField( + model_name="bibliographyitem", + name="full_citation", + field=ckeditor.fields.RichTextField( + help_text="Please use Harvard reference list style. Examples: Author surname, initial. (year). 'Title of article/book/website/photograph'. Available at: URL or DOI where applicable (date accessed). Please note that the website or photo title should be italicised. For more detailed information and examples visit: https://www5.open.ac.uk/library/referencing-and-plagiarism/quick-guide-to-harvard-referencing-cite-them-right", + null=True, + ), + ), + migrations.AlterField( + model_name="bibliographyitem", + name="short_citation", + field=models.CharField( + help_text="Please use Harvard in-text citation style. Examples: (Author surname, year), or in the case of up to 3 authors: (Author 1 surname, Author 2 surname, Author 3 surname, year), or in the case or more than 3 authors: (Author 1 surname, et al., year) ", + max_length=200, + null=True, + ), + ), + migrations.AlterField( + model_name="film", + name="format_type", + field=models.CharField( + choices=[ + ("16", "16 mm"), + ("70", "70 mm"), + ("other", "Other"), + ("9.5", "9.5 mm"), + ("35", "35 mm"), + ], + default="35", + max_length=5, + verbose_name="format", + ), + ), + migrations.AlterField( + model_name="projectnote", + name="bibliography", + field=models.ManyToManyField( + blank=True, + help_text="This field updates on save, and some items may not be visible immediately", + related_name="project_notes", + to="mod_app.bibliographyitem", + ), + ), + migrations.CreateModel( + name="Feedback", + 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="feedback", + to="mod_app.bibliographyitem", + ), + ), + ], + options={ + "verbose_name": "Feedback", + }, + ), + ] From daa6a0d114ba1b3a1b934f8367752f738265bf8f Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Thu, 27 Jun 2024 14:59:36 +0100 Subject: [PATCH 3/8] Add Feedback model to admin view --- dashboard.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dashboard.py b/dashboard.py index 10fd906c..ec9aff4b 100644 --- a/dashboard.py +++ b/dashboard.py @@ -53,6 +53,7 @@ def init_with_context(self, context): "mod_app.models.teaching_analysis_models.*", "mod_app.models.bibliography_model.*", "mod_app.models.project_note_model.ProjectNote", + "mod_app.models.feedback_model.Feedback", ), ), modules.ModelList( From 434aaa2e4001666616646bfb4fc849c637765252 Mon Sep 17 00:00:00 2001 From: acholyn Date: Thu, 27 Jun 2024 15:39:18 +0100 Subject: [PATCH 4/8] fixing project note bib related name --- mod_app/models/project_note_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod_app/models/project_note_model.py b/mod_app/models/project_note_model.py index d5eaa152..12369714 100644 --- a/mod_app/models/project_note_model.py +++ b/mod_app/models/project_note_model.py @@ -23,7 +23,7 @@ def __str__(self): bibliography = models.ManyToManyField( BibliographyItem, blank=True, - related_name="project_notes", + related_name="project_note", help_text="This field updates on save, and some items may not be visible immediately", ) From 7cc1ee78a2c777a27a0ac3b6d43496ce2c0e4447 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Thu, 27 Jun 2024 15:45:03 +0100 Subject: [PATCH 5/8] Remove unnecessary alteration for projectnote related_name --- ...23_alter_bibliographyitem_full_citation_and_more.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py b/mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py index e29e6c56..4b74779f 100644 --- a/mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py +++ b/mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py @@ -44,16 +44,6 @@ class Migration(migrations.Migration): verbose_name="format", ), ), - migrations.AlterField( - model_name="projectnote", - name="bibliography", - field=models.ManyToManyField( - blank=True, - help_text="This field updates on save, and some items may not be visible immediately", - related_name="project_notes", - to="mod_app.bibliographyitem", - ), - ), migrations.CreateModel( name="Feedback", fields=[ From 1b990b1a2c8f47d7dc11b404643d64e7bbe0d095 Mon Sep 17 00:00:00 2001 From: acholyn Date: Thu, 27 Jun 2024 15:48:31 +0100 Subject: [PATCH 6/8] fixing note admin search fields --- mod_app/admin/note_admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod_app/admin/note_admin.py b/mod_app/admin/note_admin.py index e0734939..4e403907 100644 --- a/mod_app/admin/note_admin.py +++ b/mod_app/admin/note_admin.py @@ -11,7 +11,7 @@ class ProjectNoteAdmin(admin.ModelAdmin): class Media: js = ("admin/js/mentionsPluginConfig.js",) - search_fields = ["description", "url"] + search_fields = ["title"] list_display = ["title", "safe_content"] readonly_fields = ("bibliography",) From f7f12def4e9ff6ad3be8617ca1f74212dc324063 Mon Sep 17 00:00:00 2001 From: acholyn Date: Mon, 1 Jul 2024 12:29:56 +0100 Subject: [PATCH 7/8] fixing migration name --- mod_app/migrations/0023_add_feedback_model.py | 46 +++++++++++ ...bibliographyitem_full_citation_and_more.py | 80 ------------------- 2 files changed, 46 insertions(+), 80 deletions(-) create mode 100644 mod_app/migrations/0023_add_feedback_model.py delete mode 100644 mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py diff --git a/mod_app/migrations/0023_add_feedback_model.py b/mod_app/migrations/0023_add_feedback_model.py new file mode 100644 index 00000000..1ef3be63 --- /dev/null +++ b/mod_app/migrations/0023_add_feedback_model.py @@ -0,0 +1,46 @@ +# Generated by Django 4.2.5 on 2024-06-27 13:55 + +import ckeditor_uploader.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("mod_app", "0022_bibliographyitem_annotation"), + ] + + operations = [ + migrations.CreateModel( + name="Feedback", + 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="feedback", + to="mod_app.bibliographyitem", + ), + ), + ], + options={ + "verbose_name": "Feedback", + }, + ), + ] diff --git a/mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py b/mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py deleted file mode 100644 index 4b74779f..00000000 --- a/mod_app/migrations/0023_alter_bibliographyitem_full_citation_and_more.py +++ /dev/null @@ -1,80 +0,0 @@ -# Generated by Django 4.2.5 on 2024-06-27 13:55 - -import ckeditor.fields -import ckeditor_uploader.fields -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("mod_app", "0022_bibliographyitem_annotation"), - ] - - operations = [ - migrations.AlterField( - model_name="bibliographyitem", - name="full_citation", - field=ckeditor.fields.RichTextField( - help_text="Please use Harvard reference list style. Examples: Author surname, initial. (year). 'Title of article/book/website/photograph'. Available at: URL or DOI where applicable (date accessed). Please note that the website or photo title should be italicised. For more detailed information and examples visit: https://www5.open.ac.uk/library/referencing-and-plagiarism/quick-guide-to-harvard-referencing-cite-them-right", - null=True, - ), - ), - migrations.AlterField( - model_name="bibliographyitem", - name="short_citation", - field=models.CharField( - help_text="Please use Harvard in-text citation style. Examples: (Author surname, year), or in the case of up to 3 authors: (Author 1 surname, Author 2 surname, Author 3 surname, year), or in the case or more than 3 authors: (Author 1 surname, et al., year) ", - max_length=200, - null=True, - ), - ), - migrations.AlterField( - model_name="film", - name="format_type", - field=models.CharField( - choices=[ - ("16", "16 mm"), - ("70", "70 mm"), - ("other", "Other"), - ("9.5", "9.5 mm"), - ("35", "35 mm"), - ], - default="35", - max_length=5, - verbose_name="format", - ), - ), - migrations.CreateModel( - name="Feedback", - 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="feedback", - to="mod_app.bibliographyitem", - ), - ), - ], - options={ - "verbose_name": "Feedback", - }, - ), - ] From ac70d23c3d9ceafdfcfffdade83bda80f1246b76 Mon Sep 17 00:00:00 2001 From: acholyn Date: Mon, 1 Jul 2024 12:30:16 +0100 Subject: [PATCH 8/8] adding feedback to admin --- dashboard.py | 2 +- mod_app/admin/__init__.py | 3 ++- mod_app/admin/note_admin.py | 20 +++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/dashboard.py b/dashboard.py index ec9aff4b..24211575 100644 --- a/dashboard.py +++ b/dashboard.py @@ -53,7 +53,6 @@ def init_with_context(self, context): "mod_app.models.teaching_analysis_models.*", "mod_app.models.bibliography_model.*", "mod_app.models.project_note_model.ProjectNote", - "mod_app.models.feedback_model.Feedback", ), ), modules.ModelList( @@ -86,6 +85,7 @@ def init_with_context(self, context): "mod_app.models.support_models.Source", "mod_app.models.support_models.OtherLink", "mod_app.models.support_models.Tag", + "mod_app.models.feedback_model.Feedback", ), ), ], diff --git a/mod_app/admin/__init__.py b/mod_app/admin/__init__.py index b0b2adf6..bbe3a464 100644 --- a/mod_app/admin/__init__.py +++ b/mod_app/admin/__init__.py @@ -30,7 +30,7 @@ PostcardAdmin, TagAdmin, ) -from .note_admin import ProjectNoteAdmin +from .note_admin import ProjectNoteAdmin, FeedbackAdmin __all__ = [ "BibliographyItemAdmin", @@ -66,4 +66,5 @@ "TagAdmin", "CustomUserAdmin", "ProjectNoteAdmin", + "FeedbackAdmin", ] diff --git a/mod_app/admin/note_admin.py b/mod_app/admin/note_admin.py index 4e403907..4c3df069 100644 --- a/mod_app/admin/note_admin.py +++ b/mod_app/admin/note_admin.py @@ -3,7 +3,7 @@ from django.utils.html import format_html -from mod_app.models import ProjectNote +from mod_app.models import ProjectNote, Feedback @admin.register(ProjectNote) @@ -22,3 +22,21 @@ def safe_content(self, obj): safe_content.allow_tags = True safe_content.short_description = "Content" + + +@admin.register(Feedback) +class FeedbackAdmin(admin.ModelAdmin): + class Media: + js = ("admin/js/mentionsPluginConfig.js",) + + search_fields = ["title"] + list_display = ["title", "safe_content"] + readonly_fields = ("bibliography",) + + 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"