Skip to content

Commit

Permalink
CONCD-654 Merge Feature branch into Main (#2276)
Browse files Browse the repository at this point in the history
* CONCD-488 Delete Quick Tips module, but keep Simple Content Blocks (for now)

* CONCD-492 Create database tables for Tutorial slides (Requires DB Migration) (#2086)

* CONCD-492 Create database tables for Tutorial slides (WiP)

* CONCD-492 I don't actually want this to display as 'Tutorial Cards' in the admin

* CONCD-492 Card display, sort order

* CONCD-488 Delete Quick Tips module in Django admin (#2084)

* CONCD-488 Delete Quick Tips module in Django admin

* CONCD-488 database change (Requires Migration)

* CONCD-488 no idea where auth 0013 came from

* CONCD-491 post_save signal handler (#2094)

* CONCD-491 post_save signal handler

* CONCD-491 trying to resolve a merge conflict

* CONCD-531 conflicting migrations (#2105)

* CONCD-482 Build Tutorial popup and cards navigation (WiP)

* CONCD-482 Modal dialog (WiP)

* CONCD-480 Create manual link for opening tutorial (#2119)

* CONCD-480 Create manual link for opening tutorial

* CONCD-480 toggle modal

* CONCD-482 dialog layout (WiP)

* CONCD-482 Work in Progress

* CONCD-482 Bootstrap carousel

* CONCD-482 Carousel styling (WiP)

* CONCD-482 header, close button

* CONCD-482 style fixes

* CONCD-482 card images

* CONCD-482 The first card should not have a Back button

* CONCD-482 Borders

* CONCD-480 Link text should be bolded, cursor should change to a hand when hovering over the link.

* CONCD-482 Change Meta options on Card (ordering) and Tutorial Card (verbose_name_plural)

* CONCD-482 field order

* CONCD-480 Link should be underlined (#2134)

* CONCD-530 Add rich text editor for django admin fields (WiP)

* CONCD-530 added django-tinymce to Pipfile.lock

* CONCD-530 all of Pipfile.lock needs to be updated (instead of just adding a single entry)

* CONCD-530 still getting the Pipfile.lock error

* CONCD-483 Implement tutorial popup rules based on session activity and user type (WiP)

* CONCD-483 show modal

* CONCD-483 if user is not logged in, remove key from local storage

* CONCD-483 if an anonymouse user navigates to another page in the site and comes back, the popup should automatically open again

* CONCD-483 moved session code to base template

* CONCD-530 numlist, searchreplace, wordcount

* CONCD-483 fixed an issue (#2155)

* CONCD-483 fixed an issue where, if a user navigated to an asset, tutorial was not popping up

* CONCD-483 don't set the key and then immediately clear it

* CONCD-576 When adding cards to a family, display card title (rather than the ID/ pk) (#2184)

* CONCD-576 When adding cards to a family, display card title (WiP)

* CONCD-576 need to actually include the js

* CONCD-576 actually got it working, although the color is off

* CONCD-276 changed the text to a link

* CONCD-576 added unit test for new view

* CONCD-590 database migrations (#2186)

* CONCD-590 migration for class meta (card, tutorialcard)

* CONCD-590 trying to resolve an error in the feature branch

* CONCD-590 cherry-picked a commit with missing libraries (#2194)

Co-authored-by: joshuastegmaier <jstegmaier@loc.gov>

* CONCD-576 trigger when popup is dismissed (#2197)

* CONCD-629 Create data model for How To Guide (#2208)

* CONCD-630 Create database tables for How To Guide (#2218)

* CONCD-630 Create database tables for How To Guide

* CONCD-630 body field should support rich text

* CONCD-630 re-numbered migration

* CONCD-588 Add card display heading, create date, and campaign fields (#2224)

* CONCD-588 Add card display heading, create date, and campaign fields (WiP)

* CONCD-588 add create date as sortable field

* CONCD-588 add a campaign filter (WiP)

* CONCD-588 implement campaign filter

* CONCD-588 I don't believe that we should actually add a new campaign field

* CONCD-480, 482, 483 redoing a bunch of changes that had gotten stomped by a bad merge

* CONCD-588 use Card.display_heading

* Initial implementation of maintenance mode (#2227) (#2231)

* Initial implementation of maintenance mode. Updated pre-commit-config to allow 256k files. Rolled back stylelint packages so they actually work.

* Fixed typo in 503 error page

Co-authored-by: Josh Stegmaier <104993387+joshuastegmaier@users.noreply.github.com>

* CONCD-592 (#2233)

* Bump jinja2 from 3.1.2 to 3.1.3 (#2229)

Bumps [jinja2](https://github.com/pallets/jinja) from 3.1.2 to 3.1.3.
- [Release notes](https://github.com/pallets/jinja/releases)
- [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst)
- [Commits](pallets/jinja@3.1.2...3.1.3)

---
updated-dependencies:
- dependency-name: jinja2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* CONCD-646 Simple unit test (#2232)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* CONCD-650 Build front end for How To Guide (#2235)

* CONCD-650 Build front end for How To Guide (WiP)

* CONCD-650 I'm struggling to get this to work using bootstrap, so for now I'm going to implement it using only html and css

* CONCD-650 just barely started working on the actual layout

* CONCD-650 misc style fixes

* CONCD-650 implementing the various guides as custom panes

* CONCD-650 I think that it actually makes more sense to organize these as a carousel

* CONCD-650 fixed the issue with the 'hamburger' icon not being rendered correctly

* CONCD-650 moved the button/ label to the side

* CONCD-650 About this Campaign

* CONCD-650 Helpful links

* CONCD-650 minor fixes. I think the carousel works a lot better, if we just remove the 'slide' class

* CONCD-650 while the guide is 'hidden', its border shouldn't be visible

* CONCD-650 some code clean-up

* CONCD-650 A couple things (#2243)

* CONCD-650 slide indices were off by 1

* CONCD-650 pointer: cursor

* CONCD-651 Share data between simple pages and guides (#2242)

* CONCD-651 Share data between simple pages and guides

* CONCD-650 slide indices were off by 1

* CONCD-651 fixing an issue where view tests were failing

* CONCD-650 Initial feedback (#2245)

* CONCD-650 Make the X to escape out always available

* CONCD-650 Also make the guide closeable at any time by hitting ESC

* CONCD-650 the padding around the transcription box is missing

* CONCD-650 Reduce padding around both the How to Guide heading and the section title

* CONCD-650 Campaign.description

* CONCD-650 added padding above Helpful Links

* CONCD-650 reduced font size of Helpful Links

* Modified daily data backfill functions to split them using tasks and allow date data to be passed in from the admin (#2246) (#2247)

* Modified daily data backfill functions to split them using tasks and allow date data to be psssed in from the admin

* Updated black version in pre-commit config

* Updated black version to lint files

* Linted one other file

Co-authored-by: Josh Stegmaier <104993387+joshuastegmaier@users.noreply.github.com>

* CONCD-675 Refactor simple pages (#2250)

* CONCD-675 refactor Simple Pages (WiP)

* CONCD-675 setup codemirror

* CONCD-675 add new field to the template

* CONCD-674 display heading data has not yet been added (#2251)

* CONCD-674 display heading data has not yet been added

* CONCD-674 set the dialog box to one standard height (WiP)

* CONCD-674 fixed an issue where controls weren't always clickable

* CONCD-674 alt text

* CONCD-674 display heading should not be larger than the title (#2254)

* CONCD-650 A few more mostly small tweaks (#2255)

* CONCD-650 going to try moving the guide outside of the editor column

* CONCD-650 adjusting the vertical positioning of the guide

* CONCD-650 additional padding between the About this Campaign sections

* CONCD-650 fixed a bug where the external link symbol was being displayed next to loc.gov links

* CONCD-650 reduced font of Helpful Links

* CONCD-650 Change title to 'How-To Guide'

* CONCD-650 fixed an issue where css was having unintended consequences

* CONCD-650 trying to fix an issue where the modal cannot be interacted with, unless there is at least one guide object

* CONCD-650 center name in the title bar vertically

* CONCD-650 center X vertically

* CONCD-650 trying to make the 'x' consistent across guide sections

* CONCD-675 pull content for Simple Page from the corresponding Guide (#2258)

* CONCD-675 pull content for Simple Page from the corresponding Guide section (rather than the reverse)

* CONCD-675 reverting older changes

* CONCD-588 Card fields (#2262)

* CONCD-588 order the new fields a little more logically

* CONCD-588 added updated_on field to Card model (Requires Migration)

* CONCD-588 set Card.updated_on (Requires Migration)

* CONCD-588 renumbered migrations

* CONCD-675 How to transcribe (#2264)

* CONCD-675 exception for transcription page (WiP)

* CONCD-675 exception for transcription page

* CONCD-675 reverting this change (will no longer be needed) (#2267)

* CONCD-674 rsar reduce padding (#2270)

* CONCD-674 reduce some padding slightly

* CONCD-674 close button should align with header

* CONCD-674 set height dynamically

* CONCD-650 move title bar out of carousel (#2272)

* CONCD-650 I want to try moving the title bar outside of the carousel (WiP)

* CONCD-650 I think the title bar looks better works better outside of the carousel

* CONCD-650 show/ hide the 'hamburger' icon

* CONCD-675 include intro text from simple page body (#2273)

* Concd 650 rsar guide tweaks (#2274)

* CONCD-650 within text areas, set headers to the same size as text (1 rem) but bolded

* CONCD-650 add 8px of padding above the H3s

* CONCD-654 squashed migrations

* CONCD-654 these are now controlled through the admin, and should no longer be in settings

* CONCD-654 removed all prettier and stylelint libraries from package.json

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: joshuastegmaier <jstegmaier@loc.gov>
Co-authored-by: Josh Stegmaier <104993387+joshuastegmaier@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
4 people committed Feb 13, 2024
1 parent 4a4c9cd commit b5329bb
Show file tree
Hide file tree
Showing 23 changed files with 1,907 additions and 7,847 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ django-admin-multiple-choice-list-filter = "*"
django-npm = "*"
fpdf2 = "==2.5.5"
pymemcache = "*"
black = ">=24"
weasyprint = "*"
tesseract = "==0.1.3"
pytesseract = "*"
Expand Down
190 changes: 144 additions & 46 deletions Pipfile.lock

Large diffs are not rendered by default.

50 changes: 35 additions & 15 deletions concordia/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@
Banner,
Campaign,
CampaignRetirementProgress,
Card,
CardFamily,
CarouselSlide,
Guide,
Item,
Project,
Resource,
ResourceFile,
SimpleContentBlock,
SimplePage,
SiteReport,
Tag,
Topic,
Transcription,
TutorialCard,
UserAssetTagCollection,
UserProfileActivity,
)
Expand All @@ -61,6 +64,7 @@
AssetCampaignListFilter,
AssetCampaignStatusListFilter,
AssetProjectListFilter,
CardCampaignListFilter,
ItemCampaignListFilter,
ItemCampaignStatusListFilter,
ItemProjectListFilter,
Expand All @@ -86,9 +90,10 @@
from .forms import (
AdminItemImportForm,
CampaignAdminForm,
CardAdminForm,
GuideAdminForm,
ProjectAdminForm,
SanitizedDescriptionAdminForm,
SimpleContentBlockAdminForm,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -193,6 +198,7 @@ class CampaignAdmin(admin.ModelAdmin, CustomListDisplayFieldsMixin):
)
list_display_links = ("title",)
prepopulated_fields = {"slug": ("title",)}
raw_id_fields = ("card_family",)
search_fields = ["title", "description"]
list_filter = (
"published",
Expand Down Expand Up @@ -793,19 +799,6 @@ def export_to_excel(self, request, queryset):
actions = (export_to_csv, export_to_excel)


@admin.register(SimpleContentBlock)
class SimpleContentBlockAdmin(admin.ModelAdmin):
form = SimpleContentBlockAdminForm

list_display = ("slug", "created_on", "updated_on")
readonly_fields = ("created_on", "updated_on")

fieldsets = (
(None, {"fields": ("created_on", "updated_on", "slug")}),
("Body", {"classes": ("markdown-preview",), "fields": ("body",)}),
)


@admin.register(CarouselSlide)
class CarouselSlideAdmin(admin.ModelAdmin):
list_display = ("headline", "published", "ordering")
Expand Down Expand Up @@ -991,3 +984,30 @@ def completion(self, obj):
total = obj.project_total + obj.item_total + obj.asset_total
removed = obj.projects_removed + obj.items_removed + obj.assets_removed
return "{}%".format(round(removed / total * 100, 2))


@admin.register(Card)
class CardAdmin(admin.ModelAdmin):
form = CardAdminForm
fields = ("title", "display_heading", "body_text", "image", "image_alt_text")
list_display = ["title", "created_on", "updated_on"]
list_filter = (CardCampaignListFilter, "updated_on")


class TutorialInline(admin.TabularInline):
model = TutorialCard
extra = 1
raw_id_fields = ("card",)


@admin.register(CardFamily)
class CardFamilyAdmin(admin.ModelAdmin):
inlines = (TutorialInline,)

class Media:
js = ("admin/custom-inline.js",)


@admin.register(Guide)
class GuideAdmin(admin.ModelAdmin):
form = GuideAdminForm
25 changes: 25 additions & 0 deletions concordia/admin/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,31 @@ def queryset(self, request, queryset):
return queryset


class CardCampaignListFilter(admin.SimpleListFilter):
"""
Allow CMs to filter cards by campaign
"""

title = _("campaign")
parameter_name = "campaign"

def lookups(self, request, model_admin):
return Campaign.objects.exclude(card_family__isnull=True).values_list(
"pk", "title"
)

def queryset(self, request, queryset):
campaign_id = self.value()
if campaign_id:
card_family = Campaign.objects.get(pk=campaign_id).card_family
if card_family is None:
pks = []
else:
pks = card_family.cards.values_list("pk", flat=True)
queryset = queryset.filter(id__in=pks)
return queryset


class ProjectCampaignListFilter(CampaignListFilter):
parameter_name = "campaign__id__exact"
status_filter_parameter = "campaign__status"
Expand Down
22 changes: 20 additions & 2 deletions concordia/admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django import forms
from tinymce.widgets import TinyMCE

from ..models import Campaign, Project
from ..models import Campaign, Card, Guide, Project

FRAGMENT_ALLOWED_TAGS = {
"a",
Expand Down Expand Up @@ -89,7 +89,7 @@ def clean_short_description(self):
)


class CampaignAdminForm(forms.ModelForm):
class CampaignAdminForm(SanitizedDescriptionAdminForm):
class Meta(SanitizedDescriptionAdminForm.Meta):
model = Campaign
widgets = {
Expand All @@ -114,3 +114,21 @@ def clean_body(self):
tags=BLOCK_ALLOWED_TAGS,
attributes=ALLOWED_ATTRIBUTES,
)


class CardAdminForm(forms.ModelForm):
class Meta:
model = Card
widgets = {
"body_text": TinyMCE(),
}
fields = "__all__"


class GuideAdminForm(forms.ModelForm):
class Meta:
model = Guide
widgets = {
"body": TinyMCE(),
}
fields = "__all__"
19 changes: 19 additions & 0 deletions concordia/admin/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import re
import tempfile
import time
from http import HTTPStatus

from bittersweet.models import validated_get_or_create
from celery import Celery
from django.apps import apps
from django.contrib import messages
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import permission_required
from django.core.exceptions import ValidationError
from django.db.models import OuterRef, Subquery
from django.http import JsonResponse
from django.shortcuts import render
from django.utils.text import slugify
from django.views import View
from django.views.decorators.cache import never_cache
from tabular_export.core import export_to_csv_response, flatten_queryset

Expand Down Expand Up @@ -611,3 +615,18 @@ def admin_retired_site_report_view(request):
data.append(row)

return export_to_csv_response("retired-site-report.csv", headers, data)


class SerializedObjectView(View):
def get(self, request, *args, **kwargs):
model_name = request.GET.get("model_name")
object_id = request.GET.get("object_id")
field_name = request.GET.get("field_name")

model = apps.get_model(app_label="concordia", model_name=model_name)
try:
instance = model.objects.get(pk=object_id)
value = getattr(instance, field_name)
return JsonResponse({field_name: value})
except model.DoesNotExist:
return JsonResponse({"status": "false"}, status=HTTPStatus.NOT_FOUND)
6 changes: 6 additions & 0 deletions concordia/admin_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ConcordiaAdminSite(admin.AdminSite):

def get_urls(self):
from concordia.admin.views import (
SerializedObjectView,
admin_bulk_import_review,
admin_bulk_import_view,
admin_retired_site_report_view,
Expand Down Expand Up @@ -37,6 +38,11 @@ def get_urls(self):
project_level_export,
name="project-level-export",
),
path(
"serialized_object/",
SerializedObjectView.as_view(),
name="serialized_object",
),
]

return custom_urls + urls
136 changes: 136 additions & 0 deletions concordia/migrations/0087_auto_20240213_0756.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Generated by Django 3.2.23 on 2024-02-13 12:56

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("concordia", "0086_auto_20231215_1311"),
]

operations = [
migrations.CreateModel(
name="Card",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("image_alt_text", models.TextField(blank=True)),
(
"image",
models.ImageField(blank=True, null=True, upload_to="card_images"),
),
("title", models.CharField(max_length=80)),
("body_text", models.TextField(blank=True)),
("created_on", models.DateTimeField(auto_now_add=True)),
("updated_on", models.DateTimeField(auto_now=True, null=True)),
(
"display_heading",
models.CharField(blank=True, max_length=80, null=True),
),
],
options={
"ordering": ("title",),
},
),
migrations.CreateModel(
name="CardFamily",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"slug",
models.SlugField(allow_unicode=True, max_length=80, unique=True),
),
("default", models.BooleanField(default=False)),
],
options={
"verbose_name_plural": "card families",
},
),
migrations.CreateModel(
name="Guide",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=80)),
("body", models.TextField(blank=True)),
("order", models.IntegerField(default=1)),
("link_text", models.CharField(blank=True, max_length=80, null=True)),
("link_url", models.CharField(blank=True, max_length=255, null=True)),
],
),
migrations.CreateModel(
name="TutorialCard",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("order", models.IntegerField(default=0)),
(
"card",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="concordia.card"
),
),
(
"tutorial",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="concordia.cardfamily",
),
),
],
options={
"verbose_name_plural": "cards",
},
),
migrations.DeleteModel(
name="SimpleContentBlock",
),
migrations.AddField(
model_name="cardfamily",
name="cards",
field=models.ManyToManyField(
through="concordia.TutorialCard", to="concordia.Card"
),
),
migrations.AddField(
model_name="campaign",
name="card_family",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="concordia.cardfamily",
),
),
]
Loading

0 comments on commit b5329bb

Please sign in to comment.