# Path: registration/models.py
# class Member(models.Model):
#     involvement_choices = (
#         ('21cd9799b6', 'General (receive email)'),
#         ('3a5a719017', 'Volunteering'),
#         ('0ebb0b5468', 'Events'),
#         ('84309225e7', 'Workshops'),
#         ('c96d389517', 'Shop'),
#     )
# 
#     user = models.OneToOneField(CustomUser, on_delete=models.CASCADE,
#                                 null=True, blank=True)
#     email = models.EmailField(
#         verbose_name='email address',
#         max_length=255,
#         unique=False,
#         null=True,
#         blank=True,
#         )
#     email_consent = models.BooleanField(default=False, blank=False)
#     first_name = models.CharField(max_length=255, null=False, blank=False)
#     last_name = models.CharField(max_length=255, null=False, blank=False)
#     preferred_name = models.CharField(max_length=255, null=True, blank=True)
#     date_of_birth = models.DateField(null=True, blank=True)
#     guardian_name = models.CharField(max_length=255, null=True, blank=True)
#     phone = models.CharField(max_length=20, null=True, blank=True)
#     street = models.CharField(max_length=255, null=True, blank=True)
#     city = models.CharField(max_length=255, null=True, blank=True)
#     province = models.CharField(max_length=255, null=True, blank=True)
#     country = models.CharField(max_length=255, null=True, blank=True)
#     post_code = models.CharField(max_length=20, null=True, blank=False)
#     waiver = models.DateTimeField(null=True, blank=True)
#     is_active = models.BooleanField(default=True)
#     notes = models.TextField(null=True, blank=True)
#     suspended = models.BooleanField(default=False)
#     banned = models.BooleanField(default=False)
#     created_at = models.DateTimeField(auto_now_add=True)
#     modified_at = models.DateTimeField(auto_now=True)
#     involvement = MultiSelectField(choices=involvement_choices, null=True, blank=True)
# 
#     @property
#     def full_name(self):
#         return self.get_full_name()
# 
#     def get_full_name(self):
#         # The user is identified by their email address
#         return '{0} {1}'.format(self.first_name, self.last_name)
# 
#     def get_short_name(self):
#         # The user is identified by their email address
#         if self.email:
#             return self.email
#         else:
#             return self.last_name
# 
#     def __str__(self):              # __unicode__ on Python 2
#         return self.email
# 
# Path: core/models.py
# class Membership(models.Model):
#     created_at = models.DateTimeField(auto_now_add=True)
#     modified_at = models.DateTimeField(auto_now=True)
#     renewed_at = models.DateTimeField(default=timezone.now)
#     self_identification = models.CharField(max_length=255, null=True, blank=True)
#     gender = models.CharField(max_length=255, null=True, blank=True)
#     involvement = models.CharField(max_length=255, null=True, blank=True)
#     member = models.ForeignKey(
#         'registration.Member',
#         on_delete=models.CASCADE,
#         related_name='memberships',
#         blank=True,
#         null=True
#     )
#     payment = models.OneToOneField(
#         'Payment',
#         on_delete=models.CASCADE,
#         related_name='membership',
#         blank=False,
#         null=True
#     )
# 
#     @cached_property
#     def expires_at(self):
#         return self.renewed_at + relativedelta(years=1)
# 
# class Payment(models.Model):
#     payment_choices = (
#         ('NONE', 'None'),
#         ('CASH', 'Cash'),
#         ('CHEQUE', 'Cheque'),
#         ('VOLUNTEERING', 'Volunteering'),
#         ('SQUARE', 'Square'),
#         ('PAYPAL', 'PayPal'),
#         ('YOUTH', 'Youth'),
#         ('UNKNOWN', 'Unknown')
#     )
#     type = models.CharField(max_length=12, choices=payment_choices, default='NONE')
#     created_at = models.DateTimeField(auto_now_add=True)


import logging
from django.forms import BooleanField, CharField, CheckboxInput, RadioSelect, ModelForm, TextInput, HiddenInput
from registration.models import Member
from .models import Membership, Payment
            ('other', 'Other')
        )

        widgets = {
            'self_identification': RadioSelect(choices=self_ident_choices, attrs={'class': 'mdl-radio__button'}),
            'gender': RadioSelect(choices=gender_choices, attrs={'class': 'mdl-radio__button'}),
            'renewed_at': TextInput(attrs={'class': 'mdl-textfield__input'}),
        }

    def save(self, commit=True):
        instance = super(MembershipForm, self).save(commit=False)
        member = Member.objects.get(id=self.cleaned_data['member'])
        instance.member = member
        logger.debug(self.cleaned_data['self_identification'])
        logger.debug(self.cleaned_data['gender'])

        if self.cleaned_data['gender_other']:
            instance.gender = self.cleaned_data['gender_other']

        if self.cleaned_data['self_ident_other']:
            instance.self_identification = self.cleaned_data['self_ident_other']

        if commit:
            instance.save()

        return instance


class PaymentForm(ModelForm):
    class Meta:

