import django_filters
from django import forms
from django.core.mail import send_mail

from webstore.core.widgets import MaterializeCheckboxInput
from webstore.payment.models import Payment
from webstore.order.models import OrderStatus


class FilterPaymentForm(django_filters.FilterSet):
    created_before = django_filters.DateFilter(
        field_name='created',
        lookup_expr='lte',
        label='Created before',
    )
    created_after = django_filters.DateFilter(
        field_name='created',
        lookup_expr='gte',
        label='Created after',
    )
    value_gte = django_filters.NumberFilter(
        field_name='value',
        lookup_expr='gte',
        label='value greater than',
    )
    value_lte = django_filters.NumberFilter(
        field_name='value',
        lookup_expr='lte',
        label='value less than',
    )

    class Meta:
        model = Payment
        fields = [
            'payed',
        ]


class UpdatePaymentForm(forms.ModelForm):
    send_mail = forms.BooleanField(
        label='Send mail to client',
        required=False,
        widget=MaterializeCheckboxInput(
            attrs={
                'class': 'filled-in',
                'checked': 'checked',
            }
        )
    )

    payed = forms.BooleanField(
        label='Payment recived',
        required=False,
        widget=MaterializeCheckboxInput(
            attrs={
                'class': 'filled-in',
                'checked': 'checked',
            }
        )
    )

    class Meta:
        model = Payment
        fields = [
            'payed',
        ]

    def save(self, commit=True):
        object = super().save(commit)
        send_mail_flag = self.cleaned_data.get('send_mail')
        if object.payed is True and self.order.status == OrderStatus.AWAITING_PAYMENT.name:
            self.order.status = OrderStatus.SHIPPING.name
            self.order.save()
        if send_mail_flag is True:
            send_mail(
                subject='Payment status for order: {}'.format(object.order.id),
                message='Payment status was updated to: {}'.format(object.status),
                from_email='placeholder@test.com',
                recipient_list=[object.order.user.email],
                fail_silently=False,
            )
        return object

    def __init__(self, *args, **kwargs):
        self.order = kwargs.pop('order')
        super(UpdatePaymentForm, self).__init__(*args, **kwargs)

4dfc782be7fc0d2135d064bc18df3151c5c93ee3
<mask token>


class UpdatePaymentForm(forms.ModelForm):
    <mask token>
    <mask token>


    class Meta:
        model = Payment
        fields = ['payed']

    def save(self, commit=True):
        object = super().save(commit)
        send_mail_flag = self.cleaned_data.get('send_mail')
        if (object.payed is True and self.order.status == OrderStatus.
            AWAITING_PAYMENT.name):
            self.order.status = OrderStatus.SHIPPING.name
            self.order.save()
        if send_mail_flag is True:
            send_mail(subject='Payment status for order: {}'.format(object.
                order.id), message='Payment status was updated to: {}'.
                format(object.status), from_email='placeholder@test.com',
                recipient_list=[object.order.user.email], fail_silently=False)
        return object

    def __init__(self, *args, **kwargs):
        self.order = kwargs.pop('order')
        super(UpdatePaymentForm, self).__init__(*args, **kwargs)

<mask token>


class FilterPaymentForm(django_filters.FilterSet):
    <mask token>
    <mask token>
    <mask token>
    <mask token>


    class Meta:
        model = Payment
        fields = ['payed']


class UpdatePaymentForm(forms.ModelForm):
    send_mail = forms.BooleanField(label='Send mail to client', required=
        False, widget=MaterializeCheckboxInput(attrs={'class': 'filled-in',
        'checked': 'checked'}))
    payed = forms.BooleanField(label='Payment recived', required=False,
        widget=MaterializeCheckboxInput(attrs={'class': 'filled-in',
        'checked': 'checked'}))


    class Meta:
        model = Payment
        fields = ['payed']

    def save(self, commit=True):
        object = super().save(commit)
        send_mail_flag = self.cleaned_data.get('send_mail')
        if (object.payed is True and self.order.status == OrderStatus.
            AWAITING_PAYMENT.name):
            self.order.status = OrderStatus.SHIPPING.name
            self.order.save()
        if send_mail_flag is True:
            send_mail(subject='Payment status for order: {}'.format(object.
                order.id), message='Payment status was updated to: {}'.
                format(object.status), from_email='placeholder@test.com',
                recipient_list=[object.order.user.email], fail_silently=False)
        return object

    def __init__(self, *args, **kwargs):
        self.order = kwargs.pop('order')
        super(UpdatePaymentForm, self).__init__(*args, **kwargs)

<mask token>


class FilterPaymentForm(django_filters.FilterSet):
    created_before = django_filters.DateFilter(field_name='created',
        lookup_expr='lte', label='Created before')
    created_after = django_filters.DateFilter(field_name='created',
        lookup_expr='gte', label='Created after')
    value_gte = django_filters.NumberFilter(field_name='value', lookup_expr
        ='gte', label='value greater than')
    value_lte = django_filters.NumberFilter(field_name='value', lookup_expr
        ='lte', label='value less than')


    class Meta:
        model = Payment
        fields = ['payed']


