# Path: homepage/forms.py
# class UnitChoiceForm(forms.Form):
#     unit_choice = forms.ChoiceField(
#         label='',
#         required=True,
#         choices=UNIT_CHOICES_DJANGO,
#         widget=forms.Select(attrs={'onchange': 'this.form.submit()'}),
#     )
# 
# Path: blockexplorer/settings.py
# DEFAULT_USER_UNIT = 'btc'


from homepage.forms import UnitChoiceForm
from blockexplorer.settings import DEFAULT_USER_UNIT
from blockcypher.constants import UNIT_CHOICES




# speedup since called on every pageload
UNIT_CHOICES_SET = set(UNIT_CHOICES)


def get_user_units(request):

    user_units = request.session.get('user_units')
    if not user_units:
        user_units = DEFAULT_USER_UNIT
        request.session['user_units'] = DEFAULT_USER_UNIT

    if user_units not in UNIT_CHOICES_SET:
        # shouldn't be possible, defensive check to fail gracefully

# Path: homepage/forms.py
# class UnitChoiceForm(forms.Form):
#     unit_choice = forms.ChoiceField(
#         label='',
#         required=True,
#         choices=UNIT_CHOICES_DJANGO,
#         widget=forms.Select(attrs={'onchange': 'this.form.submit()'}),
#     )
# 
# Path: blockexplorer/settings.py
# DEFAULT_USER_UNIT = 'btc'


# Path: blockexplorer/context_processors.py
from homepage.forms import UnitChoiceForm
from blockexplorer.settings import DEFAULT_USER_UNIT
from blockcypher.constants import UNIT_CHOICES





# speedup since called on every pageload
UNIT_CHOICES_SET = set(UNIT_CHOICES)


def get_user_units(request):

    user_units = request.session.get('user_units')
    if not user_units:
        user_units = DEFAULT_USER_UNIT
        request.session['user_units'] = DEFAULT_USER_UNIT

    if user_units not in UNIT_CHOICES_SET:
        # shouldn't be possible, defensive check to fail gracefully

        user_units = DEFAULT_USER_UNIT