Python django.conf.settings 模块,ANONYMOUS_USER_ID 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用django.conf.settings.ANONYMOUS_USER_ID

项目:fieldsight-kobocat    作者:awemulya    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request')
        super(AssignOrgAdmin, self).__init__(*args, **kwargs)
        role = kwargs.get('instance')
        if role is not None:
            old_admins = role.organization.get_staffs
            old_admins_id = [admin[0] for admin in old_admins]
            old_admins_id.append(settings.ANONYMOUS_USER_ID)
            if hasattr(self.request, "organization"):
                if self.request.organization:
                    users = User.objects.filter(user_profile__organization=self.request.organization, is_active=True).\
                        filter(id__in=old_admins_id)
                else:
                    users = User.objects.filter(is_active=True).exclude(id__in=old_admins_id)
            else:
                users = User.objects.filter(is_active=True).exclude(id__in=old_admins_id)
            self.fields['user'].queryset = users
            self.fields['organization'].choices = old_admins
项目:fieldsight-kobocat    作者:awemulya    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request')
        super(SetProjectRoleForm, self).__init__(*args, **kwargs)
        self.fields['group'].empty_label = None
        role = kwargs.get('instance')
        if role is not None:
            old_admins = role.project.get_staffs_both_role
            old_admins.append(settings.ANONYMOUS_USER_ID)
            if hasattr(self.request, "organization"):
                if self.request.organization:
                    users = User.objects.filter(is_active=True, user_profile__organization=self.request.organization)\
                        .exclude(id__in=old_admins)
                else:
                    users = User.objects.filter(is_active=True).exclude(id__in=old_admins)
            else:
                users = User.objects.filter(is_active=True).exclude(id__in=old_admins)
            self.fields['user'].queryset = users
        self.fields['group'].queryset = Group.objects.filter(
            name__in=['Project Manager'])
项目:fieldsight-kobocat    作者:awemulya    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request')
        super(SetProjectManagerForm, self).__init__(*args, **kwargs)
        role = kwargs.get('instance')
        if role is not None:
            old_admins = role.project.get_staffs_id
            users = User.objects.filter().exclude(id=settings.ANONYMOUS_USER_ID).exclude(id__in=old_admins)
            if hasattr(self.request, "organization"):
                if self.request.organization:
                    users = users.filter(user_profile__organization=self.request.organization)
            self.fields['user'].queryset = users
项目:fieldsight-kobocat    作者:awemulya    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request')
        super(SetSupervisorForm, self).__init__(*args, **kwargs)
        role = kwargs.get('instance')
        if role is not None:
            old_pm = role.site.get_supervisor_id
            users = User.objects.filter().exclude(id=settings.ANONYMOUS_USER_ID).exclude(id__in=old_pm)
            if hasattr(self.request, "organization"):
                if self.request.organization:
                    users = users.filter(user_profile__organization=self.request.organization)
            self.fields['user'].queryset = users
项目:fieldsight-kobocat    作者:awemulya    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(UserRoleForm, self).__init__(*args, **kwargs)
        self.fields['group'].empty_label = None
        self.fields['user'].empty_label = None
        users = User.objects.filter().exclude(id=settings.ANONYMOUS_USER_ID)
        self.fields['user'].choices = [(user.pk, user.username) for user in users]
项目:FormShare    作者:qlands    | 项目源码 | 文件源码
def handle(self, *args, **options):
        print "Task started ..."

        # Get all the users
        for user in queryset_iterator(
                User.objects.exclude(pk=settings.ANONYMOUS_USER_ID)):
            self.set_project_to_user_forms(user)

        print "Task completed ..."
项目:FormShare    作者:qlands    | 项目源码 | 文件源码
def get_queryset(self):
        """Set AnonymousUser from the database to allow object permissions."""
        if self.request and self.request.user.is_anonymous():
            self.request.user = get_object_or_404(
                User, pk=settings.ANONYMOUS_USER_ID)

        return super(AnonymousUserMixin, self).get_queryset()