Esempio n. 1
0
    def add_condition(self, request):
        key = request.POST.get("key")
        condition_set_id = request.POST.get("id")
        field_name = request.POST.get("field")
        exclude = int(request.POST.get("exclude") or 0)

        if not all([key, condition_set_id, field_name]):
            raise GargoyleException("Fields cannot be empty")

        field = gargoyle.get_condition_set_by_id(condition_set_id).fields[field_name]
        value = field.validate(request.POST)

        switch = gargoyle[key]
        switch.add_condition(condition_set_id, field_name, value, exclude=exclude)

        logger.info('Condition added to %r (%r, %s=%r, exclude=%r)' % (switch.key,
                    condition_set_id, field_name, value, bool(exclude)))

        signals.switch_condition_added.send(
            sender=self,
            request=request,
            switch=switch,
            condition={
                'condition_set_id': condition_set_id,
                'field_name': field_name,
                'value': value,
            },
        )

        return switch.to_dict(gargoyle)
Esempio n. 2
0
    def add_condition(self, request):
        key = request.POST.get("key")
        condition_set_id = request.POST.get("id")
        field_name = request.POST.get("field")
        exclude = int(request.POST.get("exclude") or 0)

        if not all([key, condition_set_id, field_name]):
            raise GargoyleException("Fields cannot be empty")

        field = gargoyle.get_condition_set_by_id(
            condition_set_id).fields[field_name]
        value = field.validate(request.POST)

        switch = gargoyle[key]
        switch.add_condition(condition_set_id,
                             field_name,
                             value,
                             exclude=exclude)

        logger.info(
            'Condition added to %r (%r, %s=%r, exclude=%r)' %
            (switch.key, condition_set_id, field_name, value, bool(exclude)))

        signals.switch_condition_added.send(
            sender=self,
            request=request,
            switch=switch,
            condition={
                'condition_set_id': condition_set_id,
                'field_name': field_name,
                'value': value,
            },
        )

        return switch.to_dict(gargoyle)
Esempio n. 3
0
    def add_condition(self, request):
        key = request.POST.get("key")
        condition_set_id = request.POST.get("id")
        field_name = request.POST.get("field")
        exclude = int(request.POST.get("exclude") or 0)

        if not all([key, condition_set_id, field_name]):
            raise GargoyleException("Fields cannot be empty")

        field = gargoyle.get_condition_set_by_id(condition_set_id).fields[field_name]
        value = field.validate(request.POST)

        switch = gargoyle[key]
        switch.add_condition(condition_set_id, field_name, value, exclude=exclude)

        return switch.to_dict(gargoyle)
Esempio n. 4
0
    def add_condition(self, request):
        key = request.POST.get("key")
        condition_set_id = request.POST.get("id")
        field_name = request.POST.get("field")
        exclude = int(request.POST.get("exclude") or 0)

        if not all([key, condition_set_id, field_name]):
            raise GargoyleException("Fields cannot be empty")

        field = gargoyle.get_condition_set_by_id(condition_set_id).fields[field_name]
        value = field.validate(request.POST)

        switch = Switch.objects.get(key=key)
        switch.add_condition(condition_set_id, field_name, value, exclude=exclude)

        return switch.to_dict()
Esempio n. 5
0
    def remove_condition(self, condition_set, field_name, condition, commit=True):
        from gargoyle import gargoyle

        condition_set = gargoyle.get_condition_set_by_id(condition_set)

        namespace = condition_set.get_namespace()

        if namespace not in self.value:
            return
            
        if field_name not in self.value[namespace]:
            return

        self.value[namespace][field_name] = [c for c in self.value[namespace][field_name] if c[1] != condition]

        if commit:
            self.save()
Esempio n. 6
0
    def add_condition(self, condition_set, field_name, condition, exclude=False, commit=True):
        from gargoyle import gargoyle
        
        condition_set = gargoyle.get_condition_set_by_id(condition_set)

        assert isinstance(condition, basestring), 'conditions must be strings'

        namespace = condition_set.get_namespace()

        if namespace not in self.value:
            self.value[namespace] = {}
        if field_name not in self.value[namespace]:
            self.value[namespace][field_name] = []
        if condition not in self.value[namespace][field_name]:
            self.value[namespace][field_name].append((exclude and EXCLUDE or INCLUDE, condition))

        if commit:
            self.save()
Esempio n. 7
0
    def clear_conditions(self, condition_set, field_name=None, commit=True):
        from gargoyle import gargoyle

        condition_set = gargoyle.get_condition_set_by_id(condition_set)

        namespace = condition_set.get_namespace()

        if namespace not in self.value:
            return
        
        if not field_name:
            del self.value[namespace]
        elif field_name not in self.value[namespace]:
            return
        else:
            del self.value[namespace][field_name]
        
        if commit:
            self.save()
Esempio n. 8
0
    def clear_conditions(self, condition_set, field_name=None, commit=True):
        from gargoyle import gargoyle

        condition_set = gargoyle.get_condition_set_by_id(condition_set)

        namespace = condition_set.get_namespace()

        if namespace not in self.value:
            return

        if not field_name:
            del self.value[namespace]
        elif field_name not in self.value[namespace]:
            return
        else:
            del self.value[namespace][field_name]

        if commit:
            self.save()
Esempio n. 9
0
    def remove_condition(self,
                         condition_set,
                         field_name,
                         condition,
                         commit=True):
        from gargoyle import gargoyle

        condition_set = gargoyle.get_condition_set_by_id(condition_set)

        namespace = condition_set.get_namespace()

        if namespace not in self.value:
            return

        if field_name not in self.value[namespace]:
            return

        self.value[namespace][field_name] = [
            c for c in self.value[namespace][field_name] if c[1] != condition
        ]

        if commit:
            self.save()
Esempio n. 10
0
    def add_condition(self,
                      condition_set,
                      field_name,
                      condition,
                      exclude=False,
                      commit=True):
        from gargoyle import gargoyle

        condition_set = gargoyle.get_condition_set_by_id(condition_set)

        assert isinstance(condition, basestring), 'conditions must be strings'

        namespace = condition_set.get_namespace()

        if namespace not in self.value:
            self.value[namespace] = {}
        if field_name not in self.value[namespace]:
            self.value[namespace][field_name] = []
        if condition not in self.value[namespace][field_name]:
            self.value[namespace][field_name].append((exclude and EXCLUDE
                                                      or INCLUDE, condition))

        if commit:
            self.save()