class UpdatePaymentForm(forms.ModelForm):
    send_mail = forms.BooleanField(label='Send mail to client', required=
        False, widget=MaterializeCheckboxInput(attrs={'class': 'filled-in',
        'checked': 'checked'}))
    payed = forms.BooleanField(label='Payment recived', required=False,
        widget=MaterializeCheckboxInput(attrs={'class': 'filled-in',
        'checked': 'checked'}))


    class Meta:
        model = Payment
        fields = ['payed']

    def save(self, commit=True):
        object = super().save(commit)
        send_mail_flag = self.cleaned_data.get('send_mail')
        if (object.payed is True and self.order.status == OrderStatus.
            AWAITING_PAYMENT.name):
            self.order.status = OrderStatus.SHIPPING.name
            self.order.save()
        if send_mail_flag is True:
            send_mail(subject='Payment status for order: {}'.format(object.
                order.id), message='Payment status was updated to: {}'.
                format(object.status), from_email='placeholder@test.com',
                recipient_list=[object.order.user.email], fail_silently=False)
        return object

    def __init__(self, *args, **kwargs):
        self.order = kwargs.pop('order')
        super(UpdatePaymentForm, self).__init__(*args, **kwargs)

import django_filters
from django import forms
from django.core.mail import send_mail
from webstore.core.widgets import MaterializeCheckboxInput
from webstore.payment.models import Payment
from webstore.order.models import OrderStatus


class FilterPaymentForm(django_filters.FilterSet):
    created_before = django_filters.DateFilter(field_name='created',
        lookup_expr='lte', label='Created before')
    created_after = django_filters.DateFilter(field_name='created',
        lookup_expr='gte', label='Created after')
    value_gte = django_filters.NumberFilter(field_name='value', lookup_expr
        ='gte', label='value greater than')
    value_lte = django_filters.NumberFilter(field_name='value', lookup_expr
        ='lte', label='value less than')


    class Meta:
        model = Payment
        fields = ['payed']


class UpdatePaymentForm(forms.ModelForm):
    send_mail = forms.BooleanField(label='Send mail to client', required=
        False, widget=MaterializeCheckboxInput(attrs={'class': 'filled-in',
        'checked': 'checked'}))
    payed = forms.BooleanField(label='Payment recived', required=False,
        widget=MaterializeCheckboxInput(attrs={'class': 'filled-in',
        'checked': 'checked'}))


    class Meta:
        model = Payment
        fields = ['payed']

    def save(self, commit=True):
        object = super().save(commit)
        send_mail_flag = self.cleaned_data.get('send_mail')
        if (object.payed is True and self.order.status == OrderStatus.
            AWAITING_PAYMENT.name):
            self.order.status = OrderStatus.SHIPPING.name
            self.order.save()
        if send_mail_flag is True:
            send_mail(subject='Payment status for order: {}'.format(object.
                order.id), message='Payment status was updated to: {}'.
                format(object.status), from_email='placeholder@test.com',
                recipient_list=[object.order.user.email], fail_silently=False)
        return object

    def __init__(self, *args, **kwargs):
        self.order = kwargs.pop('order')
        super(UpdatePaymentForm, self).__init__(*args, **kwargs)

import django_filters
from django import forms
from django.core.mail import send_mail

from webstore.core.widgets import MaterializeCheckboxInput
from webstore.payment.models import Payment
from webstore.order.models import OrderStatus


class FilterPaymentForm(django_filters.FilterSet):
    created_before = django_filters.DateFilter(
        field_name='created',
        lookup_expr='lte',
        label='Created before',
    )
    created_after = django_filters.DateFilter(
        field_name='created',
        lookup_expr='gte',
        label='Created after',
    )
    value_gte = django_filters.NumberFilter(
        field_name='value',
        lookup_expr='gte',
        label='value greater than',
    )
    value_lte = django_filters.NumberFilter(
        field_name='value',
        lookup_expr='lte',
        label='value less than',
    )

    class Meta:
        model = Payment
        fields = [
            'payed',
        ]


class UpdatePaymentForm(forms.ModelForm):
    send_mail = forms.BooleanField(
        label='Send mail to client',
        required=False,
        widget=MaterializeCheckboxInput(
            attrs={
                'class': 'filled-in',
                'checked': 'checked',
            }
        )
    )

    payed = forms.BooleanField(
        label='Payment recived',
        required=False,
        widget=MaterializeCheckboxInput(
            attrs={
                'class': 'filled-in',
                'checked': 'checked',
            }
        )
    )

    class Meta:
        model = Payment
        fields = [
            'payed',
        ]

    def save(self, commit=True):
        object = super().save(commit)
        send_mail_flag = self.cleaned_data.get('send_mail')
        if object.payed is True and self.order.status == OrderStatus.AWAITING_PAYMENT.name:
            self.order.status = OrderStatus.SHIPPING.name
            self.order.save()
        if send_mail_flag is True:
            send_mail(
                subject='Payment status for order: {}'.format(object.order.id),
                message='Payment status was updated to: {}'.format(object.status),
                from_email='placeholder@test.com',
                recipient_list=[object.order.user.email],
                fail_silently=False,
            )
        return object

    def __init__(self, *args, **kwargs):
        self.order = kwargs.pop('order')
        super(UpdatePaymentForm, self).__init__(*args, **kwargs)
