From 38be7ae95ccc778345d44d97d8da4fe0b7488653 Mon Sep 17 00:00:00 2001 From: ed woodward Date: Fri, 17 Nov 2023 09:03:59 -0600 Subject: [PATCH] Added source field to Thank You Note --- .../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 = [ + ]