forked from ZcashFoundation/zebra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Members-only content confactor (ZcashFoundation#142)
Co-authored-by: Jonathan Bird <[email protected]>
- Loading branch information
Showing
17 changed files
with
228 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.12 on 2023-04-22 01:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('g12f', '0067_zpage_publish_at'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='zpage', | ||
name='is_subscriber_only', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from rest_framework.views import exception_handler | ||
from rest_framework.exceptions import APIException | ||
from ..serializers import zPageDetailSerializer | ||
|
||
# custom exception handler can be used to trigger a modal on a zPage | ||
|
||
|
||
class RedirectWithModalException(APIException): | ||
status_code = 200 | ||
default_detail = "This is a custom redirect exception with modal flag." | ||
default_code = "redirect_with_modal" | ||
|
||
def __init__(self, page, show_modal=True): | ||
self.show_modal = show_modal | ||
self.page = page | ||
super().__init__(self.default_detail, self.default_code) | ||
|
||
|
||
def custom_exception_handler(exc, context): | ||
response = exception_handler(exc, context) | ||
|
||
if isinstance(exc, RedirectWithModalException): | ||
# Swap out the content so that an intrepid person can't | ||
# pull it out of the response | ||
exc.page.content = "Subscribe for exclusive content" | ||
page_serializer = zPageDetailSerializer(instance=exc.page) | ||
|
||
response.data = { | ||
'show_modal': exc.show_modal, | ||
'page': page_serializer.data | ||
} | ||
|
||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.