# -*- coding: utf-8 -*-

from django.forms import ModelForm

from coin.offers.models import OfferSubscription
from coin.offers.backends import filter_subscriptions
from coin.vpn.models import VPNSubscription


class VPNSubscriptionForm(ModelForm):

    class Meta:
        model = VPNSubscription

    def __init__(self, *args, **kwargs):
        super(VPNSubscriptionForm, self).__init__(*args, **kwargs)
        if self.instance:
            query = filter_subscriptions(self.instance.backend_name,
                                         self.instance)
            queryset = OfferSubscription.objects.filter(query)
            self.fields['administrative_subscription'].queryset = queryset
