Ejemplo n.º 1
0
    def save(self):
        if not self.is_valid():
            raise Exception('The form must be valid in order to save')
        name = self.cleaned_data['name']
        package = self.cleaned_data['package']
        resource = self.cleaned_data['resource']
        allowance = self.cleaned_data['allowance']
        monthly_rate = self.cleaned_data['monthly_rate']
        overage_rate = self.cleaned_data['overage_rate']
        enabled = self.cleaned_data['enabled']
        delete = self.cleaned_data['delete']

        if enabled == 'False':
            enabled = False
        else:
            enabled = True

        if self.cleaned_data['sub_id']:
            p = MembershipPackage.objects.get(id=package)
            p.enabled = enabled
            p.save()

            sub_default = SubscriptionDefault.objects.get(
                id=self.cleaned_data['sub_id'])
            if delete == True:
                sub_default.delete()
            else:
                sub_default.allowance = allowance
                sub_default.monthly_rate = monthly_rate
                sub_default.overage_rate = overage_rate
                sub_default.save()
        else:
            if MembershipPackage.objects.filter(name=name):
                raise Exception(
                    'A membership package with this name already exists.')
            if package:
                p = MembershipPackage.objects.get(id=package)
                p.enabled = enabled
                p.save()
            else:
                p = MembershipPackage(name=name, enabled=enabled)
                p.save()

            sub_default = SubscriptionDefault(package=p,
                                              resource=resource,
                                              allowance=allowance,
                                              monthly_rate=monthly_rate,
                                              overage_rate=overage_rate)
            print(('Default is %s' % sub_default))
            sub_default.save()

        return sub_default
Ejemplo n.º 2
0
    def save(self):
        if not self.is_valid():
            raise Exception('The form must be valid in order to save')
        name = self.cleaned_data['name']
        package = self.cleaned_data['package']
        resource = self.cleaned_data['resource']
        allowance = self.cleaned_data['allowance']
        monthly_rate = self.cleaned_data['monthly_rate']
        overage_rate = self.cleaned_data['overage_rate']
        enabled = self.cleaned_data['enabled']
        delete = self.cleaned_data['delete']

        if enabled == 'False':
            enabled = False
        else:
            enabled = True

        if self.cleaned_data['sub_id']:
            p = MembershipPackage.objects.get(id=package)
            p.enabled = enabled
            p.save()

            sub_default = SubscriptionDefault.objects.get(id=self.cleaned_data['sub_id'])
            if delete == True:
                sub_default.delete()
            else:
                sub_default.allowance = allowance
                sub_default.monthly_rate = monthly_rate
                sub_default.overage_rate = overage_rate
                sub_default.save()
        else:
            if MembershipPackage.objects.filter(name=name):
                raise Exception('A membership package with this name already exists.')
            if package:
                p = MembershipPackage.objects.get(id=package)
                p.enabled = enabled
                p.save()
            else:
                p = MembershipPackage(name=name, enabled=enabled)
                p.save()

            sub_default = SubscriptionDefault(package=p, resource=resource, allowance=allowance, monthly_rate=monthly_rate, overage_rate=overage_rate)
            print(('Default is %s' % sub_default))
            sub_default.save()

        return sub_default