# Path: registration/models.py
# class Member(models.Model):
#     involvement_choices = (
#         ('21cd9799b6', 'General (receive email)'),
#         ('3a5a719017', 'Volunteering'),
#         ('0ebb0b5468', 'Events'),
#         ('84309225e7', 'Workshops'),
#         ('c96d389517', 'Shop'),
#     )
# 
#     user = models.OneToOneField(CustomUser, on_delete=models.CASCADE,
#                                 null=True, blank=True)
#     email = models.EmailField(
#         verbose_name='email address',
#         max_length=255,
#         unique=False,
#         null=True,
#         blank=True,
#         )
#     email_consent = models.BooleanField(default=False, blank=False)
#     first_name = models.CharField(max_length=255, null=False, blank=False)
#     last_name = models.CharField(max_length=255, null=False, blank=False)
#     preferred_name = models.CharField(max_length=255, null=True, blank=True)
#     date_of_birth = models.DateField(null=True, blank=True)
#     guardian_name = models.CharField(max_length=255, null=True, blank=True)
#     phone = models.CharField(max_length=20, null=True, blank=True)
#     street = models.CharField(max_length=255, null=True, blank=True)
#     city = models.CharField(max_length=255, null=True, blank=True)
#     province = models.CharField(max_length=255, null=True, blank=True)
#     country = models.CharField(max_length=255, null=True, blank=True)
#     post_code = models.CharField(max_length=20, null=True, blank=False)
#     waiver = models.DateTimeField(null=True, blank=True)
#     is_active = models.BooleanField(default=True)
#     notes = models.TextField(null=True, blank=True)
#     suspended = models.BooleanField(default=False)
#     banned = models.BooleanField(default=False)
#     created_at = models.DateTimeField(auto_now_add=True)
#     modified_at = models.DateTimeField(auto_now=True)
#     involvement = MultiSelectField(choices=involvement_choices, null=True, blank=True)
# 
#     @property
#     def full_name(self):
#         return self.get_full_name()
# 
#     def get_full_name(self):
#         # The user is identified by their email address
#         return '{0} {1}'.format(self.first_name, self.last_name)
# 
#     def get_short_name(self):
#         # The user is identified by their email address
#         if self.email:
#             return self.email
#         else:
#             return self.last_name
# 
#     def __str__(self):              # __unicode__ on Python 2
#         return self.email
# 
# Path: core/models.py
# class Membership(models.Model):
#     created_at = models.DateTimeField(auto_now_add=True)
#     modified_at = models.DateTimeField(auto_now=True)
#     renewed_at = models.DateTimeField(default=timezone.now)
#     self_identification = models.CharField(max_length=255, null=True, blank=True)
#     gender = models.CharField(max_length=255, null=True, blank=True)
#     involvement = models.CharField(max_length=255, null=True, blank=True)
#     member = models.ForeignKey(
#         'registration.Member',
#         on_delete=models.CASCADE,
#         related_name='memberships',
#         blank=True,
#         null=True
#     )
#     payment = models.OneToOneField(
#         'Payment',
#         on_delete=models.CASCADE,
#         related_name='membership',
#         blank=False,
#         null=True
#     )
# 
#     @cached_property
#     def expires_at(self):
#         return self.renewed_at + relativedelta(years=1)
# 
# class Payment(models.Model):
#     payment_choices = (
#         ('NONE', 'None'),
#         ('CASH', 'Cash'),
#         ('CHEQUE', 'Cheque'),
#         ('VOLUNTEERING', 'Volunteering'),
#         ('SQUARE', 'Square'),
#         ('PAYPAL', 'PayPal'),
#         ('YOUTH', 'Youth'),
#         ('UNKNOWN', 'Unknown')
#     )
#     type = models.CharField(max_length=12, choices=payment_choices, default='NONE')
#     created_at = models.DateTimeField(auto_now_add=True)


# Path: core/forms.py
import logging
from django.forms import BooleanField, CharField, CheckboxInput, RadioSelect, ModelForm, TextInput, HiddenInput
from registration.models import Member
from .models import Membership, Payment

            ('other', 'Other')
        )

        widgets = {
            'self_identification': RadioSelect(choices=self_ident_choices, attrs={'class': 'mdl-radio__button'}),
            'gender': RadioSelect(choices=gender_choices, attrs={'class': 'mdl-radio__button'}),
            'renewed_at': TextInput(attrs={'class': 'mdl-textfield__input'}),
        }

    def save(self, commit=True):
        instance = super(MembershipForm, self).save(commit=False)
        member = Member.objects.get(id=self.cleaned_data['member'])
        instance.member = member
        logger.debug(self.cleaned_data['self_identification'])
        logger.debug(self.cleaned_data['gender'])

        if self.cleaned_data['gender_other']:
            instance.gender = self.cleaned_data['gender_other']

        if self.cleaned_data['self_ident_other']:
            instance.self_identification = self.cleaned_data['self_ident_other']

        if commit:
            instance.save()

        return instance


class PaymentForm(ModelForm):
    class Meta:

        model = Payment