NewsletterController (controllers/newsletter_controller.py)

python-for-entrepreneurs-course-demos · 15-deployment/blue_yellow_app_deployment/blue_yellow_app/controllers/newsletter_controller.py · python · MIT
email

Pyramid controller handling newsletter subscription actions and rendering templates.

# Source: https://github.com/mikeckennedy/python-for-entrepreneurs-course-demos | License: MIT | Copyright 2016 Michael Kennedy
# Provided via justclaw.it.com; keep this notice with the code.
import pyramid_handlers
from blue_yellow_app.controllers.base_controller import BaseController
from blue_yellow_app.services.mailinglist_service import MailingListService


class NewsletterController(BaseController):
    # POST /newsletter/add_subscriber
    @pyramid_handlers.action(request_method='POST')
    def add_subscriber(self):
        email = self.data_dict.get('email')

        if MailingListService.add_subscriber(email):
            self.redirect('/newsletter/subscribed')

        self.redirect('/newsletter/failed')

    @pyramid_handlers.action(renderer='templates/newsletter/subscribed.pt')

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key