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

Wagtail 6 #1581

Merged
merged 7 commits into from
Sep 18, 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
15 changes: 0 additions & 15 deletions .github/workflows/add-issue-to-project.yml

This file was deleted.

61 changes: 61 additions & 0 deletions allies/migrations/0012_remove_ally_adaptive_courseware_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Generated by Django 5.1.1 on 2024-09-05 17:43

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("allies", "0011_auto_20180301_1107"),
]

operations = [
migrations.RemoveField(
model_name="ally",
name="adaptive_courseware",
),
migrations.RemoveField(
model_name="ally",
name="customization_tools",
),
migrations.RemoveField(
model_name="ally",
name="do_not_display",
),
migrations.RemoveField(
model_name="ally",
name="heading",
),
migrations.RemoveField(
model_name="ally",
name="is_ap",
),
migrations.RemoveField(
model_name="ally",
name="logo_bw",
),
migrations.RemoveField(
model_name="ally",
name="logo_color",
),
migrations.RemoveField(
model_name="ally",
name="long_description",
),
migrations.RemoveField(
model_name="ally",
name="online_homework",
),
migrations.RemoveField(
model_name="ally",
name="short_description",
),
migrations.RemoveField(
model_name="allysubject",
name="ally",
),
migrations.RemoveField(
model_name="allysubject",
name="subject",
),
]
86 changes: 3 additions & 83 deletions allies/models.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,12 @@
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail.admin.panels import (FieldPanel, InlinePanel,
MultiFieldPanel)
from wagtail.fields import RichTextField
from wagtail.models import Page

from openstax.functions import build_image_url
from snippets.models import Subject


#TODO: remove this app after all migrations have been applied
class AllySubject(models.Model):
subject = models.ForeignKey(Subject, on_delete=models.PROTECT)
ally = ParentalKey('Ally', related_name='ally_subjects')

def get_subject_name(self):
return self.subject.name
pass


class Ally(Page):
online_homework = models.BooleanField(default=False)
adaptive_courseware = models.BooleanField(default=False)
customization_tools = models.BooleanField(default=False)
is_ap = models.BooleanField(default=False)
do_not_display = models.BooleanField(default=False)

logo_color = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='logo_color',
help_text="Image should be 460px wide"
)

def get_ally_logo(self):
return build_image_url(self.ally.logo_color)
ally_color_logo = property(get_ally_logo)

logo_bw = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='logo_bw',
help_text="Image should be 340px wide, grayscale"
)

def get_ally_logo(self):
return build_image_url(self.ally.logo_bw)

ally_bw_logo = property(get_ally_logo)

heading = models.CharField(max_length=255)
short_description = RichTextField()
long_description = RichTextField()

# a method to reverse retrieve the subject names, prevents multiple calls from Webview
# /api/v1/pages/?type=allies.Ally&fields=title,short_description,ally_logo,heading,ally_subject_list
def ally_subject_list(self):
subjects = AllySubject.objects.filter(ally=self)
subject_names = []
for subject in subjects:
subject_names.append(subject.subject.name)
return subject_names
property(ally_subject_list)

api_fields = ('online_homework', 'adaptive_courseware', 'customization_tools',
'ally_subject_list', 'is_ap', 'do_not_display',
'ally_color_logo', 'ally_bw_logo', 'heading',
'short_description', 'long_description')

content_panels = Page.content_panels + [
MultiFieldPanel(
[
FieldPanel('online_homework'),
FieldPanel('adaptive_courseware'),
FieldPanel('customization_tools'),
],
heading="Categories",
),
InlinePanel('ally_subjects', label="Subjects"),
FieldPanel('is_ap'),
FieldPanel('do_not_display'),
FieldPanel('logo_color'),
FieldPanel('logo_bw'),
FieldPanel('heading'),
FieldPanel('short_description'),
FieldPanel('long_description'),
]
pass

parent_page_types = ['pages.HomePage']
46 changes: 0 additions & 46 deletions allies/tests.py

This file was deleted.

13 changes: 8 additions & 5 deletions books/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@


def cleanhtml(raw_html):
remove_numbers = re.sub('<span class=\W*(os-number)\W*>.*?>', '', raw_html)
remove_dividers = re.sub('<span class=\W*(os-divider)\W*>.*?>', '', remove_numbers)
remove_numbers = re.sub('<span class=\\W*(os-number)\\W*>.*?>', '', raw_html)
remove_dividers = re.sub('<span class=\\W*(os-divider)\\W*>.*?>', '', remove_numbers)

Check warning on line 29 in books/models.py

View check run for this annotation

Codecov / codecov/patch

books/models.py#L28-L29

