Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
f0ef002e
Commit
f0ef002e
authored
3 years ago
by
jan.bednarik
Browse files
Options
Downloads
Patches
Plain Diff
czech inspirational: Newsletter subscribe refactoring
parent
2d7f1805
No related branches found
No related tags found
2 merge requests
!263
release
,
!262
Volby
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
czech_inspirational/models.py
+5
-19
5 additions, 19 deletions
czech_inspirational/models.py
majak/settings/base.py
+8
-0
8 additions, 0 deletions
majak/settings/base.py
shared/utils.py
+25
-0
25 additions, 0 deletions
shared/utils.py
with
38 additions
and
19 deletions
czech_inspirational/models.py
+
5
−
19
View file @
f0ef002e
import
json
import
logging
import
requests
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.core.validators
import
validate_email
from
django.core.validators
import
validate_email
...
@@ -20,11 +16,10 @@ from wagtail.images.edit_handlers import ImageChooserPanel
...
@@ -20,11 +16,10 @@ from wagtail.images.edit_handlers import ImageChooserPanel
from
wagtailmetadata.models
import
MetadataPageMixin
from
wagtailmetadata.models
import
MetadataPageMixin
from
shared.models
import
SubpageMixin
from
shared.models
import
SubpageMixin
from
shared.utils
import
subscribe_to_newsletter
from
tuning
import
help
from
tuning
import
help
from
uniweb.constants
import
RICH_TEXT_FEATURES
from
uniweb.constants
import
RICH_TEXT_FEATURES
logger
=
logging
.
getLogger
()
class
CzechInspirationalHomePage
(
Page
,
MetadataPageMixin
):
class
CzechInspirationalHomePage
(
Page
,
MetadataPageMixin
):
### FIELDS
### FIELDS
...
@@ -285,19 +280,10 @@ class CzechInspirationalDownloadPage(Page, SubpageMixin, MetadataPageMixin):
...
@@ -285,19 +280,10 @@ class CzechInspirationalDownloadPage(Page, SubpageMixin, MetadataPageMixin):
except
ValidationError
:
except
ValidationError
:
pass
pass
else
:
else
:
payload
=
{
subscribe_to_newsletter
(
"
email
"
:
email
,
email
,
"
news_id
"
:
settings
.
CZECH_INSPIRATIONAL_NEWSLETTER_ID
,
settings
.
CZECH_INSPIRATIONAL_NEWSLETTER_ID
,
}
settings
.
CZECH_INSPIRATIONAL_NEWSLETTER_SOURCE
,
response
=
requests
.
post
(
settings
.
NALODENI_API_NEWS_SUBSCRIBE_URL
,
data
=
json
.
dumps
(
payload
),
auth
=
tuple
(
settings
.
NALODENI_API_CREDENTIALS
.
split
(
"
:
"
)),
)
)
if
response
.
status_code
!=
200
:
logger
.
error
(
"
Failed to subscribe!
"
,
extra
=
{
"
email
"
:
email
,
"
response
"
:
response
.
text
},
)
return
context
return
context
This diff is collapsed.
Click to expand it.
majak/settings/base.py
+
8
−
0
View file @
f0ef002e
...
@@ -254,7 +254,15 @@ DONATE_PORTAL_API_CACHE_TIMEOUT = 60 * 5
...
@@ -254,7 +254,15 @@ DONATE_PORTAL_API_CACHE_TIMEOUT = 60 * 5
CZECH_INSPIRATIONAL_NEWSLETTER_ID
=
env
.
int
(
CZECH_INSPIRATIONAL_NEWSLETTER_ID
=
env
.
int
(
"
CZECH_INSPIRATIONAL_NEWSLETTER_ID
"
,
default
=
0
"
CZECH_INSPIRATIONAL_NEWSLETTER_ID
"
,
default
=
0
)
)
CZECH_INSPIRATIONAL_NEWSLETTER_SOURCE
=
env
.
str
(
"
CZECH_INSPIRATIONAL_NEWSLETTER_SOURCE
"
,
default
=
"
Česko inspirativní
"
)
NALODENI_API_NEWS_SUBSCRIBE_URL
=
env
.
str
(
"
NALODENI_API_NEWS_SUBSCRIBE_URL
"
,
default
=
""
)
NALODENI_API_NEWS_SUBSCRIBE_URL
=
env
.
str
(
"
NALODENI_API_NEWS_SUBSCRIBE_URL
"
,
default
=
""
)
NALODENI_API_CREDENTIALS
=
env
.
str
(
"
NALODENI_API_CREDENTIALS
"
,
default
=
""
)
NALODENI_API_CREDENTIALS
=
env
.
str
(
"
NALODENI_API_CREDENTIALS
"
,
default
=
""
)
ELECTIONS2021_COOKIE_NAME
=
"
program
"
ELECTIONS2021_COOKIE_NAME
=
"
program
"
ELECTIONS2021_NEWSLETTER_ID
=
env
.
int
(
"
ELECTIONS2021_NEWSLETTER_ID
"
,
default
=
0
)
ELECTIONS2021_NEWSLETTER_SOURCE
=
env
.
str
(
"
ELECTIONS2021_NEWSLETTER_SOURCE
"
,
"
Koalice 2021
"
)
This diff is collapsed.
Click to expand it.
shared/utils.py
+
25
−
0
View file @
f0ef002e
import
json
import
logging
import
requests
from
django.conf
import
settings
from
wagtail.core.models
import
Page
from
wagtail.core.models
import
Page
logger
=
logging
.
getLogger
()
def
get_subpage_url
(
page
,
dest_page_type
):
def
get_subpage_url
(
page
,
dest_page_type
):
try
:
try
:
return
page
.
get_descendants
().
type
(
dest_page_type
).
live
().
first
().
get_url
()
return
page
.
get_descendants
().
type
(
dest_page_type
).
live
().
first
().
get_url
()
except
(
Page
.
DoesNotExist
,
AttributeError
):
except
(
Page
.
DoesNotExist
,
AttributeError
):
return
"
#
"
return
"
#
"
def
subscribe_to_newsletter
(
email
,
news_id
,
source
):
payload
=
{
"
email
"
:
email
,
"
news_id
"
:
news_id
,
"
source
"
:
source
,
}
response
=
requests
.
post
(
settings
.
NALODENI_API_NEWS_SUBSCRIBE_URL
,
data
=
json
.
dumps
(
payload
),
auth
=
tuple
(
settings
.
NALODENI_API_CREDENTIALS
.
split
(
"
:
"
)),
)
if
response
.
status_code
!=
200
:
logger
.
error
(
"
Failed to subscribe!
"
,
extra
=
{
"
payload
"
:
payload
,
"
response
"
:
response
.
text
},
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment