|
@@ -0,0 +1,23 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+
|
|
|
+from django.forms import ModelForm
|
|
|
+from django.db.models import Q
|
|
|
+
|
|
|
+from coin.offers.models import OfferSubscription
|
|
|
+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 = Q(offer__backend="openvpn_ldap") & (
|
|
|
+ # Select "unassociated" subscriptions, plus our own
|
|
|
+ # subscription (in case we are editing the object).
|
|
|
+ Q(("openvpn_ldap", None)) | Q(("openvpn_ldap", self.instance.pk)))
|
|
|
+ queryset = OfferSubscription.objects.filter(query)
|
|
|
+ self.fields['administrative_subscription'].queryset = queryset
|