Ejemplo n.º 1
0
class UserConditionSet(ModelConditionSet):
    username = String()
    email = String()
    is_anonymous = Boolean(label='Anonymous')
    is_active = Boolean(label='Active')
    is_staff = Boolean(label='Staff')
    is_superuser = Boolean(label='Superuser')
    date_joined = OnOrAfterDate(label='Joined on or after')

    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')
        if condition is not None:
            return bool(condition)
        return None
Ejemplo n.º 2
0
class HostConditionSet(ConditionSet):
    hostname = String()

    def get_namespace(self):
        return 'host'

    def can_execute(self, instance):
        return instance is None

    def get_field_value(self, instance, field_name):
        if field_name == 'hostname':
            return socket.gethostname()

    def get_group_label(self):
        return 'Host'
Ejemplo n.º 3
0
class UserConditionSet(ModelConditionSet):
    percent = Percent()
    username = String()
    is_anonymous = Boolean(label='Anonymous')
    is_staff = Boolean(label='Staff')
    is_superuser = Boolean(label='Superuser')

    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)