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

Add feedback model #111

Merged
merged 9 commits into from
Jul 1, 2024
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
1 change: 1 addition & 0 deletions dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,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",
),
),
],
Expand Down
3 changes: 2 additions & 1 deletion mod_app/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
PostcardAdmin,
TagAdmin,
)
from .note_admin import ProjectNoteAdmin
from .note_admin import ProjectNoteAdmin, FeedbackAdmin

__all__ = [
"BibliographyItemAdmin",
Expand Down Expand Up @@ -66,4 +66,5 @@
"TagAdmin",
"CustomUserAdmin",
"ProjectNoteAdmin",
"FeedbackAdmin",
]
22 changes: 20 additions & 2 deletions mod_app/admin/note_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@
from django.utils.html import format_html


from mod_app.models import ProjectNote
from mod_app.models import ProjectNote, Feedback


@admin.register(ProjectNote)
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",)

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(Feedback)
class FeedbackAdmin(admin.ModelAdmin):
class Media:
js = ("admin/js/mentionsPluginConfig.js",)

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

Expand Down
46 changes: 46 additions & 0 deletions mod_app/migrations/0023_add_feedback_model.py
Original file line number Diff line number Diff line change
@@ -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",
},
),
]
2 changes: 2 additions & 0 deletions mod_app/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -44,4 +45,5 @@
"OtherLink",
"Video",
"ProjectNote",
"Feedback",
]
33 changes: 33 additions & 0 deletions mod_app/models/feedback_model.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion mod_app/models/project_note_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
Loading