From 8e62c0736983dfba151e88cacb6759465a12071f Mon Sep 17 00:00:00 2001 From: Ed Woodward Date: Fri, 17 Nov 2023 08:27:39 -0600 Subject: [PATCH 1/9] Wagtail 4.1.9 upgrade (#1522) * Updated to wagtail 4.1.9 and replaced WagtailPageTests with WagtailPageTestCase * Fixes migration conflict --- allies/tests.py | 7 ++----- books/tests.py | 4 ++-- news/tests.py | 6 +++--- oxmenus/tests.py | 4 ++-- pages/tests.py | 12 ++++++------ requirements/base.txt | 7 ++++--- salesforce/tests.py | 4 ++-- snippets/migrations/0031_merge_20231101_1313.py | 14 ++++++++++++++ webinars/tests.py | 4 ++-- 9 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 snippets/migrations/0031_merge_20231101_1313.py diff --git a/allies/tests.py b/allies/tests.py index 3c7605cb4..f5a6284ea 100644 --- a/allies/tests.py +++ b/allies/tests.py @@ -3,10 +3,10 @@ from allies.models import AllySubject, Ally from snippets.models import Subject -from wagtail.test.utils import WagtailTestUtils, WagtailPageTests +from wagtail.test.utils import WagtailTestUtils, WagtailPageTestCase -class AlliesTests(WagtailPageTests): +class AlliesTests(WagtailPageTestCase): def setUp(self): self.math = Subject(name="Math", page_content="Math page content.", seo_title="Math SEO Title", search_description="Math page description.") @@ -42,8 +42,5 @@ def test_can_create_ally_subject(self): self.assertEquals('Math', result.get_subject_name()) def test_can_create_ally(self): - #ally_subject = AllySubject(subject=self.math, ally=self.ally) - #ally_subject.save() result = Ally.objects.all()[0] - #print('ally subject: ' + str(result)) self.assertEquals('Ally Heading', result.heading) diff --git a/books/tests.py b/books/tests.py index dbab26d59..ebfc185ef 100644 --- a/books/tests.py +++ b/books/tests.py @@ -1,6 +1,6 @@ import vcr -from wagtail.test.utils import WagtailPageTests +from wagtail.test.utils import WagtailPageTestCase from wagtail.models import Page import snippets.models @@ -14,7 +14,7 @@ import datetime -class BookTests(WagtailPageTests): +class BookTests(WagtailPageTestCase): def setUp(self): self.client = Client() diff --git a/news/tests.py b/news/tests.py index ad0547b5e..49c0a4da3 100644 --- a/news/tests.py +++ b/news/tests.py @@ -3,7 +3,7 @@ from django.utils import timezone from django.test import TestCase -from wagtail.test.utils import WagtailPageTests +from wagtail.test.utils import WagtailPageTestCase from wagtail.models import Page from pages.models import HomePage from shared.test_utilities import assertPathDoesNotRedirectToTrailingSlash @@ -12,7 +12,7 @@ from snippets.models import Subject, BlogContentType, BlogCollection -class NewsTests(WagtailPageTests, TestCase): +class NewsTests(WagtailPageTestCase, TestCase): def setUp(self): # create collections self.learning = BlogCollection(name='Teaching and Learning', description='this is a collection') @@ -258,7 +258,7 @@ def test_search_blog_collection_and_two_subjects(self): self.assertContains(response, 'Math') -class PressTests(WagtailPageTests): +class PressTests(WagtailPageTestCase): def setUp(self): press_index = PressIndex.objects.all()[0] self.press_release = PressRelease(title='Press release', diff --git a/oxmenus/tests.py b/oxmenus/tests.py index 3c38f44fa..cbdbde51d 100644 --- a/oxmenus/tests.py +++ b/oxmenus/tests.py @@ -1,11 +1,11 @@ import json from django.test import TestCase -from wagtail.test.utils import WagtailPageTests +from wagtail.test.utils import WagtailPageTestCase from oxmenus.models import Menus -class OXMenuTests(WagtailPageTests, TestCase): +class OXMenuTests(WagtailPageTestCase, TestCase): def setUp(self): oxmenu = Menus(name="What we do", menu=json.dumps( diff --git a/pages/tests.py b/pages/tests.py index 9e83a604a..f73cd218e 100644 --- a/pages/tests.py +++ b/pages/tests.py @@ -3,7 +3,7 @@ from django.test import TestCase, Client from django.core.management import call_command -from wagtail.test.utils import WagtailTestUtils, WagtailPageTests +from wagtail.test.utils import WagtailTestUtils, WagtailPageTestCase from wagtail.models import Page from pages.models import (HomePage, ContactUs, @@ -44,7 +44,7 @@ from shared.test_utilities import assertPathDoesNotRedirectToTrailingSlash, mock_user_login from http import cookies -class HomePageTests(WagtailPageTests): +class HomePageTests(WagtailPageTestCase): def setUp(self): mock_user_login() @@ -105,7 +105,7 @@ def test_allowed_subpages(self): Assignable, }) -class PageTests(WagtailPageTests): +class PageTests(WagtailPageTestCase): def setUp(self): mock_user_login() root_page = Page.objects.get(title="Root") @@ -496,7 +496,7 @@ def test_can_create_assignable_page(self): self.assertEqual(retrieved_page.title, "Assignable Page") -class ErrataListTest(WagtailPageTests): +class ErrataListTest(WagtailPageTestCase): def setUp(self): mock_user_login() @@ -521,7 +521,7 @@ def test_can_create_errata_list_page(self): self.assertEqual(retrieved_page.title, "Errata List Template") -class SubjectsPageTest(WagtailPageTests): +class SubjectsPageTest(WagtailPageTestCase): def setUp(self): mock_user_login() @@ -543,7 +543,7 @@ def test_can_create_subjects_page(self): self.assertEqual(retrieved_page.title, "Subjects") -class SubjectPageTest(WagtailPageTests): +class SubjectPageTest(WagtailPageTestCase): def setUp(self): mock_user_login() diff --git a/requirements/base.txt b/requirements/base.txt index 94257972a..089c8e2bd 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -9,9 +9,10 @@ django-import-export==2.8.0 django-libsass==0.9 django-rest-auth==0.9.5 django-reversion==5.0.0 +djangorestframework==3.14.0 django-ses==3.0.1 django-storages==1.12.3 -django-taggit>=3.0.0 +django-taggit>=3.1.0 future==0.18.2 html2text==2020.1.16 # used in news feed jsonfield==3.1.0 @@ -19,7 +20,7 @@ mapbox==0.18.1 MarkupPy==1.14 odfpy==1.4.1 openpyxl==3.0.10 -psycopg2>=2.9.5 +psycopg2>=2.9.9 pycryptodome==3.14.1 # for using the SSO cookie from accounts PyJWE==1.0.0 sentry-sdk @@ -30,7 +31,7 @@ ua_parser==0.16.1 unicodecsv==0.14.1 Unidecode==1.3.4 vcrpy==4.1.1 # for recording test interactions with third-party APIs -wagtail==4.0.4 +wagtail==4.1.9 Wand==0.6.7 # for supporting animated gifs whitenoise==6.1.0 xlrd==2.0.1 diff --git a/salesforce/tests.py b/salesforce/tests.py index ced83cf9a..51dc553bd 100644 --- a/salesforce/tests.py +++ b/salesforce/tests.py @@ -22,7 +22,7 @@ from rest_framework.test import APITestCase from rest_framework.test import APIRequestFactory -from wagtail.test.utils import WagtailPageTests +from wagtail.test.utils import WagtailPageTestCase from wagtail.models import Page from wagtail.documents.models import Document @@ -103,7 +103,7 @@ def test_all_partners_no_reviews(self): # self.assertEqual(response.data['status'], 'Deleted') -class SalesforceTest(LiveServerTestCase, WagtailPageTests): +class SalesforceTest(LiveServerTestCase, WagtailPageTestCase): def setUp(self): mock_user_login() diff --git a/snippets/migrations/0031_merge_20231101_1313.py b/snippets/migrations/0031_merge_20231101_1313.py new file mode 100644 index 000000000..7c337c735 --- /dev/null +++ b/snippets/migrations/0031_merge_20231101_1313.py @@ -0,0 +1,14 @@ +# Generated by Django 4.1.7 on 2023-11-01 18:13 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('snippets', '0030_alter_erratacontent_book_state'), + ('snippets', '0030_amazonbookblurb'), + ] + + operations = [ + ] diff --git a/webinars/tests.py b/webinars/tests.py index 86f8feda6..72e550ff5 100644 --- a/webinars/tests.py +++ b/webinars/tests.py @@ -2,13 +2,13 @@ from django.test import TestCase from django.utils import timezone -from wagtail.test.utils import WagtailPageTests +from wagtail.test.utils import WagtailPageTestCase from snippets.models import Subject, WebinarCollection from webinars.models import Webinar -class WebinarTests(WagtailPageTests, TestCase): +class WebinarTests(WagtailPageTestCase, TestCase): def setUp(self): # create subjects self.math = Subject(name="Math", page_content="Math page content.", seo_title="Math SEO Title", From f349c586a73544f748ad9f4fbe45e958f490ea30 Mon Sep 17 00:00:00 2001 From: Ed Woodward Date: Fri, 17 Nov 2023 09:51:32 -0600 Subject: [PATCH 2/9] Added source field to Thank You Note (#1529) --- .../migrations/0008_thankyounote_source.py | 18 ++++++++++++++++++ donations/models.py | 1 + donations/serializers.py | 6 ++++-- donations/tests.py | 2 +- donations/views.py | 4 +++- errata/migrations/0056_alter_errata_options.py | 17 +++++++++++++++++ .../migrations/0032_merge_20231117_0830.py | 14 ++++++++++++++ 7 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 donations/migrations/0008_thankyounote_source.py create mode 100644 errata/migrations/0056_alter_errata_options.py create mode 100644 snippets/migrations/0032_merge_20231117_0830.py diff --git a/donations/migrations/0008_thankyounote_source.py b/donations/migrations/0008_thankyounote_source.py new file mode 100644 index 000000000..024ad0a09 --- /dev/null +++ b/donations/migrations/0008_thankyounote_source.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-11-17 14:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('donations', '0007_auto_20220516_2113'), + ] + + operations = [ + migrations.AddField( + model_name='thankyounote', + name='source', + field=models.CharField(blank=True, default='', max_length=255), + ), + ] diff --git a/donations/models.py b/donations/models.py index 66cfcca53..f752b4a18 100644 --- a/donations/models.py +++ b/donations/models.py @@ -21,6 +21,7 @@ class ThankYouNote(models.Model): created = models.DateField(auto_now_add=True) consent_to_share_or_contact = models.BooleanField(default=False) contact_email_address = models.EmailField(blank=True, null=True) + source = models.CharField(max_length=255, default="", blank=True) class DonationPopup(models.Model): download_image = models.ImageField(null=True, blank=True) diff --git a/donations/serializers.py b/donations/serializers.py index 45c4c10de..1f2b4566c 100644 --- a/donations/serializers.py +++ b/donations/serializers.py @@ -11,14 +11,16 @@ class Meta: 'institution', 'created', 'consent_to_share_or_contact', - 'contact_email_address') + 'contact_email_address', + 'source') read_only_fields = ('thank_you_note', 'first_name', 'last_name', 'institution', 'created', 'consent_to_share_or_contact', - 'contact_email_address') + 'contact_email_address', + 'source') class DonationPopupSerializer(serializers.ModelSerializer): diff --git a/donations/tests.py b/donations/tests.py index 81cedbc97..e3569392d 100644 --- a/donations/tests.py +++ b/donations/tests.py @@ -37,7 +37,7 @@ def test_donation_api_get(self): class ThankYouNoteTest(APITestCase, TestCase): def test_thank_you_note_api_post(self): - data = {"thank_you_note":"OpenStax is the best! Loved not paying for a book", "last_name": "Drew", "first_name": "Jessica", "institution": "Rice University", "consent_to_share_or_contact": "True", "contact_email_address": "jess@example.com"} + data = {"thank_you_note":"OpenStax is the best! Loved not paying for a book", "last_name": "Drew", "first_name": "Jessica", "institution": "Rice University", "consent_to_share_or_contact": "True", "contact_email_address": "jess@example.com", "source": "PDF download"} response = self.client.post('/apps/cms/api/donations/thankyounote/', data, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) tyn = ThankYouNote.objects.filter(last_name='Drew').values() diff --git a/donations/views.py b/donations/views.py index 0724f38a8..b23847a18 100644 --- a/donations/views.py +++ b/donations/views.py @@ -17,13 +17,15 @@ def post(self, request): institution = request.data['institution'] consent_to_share_or_contact = request.data.get('consent_to_share_or_contact', False) contact_email_address = request.data.get('contact_email_address', '') + source = request.data.get('source', '') ty_note = ThankYouNote.objects.create(thank_you_note=thank_you_note, first_name=first_name, last_name=last_name, institution=institution, consent_to_share_or_contact=consent_to_share_or_contact, - contact_email_address=contact_email_address) + contact_email_address=contact_email_address, + source=source) serializer = ThankYouNoteSerializer(data=request.data) if serializer.is_valid(): diff --git a/errata/migrations/0056_alter_errata_options.py b/errata/migrations/0056_alter_errata_options.py new file mode 100644 index 000000000..89b6be571 --- /dev/null +++ b/errata/migrations/0056_alter_errata_options.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.7 on 2023-11-17 14:37 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('errata', '0055_remove_errata_accounts_user_email_and_more'), + ] + + operations = [ + migrations.AlterModelOptions( + name='errata', + options={'verbose_name': 'erratum list', 'verbose_name_plural': 'errata list'}, + ), + ] diff --git a/snippets/migrations/0032_merge_20231117_0830.py b/snippets/migrations/0032_merge_20231117_0830.py new file mode 100644 index 000000000..d18ebde45 --- /dev/null +++ b/snippets/migrations/0032_merge_20231117_0830.py @@ -0,0 +1,14 @@ +# Generated by Django 4.1.7 on 2023-11-17 14:30 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('snippets', '0031_merge_20231101_1313'), + ('snippets', '0031_merge_20231101_1438'), + ] + + operations = [ + ] From 7281211045023c289900d3b738002f1093254e85 Mon Sep 17 00:00:00 2001 From: Colby Date: Fri, 1 Dec 2023 16:27:24 -0600 Subject: [PATCH 3/9] Update admin.py (#1532) Co-authored-by: Staxly --- errata/admin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/errata/admin.py b/errata/admin.py index 3f24e0ac7..ac14d06c8 100644 --- a/errata/admin.py +++ b/errata/admin.py @@ -32,13 +32,13 @@ class Meta: class CustomExportResource(resources.ModelResource): location = Field(attribute='location', column_name='Location') detail = Field(attribute='detail', column_name='Detail') - resolution = Field(attribute='resolution', column_name='Resolution') + resolution_notes = Field(attribute='resolution_notes', column_name='Resolution Notes') error_type = Field(attribute='error_type', column_name='Error Type') class Meta: model = Errata - fields = ('location', 'detail', 'resolution', 'error_type') - export_order = ('location', 'detail', 'resolution', 'error_type') + fields = ('location', 'detail', 'resolution_notes', 'error_type') + export_order = ('location', 'detail', 'resolution_notes', 'error_type') def custom_export_action(modeladmin, request, queryset): resource = CustomExportResource() From 0151c27c1621f502cb6beccc4dade34d69ecff86 Mon Sep 17 00:00:00 2001 From: Colby Date: Wed, 6 Dec 2023 13:53:36 -0600 Subject: [PATCH 4/9] updating book filter to exclude (#1530) Co-authored-by: Staxly Co-authored-by: Michael Volo --- books/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/books/models.py b/books/models.py index 47147c183..94a6aa465 100644 --- a/books/models.py +++ b/books/models.py @@ -997,7 +997,7 @@ class BookIndex(Page): @property def books(self): - books = Book.objects.live().filter(locale=self.locale).filter(self.book_state is not 'unlisted').order_by('title') + books = Book.objects.live().filter(locale=self.locale).exclude(book_state='unlisted').order_by('title') book_data = [] for book in books: has_faculty_resources = BookFacultyResources.objects.filter(book_faculty_resource=book).exists() From 58d35b3774aec585e9b37a09fd544dd74e0994fd Mon Sep 17 00:00:00 2001 From: Michael Harrison Date: Wed, 13 Dec 2023 14:02:45 -0600 Subject: [PATCH 5/9] remove unused account id field from resource downloads --- ...salesforce__account_b11d37_idx_and_more.py | 20 +++++++++++++++++++ salesforce/models.py | 2 -- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 salesforce/migrations/0106_remove_resourcedownload_salesforce__account_b11d37_idx_and_more.py diff --git a/salesforce/migrations/0106_remove_resourcedownload_salesforce__account_b11d37_idx_and_more.py b/salesforce/migrations/0106_remove_resourcedownload_salesforce__account_b11d37_idx_and_more.py new file mode 100644 index 000000000..410a219e9 --- /dev/null +++ b/salesforce/migrations/0106_remove_resourcedownload_salesforce__account_b11d37_idx_and_more.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.7 on 2023-12-13 19:28 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("salesforce", "0105_auto_20221212_1543"), + ] + + operations = [ + migrations.RemoveIndex( + model_name="resourcedownload", + name="salesforce__account_b11d37_idx", + ), + migrations.RemoveField( + model_name="resourcedownload", + name="account_id", + ), + ] diff --git a/salesforce/models.py b/salesforce/models.py index 0d579e851..b4fdc2412 100644 --- a/salesforce/models.py +++ b/salesforce/models.py @@ -389,7 +389,6 @@ class ResourceDownload(models.Model): ) book = models.ForeignKey(Book, on_delete=models.SET_NULL, null=True, blank=True) book_format = models.CharField(max_length=100, choices=BOOK_FORMATS, null=True , blank=True) - account_id = models.IntegerField(blank=True, null=True) # TODO: remove this field after migrating data to UUID (see management command) account_uuid = models.UUIDField(null=True) created = models.DateTimeField(auto_now_add=True) edited = models.DateTimeField(auto_now=True) @@ -399,7 +398,6 @@ class ResourceDownload(models.Model): class Meta: indexes = [ - models.Index(fields=['account_id', ]), models.Index(fields=['account_uuid', ]), models.Index(fields=['book', ]), ] From d5e42a673ff2a9d1df0961623f23e4f915880732 Mon Sep 17 00:00:00 2001 From: Michael Harrison Date: Wed, 13 Dec 2023 14:03:09 -0600 Subject: [PATCH 6/9] do not check for book and contact on resource creation --- salesforce/serializers.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/salesforce/serializers.py b/salesforce/serializers.py index a15d558d9..c40723a87 100644 --- a/salesforce/serializers.py +++ b/salesforce/serializers.py @@ -120,17 +120,16 @@ def create(self, validated_data): resource_name = validated_data.get('resource_name', None) contact_id = validated_data.get('contact_id', None) rd = [] - if book and contact_id: - try: - rd = ResourceDownload.objects.filter(account_uuid=account_uuid, book=book) - if resource_name: - rd.filter(resource_name=resource_name) - - rd = rd[0] # we only need the first result - but there might already be duplicates so this should handle that - rd.contact_id = contact_id - rd.save() - except (ResourceDownload.DoesNotExist, IndexError): - rd = ResourceDownload.objects.create(**validated_data) + try: + rd = ResourceDownload.objects.filter(account_uuid=account_uuid, book=book) + if resource_name: + rd.filter(resource_name=resource_name) + + rd = rd.first + rd.contact_id = contact_id + rd.save() + except (ResourceDownload.DoesNotExist, IndexError): + rd = ResourceDownload.objects.create(**validated_data) return rd From 71bc827f08b976c234aa1ac0faf4d1125eb33fb6 Mon Sep 17 00:00:00 2001 From: Michael Harrison Date: Wed, 13 Dec 2023 15:39:47 -0600 Subject: [PATCH 7/9] remove rejection test --- salesforce/tests.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/salesforce/tests.py b/salesforce/tests.py index 51dc553bd..43a91a2e4 100644 --- a/salesforce/tests.py +++ b/salesforce/tests.py @@ -213,24 +213,12 @@ def test_resource_download_post(self): locale=root_page.locale ) book_index.add_child(instance=book) - data = {"book": book.pk,"book_format": "PDF","account_uuid": "310bb96b-0df8-4d10-a759-c7d366c1f524", "resource_name": "Book PDF", "contact_id": "0032f00003zYVdSAAZ"} + data = { + "book": book.pk, + "book_format": "PDF", + "account_uuid": "310bb96b-0df8-4d10-a759-c7d366c1f524", + "resource_name": "Book PDF", + "contact_id": "0032f00003zYVdSAAZ" + } response = self.client.post('/apps/cms/api/salesforce/download-tracking/', data, format='json') self.assertEqual("PDF", response.data['book_format']) - - def test_resource_download_post_rejection(self): - root_page = Page.objects.get(title="Root") - book_index = BookIndex.objects.all()[0] - book = Book(title="Biology 2e", - slug="biology-2e", - cnx_id='031da8d3-b525-429c-80cf-6c8ed997744b', - salesforce_book_id='', - description="Test Book", - cover=self.test_doc, - title_image=self.test_doc, - publish_date=datetime.date.today(), - locale=root_page.locale - ) - book_index.add_child(instance=book) - data = {"book": book.pk,"book_format": "PDF","account_uuid": "310bb96b-0df8-4d10-a759-c7d366c1f524", "resource_name": "Book PDF", "contact_id": ""} - response = self.client.post('/apps/cms/api/salesforce/download-tracking/', data, format='json') - self.assertEqual(None, response.data['book']) From 407123ba70dee42632182b2c9bc1fe69dbfc4611 Mon Sep 17 00:00:00 2001 From: Michael Harrison Date: Wed, 13 Dec 2023 15:49:32 -0600 Subject: [PATCH 8/9] Require UUID, do not require resource name --- ..._resourcedownload_account_uuid_and_more.py | 23 +++++++++++++++++++ salesforce/models.py | 6 ++--- salesforce/serializers.py | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 salesforce/migrations/0107_alter_resourcedownload_account_uuid_and_more.py diff --git a/salesforce/migrations/0107_alter_resourcedownload_account_uuid_and_more.py b/salesforce/migrations/0107_alter_resourcedownload_account_uuid_and_more.py new file mode 100644 index 000000000..8375d0e47 --- /dev/null +++ b/salesforce/migrations/0107_alter_resourcedownload_account_uuid_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.1.7 on 2023-12-13 21:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("salesforce", "0106_remove_resourcedownload_salesforce__account_b11d37_idx_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="resourcedownload", + name="account_uuid", + field=models.UUIDField(default=""), + preserve_default=False, + ), + migrations.AlterField( + model_name="resourcedownload", + name="resource_name", + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] diff --git a/salesforce/models.py b/salesforce/models.py index b4fdc2412..148941cf5 100644 --- a/salesforce/models.py +++ b/salesforce/models.py @@ -388,12 +388,12 @@ class ResourceDownload(models.Model): ('Chegg Reader', 'Chegg Reader'), ) book = models.ForeignKey(Book, on_delete=models.SET_NULL, null=True, blank=True) - book_format = models.CharField(max_length=100, choices=BOOK_FORMATS, null=True , blank=True) - account_uuid = models.UUIDField(null=True) + book_format = models.CharField(max_length=100, choices=BOOK_FORMATS, null=True, blank=True) + account_uuid = models.UUIDField(null=False) created = models.DateTimeField(auto_now_add=True) edited = models.DateTimeField(auto_now=True) last_access = models.DateTimeField() - resource_name = models.CharField(max_length=255, null=True, blank=False) + resource_name = models.CharField(max_length=255, null=True, blank=True) contact_id = models.CharField(max_length=100, null=True, blank=True) class Meta: diff --git a/salesforce/serializers.py b/salesforce/serializers.py index c40723a87..3a06751e7 100644 --- a/salesforce/serializers.py +++ b/salesforce/serializers.py @@ -125,7 +125,7 @@ def create(self, validated_data): if resource_name: rd.filter(resource_name=resource_name) - rd = rd.first + rd = rd[0] rd.contact_id = contact_id rd.save() except (ResourceDownload.DoesNotExist, IndexError): From bd41feea500479e05e83872a724dfab4810c3327 Mon Sep 17 00:00:00 2001 From: Michael Harrison Date: Wed, 13 Dec 2023 15:53:59 -0600 Subject: [PATCH 9/9] set default uuid to something random --- .../0107_alter_resourcedownload_account_uuid_and_more.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salesforce/migrations/0107_alter_resourcedownload_account_uuid_and_more.py b/salesforce/migrations/0107_alter_resourcedownload_account_uuid_and_more.py index 8375d0e47..f464ac21a 100644 --- a/salesforce/migrations/0107_alter_resourcedownload_account_uuid_and_more.py +++ b/salesforce/migrations/0107_alter_resourcedownload_account_uuid_and_more.py @@ -12,7 +12,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name="resourcedownload", name="account_uuid", - field=models.UUIDField(default=""), + field=models.UUIDField(default="19d58898-0b29-488f-a35a-6288e3c0b44c"), preserve_default=False, ), migrations.AlterField(