Added lines #L28 - L29 were not covered by tests
cleanr = re.compile('<.*?>')
cleantext = html.unescape(re.sub(cleanr, '', remove_dividers))
return cleantext
Expand Down Expand Up @@ -541,8 +541,10 @@

polish_site_link = models.URLField(blank=True, null=True,
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")
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.')
salesforce_name = models.CharField(max_length=255, blank=True, null=True, verbose_name='Name displayed on website forms',
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.')
salesforce_name = models.CharField(max_length=255, blank=True, null=True,
verbose_name='Name displayed on website forms',
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')
salesforce_book_id = models.CharField(max_length=255, blank=True, null=True,
help_text='No tracking and not included on adoption and interest forms if left blank)')
Expand Down Expand Up @@ -999,7 +1001,7 @@
book_urls = []
for field in self.api_fields:
try:
url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',

Check warning on line 1004 in books/models.py

View check run for this annotation

Codecov / codecov/patch

books/models.py#L1004

Added line #L1004 was not covered by tests
getattr(self, field))
if url:
book_urls.append(url)
Expand Down Expand Up @@ -1062,6 +1064,7 @@
def __str__(self):
return self.book_title


# old subjects interface, deprecated
class BookIndex(Page):
page_description = models.TextField()
Expand Down
17 changes: 15 additions & 2 deletions errata/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from django.shortcuts import render, redirect
from .models import Errata, ERRATA_STATUS
from .serializers import ErrataSerializer
from .forms import ErrataModelForm
from openstax_accounts.functions import get_user_info
from wagtail.admin.viewsets.model import ModelViewSet as WagtailModelViewSet


class JSONResponse(HttpResponse):
Expand Down Expand Up @@ -40,6 +39,20 @@ class ErrataView(ModelViewSet):
filterset_class = ErrataFilter
ordering_fields = ('id', 'resolution_date', 'created', 'modified', )

class ErrataModelViewSet(WagtailModelViewSet):
queryset = Errata.objects.prefetch_related("book")
model = Errata
icon = "warning"
list_display = ("id", "book", "created", "modified", 'status', 'error_type', 'resource')
list_filter = ('created', "book", "status", 'archived', 'junk')
list_export = ("id", "book", "created", "modified", 'status', 'error_type', 'resource', 'location', 'detail', 'resolution_notes')
search_fields = ("book__title",)
menu_label = "Errata (Beta)"
menu_order = 9000
add_to_admin_menu = True
exclude_form_fields = []

errata_viewset = ErrataModelViewSet("errata")

def duplicate(errata):
errata.pk = None
Expand Down
6 changes: 6 additions & 0 deletions errata/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from wagtail import hooks
from .views import errata_viewset

@hooks.register("register_admin_viewset")
def register_viewset():
return errata_viewset
2 changes: 1 addition & 1 deletion openstax/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@
# Wagtail #
###########

WAGTAIL_SITE_NAME = 'openstax'
WAGTAIL_SITE_NAME = 'OpenStax'
WAGTAILAPI_BASE_URL = os.getenv('WAGTAILAPI_BASE_URL', BASE_URL)
# Wagtail API number of results
WAGTAILAPI_LIMIT_MAX = None
Expand Down
11 changes: 6 additions & 5 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
boto3==1.34.49
botocore==1.34.49
bs4==0.0.2
Django==5.0.4
certifi==2024.7.4
django-admin-rangefilter==0.12.1
django-crontab==0.7.1
django-compressor==4.4
django-compressor==4.5.1
django-filter==23.5
django-import-export==2.8.0
django-modelcluster==6.2.1
django-openstax-accounts
django-openstax-healthcheck
django-rest-auth==0.9.5
django-reversion==5.0.12
django-reversion==5.1.0
django-ses==3.5.2
django-storages==1.12.3
django-taggit>=4.0.0
django-storages==1.14.4
django-taggit>=5.0.0
djangorestframework==3.15.2
html2text==2020.1.16 # news feed
mapbox==0.18.1
Expand All @@ -28,6 +29,6 @@ six==1.16.0
ua-parser==0.18.0
unicodecsv==0.14.1
vcrpy==6.0.1 # recoding Salesforce interactions in tests
wagtail==5.2.6
wagtail==6.2.1
wagtail-modeladmin==2.0.0
whitenoise==6.6.0
5 changes: 2 additions & 3 deletions salesforce/management/commands/update_resource_downloads.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from django.core.management.base import BaseCommand
#from django.db import transaction
from salesforce.models import ResourceDownload
from salesforce.salesforce import Salesforce
#from simple_salesforce.exceptions import SalesforceResourceNotFound
from django.utils import timezone
from datetime import timedelta

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

new_results = sf.bulk.Resource__c.insert(new_data)
if len(new_data) > 0:
new_results = sf.bulk.Resource__c.insert(new_data)

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