def can_execute(self, instance): return isinstance(instance, (User, AnonymousUser)) def is_active(self, instance, conditions): """ value is the current value of the switch instance is the instance of our type """ if isinstance(instance, User): return super(UserConditionSet, self).is_active(instance, conditions) # HACK: allow is_authenticated to work on AnonymousUser condition = conditions.get(self.get_namespace(), {}).get('is_anonymous') return bool(condition) gargoyle.register(UserConditionSet(User)) class IPAddress(String): def clean(self, value): validate_ipv4_address(value) return value class IPAddressConditionSet(RequestConditionSet): percent = Percent() ip_address = IPAddress(label='IP Address') def get_namespace(self): return 'ip' def get_field_value(self, instance, field_name): # XXX: can we come up w/ a better API?
def is_active(self, instance, conditions): """ value is the current value of the switch instance is the instance of our type """ if isinstance(instance, User): return super(UserConditionSet, self).is_active(instance, conditions) # HACK: allow is_authenticated to work on AnonymousUser condition = conditions.get(self.get_namespace(), {}).get('is_anonymous') if condition is not None: return bool(condition) return None gargoyle.register(UserConditionSet(User)) class IPAddress(String): def clean(self, value): validate_ipv4_address(value) return value @gargoyle.register class IPAddressConditionSet(RequestConditionSet): percent = Percent() ip_address = IPAddress(label='IP Address') internal_ip = Boolean(label='Internal IPs') def get_namespace(self):
value is the current value of the switch instance is the instance of our type """ if isinstance(instance, User): return super(UserConditionSet, self).is_active(instance, conditions) # HACK: allow is_authenticated to work on AnonymousUser condition = conditions.get(self.get_namespace(), {}).get('is_anonymous') if condition is not None: return bool(condition) return None gargoyle.register(UserConditionSet(User)) class IPAddress(String): def clean(self, value): validate_ipv4_address(value) return value @gargoyle.register class IPAddressConditionSet(RequestConditionSet): percent = Percent() ip_address = IPAddress(label='IP Address') internal_ip = Boolean(label='Internal IPs') def get_namespace(self):
value is the current value of the switch instance is the instance of our type """ if isinstance(instance, User): return super(UserConditionSet, self).is_active(instance, conditions) # HACK: allow is_authenticated to work on AnonymousUser condition = conditions.get(self.get_namespace(), {}).get('is_anonymous') if condition is not None: return bool(condition) return None gargoyle.register(UserConditionSet(User)) class IPAddress(String): def clean(self, value): validate_ipv4_address(value) return value class IPAddressConditionSet(RequestConditionSet): percent = Percent() ip_address = IPAddress(label='IP Address') internal_ip = Boolean(label='Internal IPs') def get_namespace(self): return 'ip'