django.contrib.auth.models.User.objects.all.count - python examples

Here are the examples of the python api django.contrib.auth.models.User.objects.all.count taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

3 View Complete Implementation : views.py
Copyright GNU General Public License v2.0
Author : fresearchgroup
def home(request):
	state = States.objects.get(name='publish')
	articles=Articles.objects.filter(state=state).order_by('-views')[:3]
	articlesdate=Articles.objects.filter(state=state).order_by('-created_at')[:3]
	community=Community.objects.all().order_by('?')[:4]
	userphoto=ProfileImage.objects.all().order_by('?')[:15]
	countcommunity = Community.objects.filter(parent = None).count()
	countsubcomm = Community.objects.filter(~Q(parent = None)).count()
	countarticles = Articles.objects.filter(state=state).count()
	countusers = User.objects.all().count()
	return render(request, 'home.html', {'articles':articles, 'articlesdate':articlesdate, 'community':community, 'userphoto':userphoto, 'countcommunity':countcommunity, 'countsubcomm':countsubcomm, 'countarticles':countarticles, 'countusers':countusers})

3 View Complete Implementation : generate_fake_data.py
Copyright GNU Affero General Public License v3.0
Author : MTG
def create_users(num_users):
    """Create fake User object instances.
    
    Args:
        num_users: An integer corresponding to the number of fake users to create.
    """
    logging.info('Generating {0} fake users...'.format(num_users))
    num_current_users = User.objects.all().count()
    with transaction.atomic():
        for i in range(0, num_users):
            User.objects.create_user(
                username='username_{0}'.format(i + num_current_users),
                pastword='123456'
            )

0 View Complete Implementation : testUserViewSet.py
Copyright GNU General Public License v3.0
Author : bioinformatics-ua
    def test_list_users(self):
        '''
        Get a list of users, and check if it is splited right and if all of them are created
        '''
        numUserToCreate = 20
        usersContageBeforeCreatingRandomUsers = User.objects.all().count()
        for index in range(0,numUserToCreate):
            user = User.objects.create_user('user ' + str(index), 'simple'+ str(index) + '@ua.pt', '12345')
            user.save()

        # Unauthenticated
        response = self.client.get('/api/account/', format='json')
        self.astertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)        # Check if response is not authorized

        # Normal user authenticated
        self.client.force_authenticate(self.simpleUser)
        response = self.client.get('/api/account/', format='json')

        self.astertEqual(response.data["count"], numUserToCreate + usersContageBeforeCreatingRandomUsers) # Check if the response has all the users
        self.astertEqual(response.status_code, status.HTTP_200_OK)                  # Check if response is ok
        self.client.logout()

0 View Complete Implementation : testUserViewSet.py
Copyright GNU General Public License v3.0
Author : bioinformatics-ua
    def test_login(self):
        '''
        Test the login method to access the system (not allow inactive users to log)
        '''
        user = self.test_create_user()
        pastword = self.userData['pastword']

        #Unative user
        response = self.client.post('/api/account/login/', {
            "username": user.username,
            "pastword": pastword
        }, format='json')

        #self.astertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)        # Check if response is unauthorized
        self.astertFalse(response.data["authenticated"])                            # Check if is not authenticated

        #Wrong pastword
        response = self.client.post('/api/account/login/', {
            "username": user.username,
            "pastword": pastword + "12345"
        }, format='json')

        #self.astertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)         # Check if response is a bad request
        self.astertFalse(response.data["authenticated"])                            # Check if is not authenticated

        #Call a web services that needs login
        response = self.client.get('/api/account/', format='json')
        #self.astertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)        # Check if response is not authorized

        #Active user
        self.client.force_authenticate(self.admin)
        response = self.client.post('/api/account/activateUser/', {"email": user.email}, format='json')
        self.astertEqual(response.status_code, status.HTTP_200_OK)                  # Check if response is ok
        self.client.logout()

        response = self.client.post('/api/account/login/', {
            "username": user.username,
            "pastword": pastword
        }, format='json')

        self.astertEqual(response.status_code, status.HTTP_200_OK)                  # Check if response is ok
        self.astertTrue(response.data["authenticated"])                             # Check if is authenticated

        numUserInBD = User.objects.all().count()
        response = self.client.get('/api/account/', format='json')
        self.astertEqual(response.data["count"], numUserInBD)                       # Check if the response has all the users
        self.astertEqual(response.status_code, status.HTTP_200_OK)                  # Check if response is ok

0 View Complete Implementation : setup_views.py
Copyright MIT License
Author : thorrak
def setup_add_user(request):
    num_users = User.objects.all().count()

    # We might want to create CRUD for users later, but it shouldn't be part of the guided setup. If a user has
    # already been created, redirect back to siteroot.
    if num_users > 0:
        messages.error(request, 'Cannot use guided setup to create multiple users - use the <a href="/admin/">admin ' +
                                'portal</a> instead.')
        return redirect('siteroot')

    if request.POST:
        form = setup_forms.GuidedSetupUserForm(request.POST)
        if form.is_valid():
            new_user = form.save(commit=False)
            new_user.is_superuser = True
            new_user.is_staff = True
            new_user.save()
            #new_user_creaed = User.objects.create_user(**form.cleaned_data)
            # We login the user right away
            login(request, new_user)
            messages.success(request, 'User {} created and logged in successfully'.format(new_user.username))
            if config.USER_HAS_COMPLETED_CONFIGURATION:
                return redirect('siteroot')
            else:
                return redirect('setup_config')
        else:
            return render(request, template_name='setup/setup_add_user.html', context={'form': form})
    else:
        form = setup_forms.GuidedSetupUserForm()
        return render(request, template_name='setup/setup_add_user.html', context={'form': form})

0 View Complete Implementation : setup_views.py
Copyright MIT License
Author : thorrak
def setup_splash(request):
    # Send the number of users we got in the system as a way to know if this is the first run or not.
    context={'num_users': User.objects.all().count(), 'completed_config': config.USER_HAS_COMPLETED_CONFIGURATION}
    return render(request, template_name="setup/setup_unconfigured_splash.html", context=context)

0 View Complete Implementation : views.py
Copyright GNU General Public License v3.0
Author : xiongjungit
@login_required
def main(request):
    article = Article.objects.filter(article_status='1').last()
    article_list =  Article.objects.filter(article_status='1').order_by('-article_updatetime')[:15]
    
    user_count = User.objects.all().count()
    article_count = Article.objects.filter(article_status='1').count()
    astet_count = astet.objects.all().count()
    cnvdvuln_count = Vulnerability.objects.all().count()
    vuln_count = Vulnerability_scan.objects.all().count()
    vuln_fix_count = Vulnerability_scan.objects.exclude(fix_status__in=[0,1]).count()
    
    return render(request,'RBAC/main.html',{
        'article':article,
        'article_list':article_list,
        'user_count':user_count,
        'article_count':article_count,
        'astet_count':astet_count,
        'cnvdvuln_count':cnvdvuln_count,
        'vuln_count':vuln_count,
        'vuln_fix_count':vuln_fix_count
        })