Skip to content

Commit df68e34

Browse files
authored
Wagtail 6 (#1581)
* upgrade to wagtail 6 and django 5 * upgrade to 6.2.1 * upgrades to support django 5+ * missing snippet * remove unused allies * do not attempt to upload 0 resources
1 parent 0c5587c commit df68e34

File tree

12 files changed

+305
-161
lines changed

12 files changed

+305
-161
lines changed

.github/workflows/add-issue-to-project.yml

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Generated by Django 5.1.1 on 2024-09-05 17:43
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("allies", "0011_auto_20180301_1107"),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name="ally",
15+
name="adaptive_courseware",
16+
),
17+
migrations.RemoveField(
18+
model_name="ally",
19+
name="customization_tools",
20+
),
21+
migrations.RemoveField(
22+
model_name="ally",
23+
name="do_not_display",
24+
),
25+
migrations.RemoveField(
26+
model_name="ally",
27+
name="heading",
28+
),
29+
migrations.RemoveField(
30+
model_name="ally",
31+
name="is_ap",
32+
),
33+
migrations.RemoveField(
34+
model_name="ally",
35+
name="logo_bw",
36+
),
37+
migrations.RemoveField(
38+
model_name="ally",
39+
name="logo_color",
40+
),
41+
migrations.RemoveField(
42+
model_name="ally",
43+
name="long_description",
44+
),
45+
migrations.RemoveField(
46+
model_name="ally",
47+
name="online_homework",
48+
),
49+
migrations.RemoveField(
50+
model_name="ally",
51+
name="short_description",
52+
),
53+
migrations.RemoveField(
54+
model_name="allysubject",
55+
name="ally",
56+
),
57+
migrations.RemoveField(
58+
model_name="allysubject",
59+
name="subject",
60+
),
61+
]

allies/models.py

+3-83
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,12 @@
11
from django.db import models
2-
from modelcluster.fields import ParentalKey
3-
from wagtail.admin.panels import (FieldPanel, InlinePanel,
4-
MultiFieldPanel)
5-
from wagtail.fields import RichTextField
62
from wagtail.models import Page
7-
8-
from openstax.functions import build_image_url
93
from snippets.models import Subject
104

11-
5+
#TODO: remove this app after all migrations have been applied
126
class AllySubject(models.Model):
13-
subject = models.ForeignKey(Subject, on_delete=models.PROTECT)
14-
ally = ParentalKey('Ally', related_name='ally_subjects')
15-
16-
def get_subject_name(self):
17-
return self.subject.name
7+
pass
188

199

2010
class Ally(Page):
21-
online_homework = models.BooleanField(default=False)
22-
adaptive_courseware = models.BooleanField(default=False)
23-
customization_tools = models.BooleanField(default=False)
24-
is_ap = models.BooleanField(default=False)
25-
do_not_display = models.BooleanField(default=False)
26-
27-
logo_color = models.ForeignKey(
28-
'wagtailimages.Image',
29-
null=True,
30-
blank=True,
31-
on_delete=models.SET_NULL,
32-
related_name='logo_color',
33-
help_text="Image should be 460px wide"
34-
)
35-
36-
def get_ally_logo(self):
37-
return build_image_url(self.ally.logo_color)
38-
ally_color_logo = property(get_ally_logo)
39-
40-
logo_bw = models.ForeignKey(
41-
'wagtailimages.Image',
42-
null=True,
43-
blank=True,
44-
on_delete=models.SET_NULL,
45-
related_name='logo_bw',
46-
help_text="Image should be 340px wide, grayscale"
47-
)
48-
49-
def get_ally_logo(self):
50-
return build_image_url(self.ally.logo_bw)
51-
52-
ally_bw_logo = property(get_ally_logo)
53-
54-
heading = models.CharField(max_length=255)
55-
short_description = RichTextField()
56-
long_description = RichTextField()
57-
58-
# a method to reverse retrieve the subject names, prevents multiple calls from Webview
59-
# /api/v1/pages/?type=allies.Ally&fields=title,short_description,ally_logo,heading,ally_subject_list
60-
def ally_subject_list(self):
61-
subjects = AllySubject.objects.filter(ally=self)
62-
subject_names = []
63-
for subject in subjects:
64-
subject_names.append(subject.subject.name)
65-
return subject_names
66-
property(ally_subject_list)
67-
68-
api_fields = ('online_homework', 'adaptive_courseware', 'customization_tools',
69-
'ally_subject_list', 'is_ap', 'do_not_display',
70-
'ally_color_logo', 'ally_bw_logo', 'heading',
71-
'short_description', 'long_description')
72-
73-
content_panels = Page.content_panels + [
74-
MultiFieldPanel(
75-
[
76-
FieldPanel('online_homework'),
77-
FieldPanel('adaptive_courseware'),
78-
FieldPanel('customization_tools'),
79-
],
80-
heading="Categories",
81-
),
82-
InlinePanel('ally_subjects', label="Subjects"),
83-
FieldPanel('is_ap'),
84-
FieldPanel('do_not_display'),
85-
FieldPanel('logo_color'),
86-
FieldPanel('logo_bw'),
87-
FieldPanel('heading'),
88-
FieldPanel('short_description'),
89-
FieldPanel('long_description'),
90-
]
11+
pass
9112

