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

Keep track of current sponsorship year #2087

Merged
merged 52 commits into from Aug 5, 2022
Merged

Conversation

berinhard
Copy link
Collaborator

@berinhard berinhard commented Jul 30, 2022

Fixes #2084

This PR introduces a new singleton model in the sponsors app called SponsorshipCurrentYear. This model is used to keep rack of the current application year.

I wanted to not use Django to manage the singleton because I felt it would make the Python code more complex. Instead, I left this responsibility to Postgres. I did so by adding an unique index on a constant value in this new table. By doing that, the only changes required in Django were to disable deletion and addition for this new model. Even though the singleton is implemented in Postgres, this PR adds Django unit tests to ensure it's working. This PR also introduces an initial data migration to populate the singleton and to set the year to 2023.

Then, a new year indexed column was added to the following models: Sponsorship, SponsorshipPackage and SponsorshipBenefit. The first one represents the sponsorship application itself, while the others are used as configuration models used by application to properly populate its related objects. The year of the sponsorship gets populated when it gets created using the value from SponsorshipCurrentYear.get_year. The year for the configuration models can be edit via Django admin, but this PR introduces an initial migration to populate them with 2023.

The queries to list packages, their benefits, add-ons and a la carte benefits in the sponsorship application form were updated to only return configured objects from the current year. That way, we can customize the whole sponsorship application form by year.

It's worthwhile to mention that the SponsorshipCurrentYear.get_year has a cache policy to avoid repeated and unnecessary db hits to fetch for the year value. The cached value, when populated, is set to never expire. But, when the year gets updated in the database, the save method invalidates the existing cache. So, that way, the cache will get populated again with the new value once SponsorshipCurrentYear.get_year is called again.

berinhard added 28 commits Jul 28, 2022
…xecution time instead of interpretation's one
@berinhard berinhard requested a review from ewdurbin Jul 30, 2022
@berinhard
Copy link
Collaborator Author

berinhard commented Jul 30, 2022

@ewdurbin I didn't manage to test this PR via the web interface. I still couldn't load the data for the sponsors app using the dump JSON files you sent me, but we can talk about this topic next Monday.

@ewdurbin ewdurbin force-pushed the feature/sponsorship-year branch from ba2db7a to 26d1b56 Compare Aug 1, 2022
berinhard added 22 commits Aug 2, 2022
@berinhard
Copy link
Collaborator Author

berinhard commented Aug 4, 2022

@ewdurbin I guess now we have the whole workflow implemented. I managed to test the whole process of cloning an sponsorship application, updating the new year's benefits info, previewing it and everything work smoothly. I'm adding a few screen shots here to guide you through you own QA:

1 - Clone by year

You can access the following page via admin going to Sponsors > Active Yer and then clicking on the button "Clone Application Configuraton".

Screenshot from 2022-08-04 17-55-47

After submiting the form, the same page will be displayed for you with the links to the benefits and packages from the new configured year in the list of already configured years:

Screenshot from 2022-08-04 17-55-43

2 - Customizing the configuration for the year

You can change benefits and package information for that year. You can access them directly from the filter URLs displayed in the Active Year as the screen shot bellow shows:

Screenshot from 2022-08-04 20-00-23

3 - Previewing the form from a specific year

As you can see, the previous page also lists a link to preview the application form for those years. I'm using the same URL as the current one, but with an extra querystring parameter called config_year that only gets evaluated if the user is a staff one. Also, as you can see bellow, I added a warning message so the staff user can now it's a preview mode:

Screenshot from 2022-08-04 19-35-33

@ewdurbin
Copy link
Member

ewdurbin commented Aug 5, 2022

This is stellar work @berinhard I pushed one minor tweak to make the preview a little more obvious.

Otherwise, I was able to test this with a full prod dataset for sponsorship and it is 💯

@ewdurbin ewdurbin merged commit 723539e into main Aug 5, 2022
2 checks passed
@ewdurbin ewdurbin deleted the feature/sponsorship-year branch Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add some way of tracking "Sponsorship Year" to Sponsorship objects.
2 participants