# Path: sitegate/exceptions.py
# class SiteGateError(Exception):
#     """Exception class for sitesignup application."""


from typing import Optional
from django import template
from django.conf import settings
from django.template import Context
from django.template.base import Parser, Token
from etc.templatetags.etc_misc import include_
from ..exceptions import SiteGateError
register.tag('sitegate_include', include_)


class sitegate_flow_formNode(template.Node):
    """Base class for flow form nodes."""

    type: str = None

    def __init__(self, flow_name: Optional[str]):
        self.flow_name = flow_name

    def render(self, context: Context) -> str:
        try:
            forms = context['request'].sitegate[f'{self.type}_forms']

            if self.flow_name is None:
                try:  # Try to use modern sign up.
                    flow_form = forms['ModernSignup']

                except KeyError:  # Try to get the first sign up flow form variable from request.
                    flow_form = forms[list(forms.keys())[0]]

            else:
                flow_form = forms[self.flow_name]

        except (AttributeError, KeyError):  # WSGI request attribute error; forms dict error.
            flow_form = None

        if flow_form is None:
            if settings.DEBUG:

# Path: sitegate/exceptions.py
# class SiteGateError(Exception):
#     """Exception class for sitesignup application."""


# Path: sitegate/templatetags/sitegate.py
from typing import Optional
from django import template
from django.conf import settings
from django.template import Context
from django.template.base import Parser, Token
from etc.templatetags.etc_misc import include_
from ..exceptions import SiteGateError

register.tag('sitegate_include', include_)


class sitegate_flow_formNode(template.Node):
    """Base class for flow form nodes."""

    type: str = None

    def __init__(self, flow_name: Optional[str]):
        self.flow_name = flow_name

    def render(self, context: Context) -> str:
        try:
            forms = context['request'].sitegate[f'{self.type}_forms']

            if self.flow_name is None:
                try:  # Try to use modern sign up.
                    flow_form = forms['ModernSignup']

                except KeyError:  # Try to get the first sign up flow form variable from request.
                    flow_form = forms[list(forms.keys())[0]]

            else:
                flow_form = forms[self.flow_name]

        except (AttributeError, KeyError):  # WSGI request attribute error; forms dict error.
            flow_form = None

        if flow_form is None:
            if settings.DEBUG:

                raise SiteGateError(