92-
parent_page_types = ['pages.HomePage']

allies/tests.py

-46
This file was deleted.

books/models.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626

2727
def cleanhtml(raw_html):
28-
remove_numbers = re.sub('<span class=\W*(os-number)\W*>.*?>', '', raw_html)
29-
remove_dividers = re.sub('<span class=\W*(os-divider)\W*>.*?>', '', remove_numbers)
28+
remove_numbers = re.sub('<span class=\\W*(os-number)\\W*>.*?>', '', raw_html)
29+
remove_dividers = re.sub('<span class=\\W*(os-divider)\\W*>.*?>', '', remove_numbers)
3030
cleanr = re.compile('<.*?>')
3131
cleantext = html.unescape(re.sub(cleanr, '', remove_dividers))
3232
return cleantext
@@ -541,8 +541,10 @@ class Book(Page):
541541

542542
polish_site_link = models.URLField(blank=True, null=True,
543543
help_text="Stores target URL to the Polish site so that REX Polish page headers lead back to each individual book on the Polish site")
544-
salesforce_abbreviation = models.CharField(max_length=255, blank=True, null=True, verbose_name='Subject Book Name', help_text='This should match the Books Name from Salesforce.')
545-
salesforce_name = models.CharField(max_length=255, blank=True, null=True, verbose_name='Name displayed on website forms',
544+
salesforce_abbreviation = models.CharField(max_length=255, blank=True, null=True, verbose_name='Subject Book Name',
545+
help_text='This should match the Books Name from Salesforce.')
546+
salesforce_name = models.CharField(max_length=255, blank=True, null=True,
547+
verbose_name='Name displayed on website forms',
546548
help_text='This is the name shown on interest/adoption forms and used in Partner filtering. The website only shows unique values from here, so it is possible to combine books for forms')
547549
salesforce_book_id = models.CharField(max_length=255, blank=True, null=True,
548550
help_text='No tracking and not included on adoption and interest forms if left blank)')
@@ -999,7 +1001,7 @@ def book_urls(self):
9991001
book_urls = []
10001002
for field in self.api_fields:
10011003
try:
1002-
url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
1004+
url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
10031005
getattr(self, field))
10041006
if url:
10051007
book_urls.append(url)
@@ -1062,6 +1064,7 @@ def get_url_parts(self, *args, **kwargs):
10621064
def __str__(self):
10631065
return self.book_title
10641066

1067+
10651068
# old subjects interface, deprecated
10661069
class BookIndex(Page):
10671070
page_description = models.TextField()

errata/views.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
from django.shortcuts import render, redirect
88
from .models import Errata, ERRATA_STATUS
99
from .serializers import ErrataSerializer
10-
from .forms import ErrataModelForm
11-
from openstax_accounts.functions import get_user_info
10+
from wagtail.admin.viewsets.model import ModelViewSet as WagtailModelViewSet
1211

1312

1413
class JSONResponse(HttpResponse):
@@ -40,6 +39,20 @@ class ErrataView(ModelViewSet):
4039
filterset_class = ErrataFilter
4140
ordering_fields = ('id', 'resolution_date', 'created', 'modified', )
4241

42+
class ErrataModelViewSet(WagtailModelViewSet):
43+
queryset = Errata.objects.prefetch_related("book")
44+
model = Errata
45+
icon = "warning"
46+
list_display = ("id", "book", "created", "modified", 'status', 'error_type', 'resource')
47+
list_filter = ('created', "book", "status", 'archived', 'junk')
48+
list_export = ("id", "book", "created", "modified", 'status', 'error_type', 'resource', 'location', 'detail', 'resolution_notes')
49+
search_fields = ("book__title",)
50+
menu_label = "Errata (Beta)"
51+
menu_order = 9000
52+
add_to_admin_menu = True
53+
exclude_form_fields = []
54+
55+
errata_viewset = ErrataModelViewSet("errata")
4356

4457
def duplicate(errata):
4558
errata.pk = None

errata/wagtail_hooks.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from wagtail import hooks
2+
from .views import errata_viewset
3+
4+
@hooks.register("register_admin_viewset")
5+
def register_viewset():
6+
return errata_viewset

openstax/settings/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@
399399
# Wagtail #
400400
###########
401401

402-
WAGTAIL_SITE_NAME = 'openstax'
402+
WAGTAIL_SITE_NAME = 'OpenStax'
403403
WAGTAILAPI_BASE_URL = os.getenv('WAGTAILAPI_BASE_URL', BASE_URL)
404404
# Wagtail API number of results
405405
WAGTAILAPI_LIMIT_MAX = None

requirements/base.txt

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
boto3==1.34.49
22
botocore==1.34.49
33
bs4==0.0.2
4+
Django==5.0.4
45
certifi==2024.7.4
56
django-admin-rangefilter==0.12.1
67
django-crontab==0.7.1
7-
django-compressor==4.4
8+
django-compressor==4.5.1
89
django-filter==23.5
910
django-import-export==2.8.0
1011
django-modelcluster==6.2.1
1112
django-openstax-accounts
1213
django-openstax-healthcheck
1314
django-rest-auth==0.9.5
14-
django-reversion==5.0.12
15+
django-reversion==5.1.0
1516
django-ses==3.5.2
16-
django-storages==1.12.3
17-
django-taggit>=4.0.0
17+
django-storages==1.14.4
18+
django-taggit>=5.0.0
1819
djangorestframework==3.15.2
1920
html2text==2020.1.16 # news feed
2021
mapbox==0.18.1
@@ -28,6 +29,6 @@ six==1.16.0
2829
ua-parser==0.18.0
2930
unicodecsv==0.14.1
3031
vcrpy==6.0.1 # recoding Salesforce interactions in tests
31-
wagtail==5.2.6
32+
wagtail==6.2.1
3233
wagtail-modeladmin==2.0.0
3334
whitenoise==6.6.0

salesforce/management/commands/update_resource_downloads.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from django.core.management.base import BaseCommand
2-
#from django.db import transaction
32
from salesforce.models import ResourceDownload
43
from salesforce.salesforce import Salesforce
5-
#from simple_salesforce.exceptions import SalesforceResourceNotFound
64
from django.utils import timezone
75
from datetime import timedelta
86

@@ -32,7 +30,8 @@ def handle(self, *args, **options):
3230
'Accounts_UUID__c': str(nrd.account_uuid)}
3331
new_data.append(data_dict_item)
3432

35-
new_results = sf.bulk.Resource__c.insert(new_data)
33+
if len(new_data) > 0:
34+
new_results = sf.bulk.Resource__c.insert(new_data)
3635

3736
response = self.style.SUCCESS("SF Resource Download Completed. Sent: {}.".format(len(new_data)))
3837
self.stdout.write(response)

0 commit comments

Comments
 (0)