Skip to content

Commit

Permalink
fix views
Browse files Browse the repository at this point in the history
  • Loading branch information
sgmdlt committed Oct 18, 2024
1 parent 6a5f095 commit ba33747
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 51 deletions.
9 changes: 9 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import sys

import dj_database_url
import sentry_sdk
Expand Down Expand Up @@ -275,3 +276,11 @@
'LOCATION': 'memcached:11211',
}
}

if 'test' in sys.argv:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
}
}
12 changes: 10 additions & 2 deletions contributors/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ class PaginationMixin(MultipleObjectMixin):

def get_context_data(self, **kwargs):
"""Add context."""
paginator = Paginator(self.get_queryset(), self.paginate_by)
queryset = kwargs.pop('object_list', self.object_list)
if queryset is None:
queryset = self.get_queryset()

# Убедимся, что queryset отсортирован
if not queryset.query.order_by:
queryset = queryset.order_by('id')

paginator = Paginator(queryset, self.paginate_by)
page = paginator.get_page(self.request.GET.get('page'))

page_slice = get_page_slice(
Expand All @@ -71,7 +79,7 @@ def get_context_data(self, **kwargs):
self.inner_visible_pages,
)

context = super().get_context_data(**kwargs)
context = super().get_context_data(object_list=queryset, **kwargs)
context.update({
'page': page,
'page_range': paginator.page_range[page_slice],
Expand Down
22 changes: 15 additions & 7 deletions contributors/views/organizations_views/organization.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
from django.db.models import Count, Prefetch, Q
from django.shortcuts import get_object_or_404
from django.utils.translation import gettext_lazy as _

from contributors.models import Organization
from contributors.models import Organization, Repository
from contributors.views.repositories_views import repositories


class OrgRepositoryList(repositories.ListView):
"""An organization's details."""

template_name = (
'contributors_sections/organizations/organization_details.html'
)
template_name = 'contributors_sections/organizations/organization_details.html'
sortable_fields = (
'name',
'project',
'pull_requests',
'issues',
('contributors_count', _("Contributors")),
)
context_object_name = 'repositories'

def get_queryset(self):
"""Get a dataset."""
self.organization = get_object_or_404(
Organization,
Organization.objects.prefetch_related(
Prefetch(
'repository_set',
queryset=Repository.objects.filter(is_visible=True).annotate(
pull_requests=Count('contribution', filter=Q(contribution__type='pr')), # noqa: E501
issues=Count('contribution', filter=Q(contribution__type='iss')),
contributors_count=Count('contribution__contributor', distinct=True) # noqa: E501
)
)
),
name=self.kwargs['slug'],
)
self.queryset = self.queryset.filter(organization=self.organization)
return super().get_queryset()
return self.organization.repository_set.all()

def get_context_data(self, **kwargs):
"""Add context."""
Expand Down
85 changes: 43 additions & 42 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
apscheduler==3.10.4 ; python_version >= "3.8" and python_version < "4.0"
asgiref==3.8.1 ; python_version >= "3.8" and python_version < "4.0"
backports-zoneinfo==0.2.1 ; python_version >= "3.8" and python_version < "3.9"
black==23.12.1 ; python_version >= "3.8" and python_version < "4.0"
certifi==2024.7.4 ; python_version >= "3.8" and python_version < "4.0"
cffi==1.16.0 ; python_version >= "3.8" and python_version < "4.0"
charset-normalizer==3.3.2 ; python_version >= "3.8" and python_version < "4.0"
click==8.1.7 ; python_version >= "3.8" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.8" and python_version < "4.0" and platform_system == "Windows"
crispy-bootstrap5==0.6 ; python_version >= "3.8" and python_version < "4.0"
cryptography==41.0.7 ; python_version >= "3.8" and python_version < "4.0"
dj-database-url==0.5.0 ; python_version >= "3.8" and python_version < "4.0"
django-crispy-forms==1.14.0 ; python_version >= "3.8" and python_version < "4.0"
django-cte==1.3.3 ; python_version >= "3.8" and python_version < "4.0"
django-debug-toolbar==3.8.1 ; python_version >= "3.8" and python_version < "4.0"
django-extensions==3.2.3 ; python_version >= "3.8" and python_version < "4.0"
django-filter==23.5 ; python_version >= "3.8" and python_version < "4.0"
django-mathfilters==1.0.0 ; python_version >= "3.8" and python_version < "4.0"
django==4.2.14 ; python_version >= "3.8" and python_version < "4.0"
gunicorn==20.1.0 ; python_version >= "3.8" and python_version < "4.0"
idna==3.7 ; python_version >= "3.8" and python_version < "4.0"
mypy-extensions==1.0.0 ; python_version >= "3.8" and python_version < "4.0"
packaging==24.1 ; python_version >= "3.8" and python_version < "4.0"
pathspec==0.12.1 ; python_version >= "3.8" and python_version < "4.0"
platformdirs==4.2.2 ; python_version >= "3.8" and python_version < "4.0"
psycopg2==2.9.9 ; python_version >= "3.8" and python_version < "4.0"
pycparser==2.22 ; python_version >= "3.8" and python_version < "4.0"
pyjwt==2.9.0 ; python_version >= "3.8" and python_version < "4.0"
python-dateutil==2.9.0.post0 ; python_version >= "3.8" and python_version < "4.0"
python-dotenv==0.20.0 ; python_version >= "3.8" and python_version < "4.0"
pytz==2024.1 ; python_version >= "3.8" and python_version < "4.0"
requests==2.32.3 ; python_version >= "3.8" and python_version < "4.0"
sentry-sdk==1.45.1 ; python_version >= "3.8" and python_version < "4.0"
setuptools==72.1.0 ; python_version >= "3.8" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.8" and python_version < "4.0"
sqlparse==0.5.1 ; python_version >= "3.8" and python_version < "4.0"
tomli==2.0.1 ; python_version >= "3.8" and python_version < "3.11"
typing-extensions==4.12.2 ; python_version >= "3.8" and python_version < "3.11"
tzdata==2024.1 ; python_version >= "3.8" and python_version < "4.0" and (sys_platform == "win32" or platform_system == "Windows")
tzlocal==5.2 ; python_version >= "3.8" and python_version < "4.0"
urllib3==2.2.2 ; python_version >= "3.8" and python_version < "4.0"
whitenoise==6.7.0 ; python_version >= "3.8" and python_version < "4.0"
apscheduler==3.10.4 ; python_full_version >= "3.8.1" and python_version < "4.0"
asgiref==3.8.1 ; python_full_version >= "3.8.1" and python_version < "4.0"
backports-zoneinfo==0.2.1 ; python_full_version >= "3.8.1" and python_version < "3.9"
black==23.12.1 ; python_full_version >= "3.8.1" and python_version < "4.0"
certifi==2024.8.30 ; python_full_version >= "3.8.1" and python_version < "4.0"
cffi==1.17.1 ; python_full_version >= "3.8.1" and python_version < "4.0"
charset-normalizer==3.4.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
click==8.1.7 ; python_full_version >= "3.8.1" and python_version < "4.0"
colorama==0.4.6 ; python_full_version >= "3.8.1" and python_version < "4.0" and platform_system == "Windows"
crispy-bootstrap5==0.6 ; python_full_version >= "3.8.1" and python_version < "4.0"
cryptography==41.0.7 ; python_full_version >= "3.8.1" and python_version < "4.0"
dj-database-url==0.5.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
django-crispy-forms==1.14.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
django-cte==1.3.3 ; python_full_version >= "3.8.1" and python_version < "4.0"
django-debug-toolbar==3.8.1 ; python_full_version >= "3.8.1" and python_version < "4.0"
django-extensions==3.2.3 ; python_full_version >= "3.8.1" and python_version < "4.0"
django-filter==23.5 ; python_full_version >= "3.8.1" and python_version < "4.0"
django-mathfilters==1.0.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
django==4.2.16 ; python_full_version >= "3.8.1" and python_version < "4.0"
gunicorn==20.1.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
idna==3.10 ; python_full_version >= "3.8.1" and python_version < "4.0"
mypy-extensions==1.0.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
packaging==24.1 ; python_full_version >= "3.8.1" and python_version < "4.0"
pathspec==0.12.1 ; python_full_version >= "3.8.1" and python_version < "4.0"
platformdirs==4.3.6 ; python_full_version >= "3.8.1" and python_version < "4.0"
psycopg2==2.9.10 ; python_full_version >= "3.8.1" and python_version < "4.0"
pycparser==2.22 ; python_full_version >= "3.8.1" and python_version < "4.0"
pyjwt==2.9.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
pymemcache==4.0.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
python-dateutil==2.9.0.post0 ; python_full_version >= "3.8.1" and python_version < "4.0"
python-dotenv==0.20.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
pytz==2024.2 ; python_full_version >= "3.8.1" and python_version < "4.0"
requests==2.32.3 ; python_full_version >= "3.8.1" and python_version < "4.0"
sentry-sdk==1.45.1 ; python_full_version >= "3.8.1" and python_version < "4.0"
setuptools==75.2.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
six==1.16.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
sqlparse==0.5.1 ; python_full_version >= "3.8.1" and python_version < "4.0"
tomli==2.0.2 ; python_full_version >= "3.8.1" and python_version < "3.11"
typing-extensions==4.12.2 ; python_full_version >= "3.8.1" and python_version < "3.11"
tzdata==2024.2 ; python_full_version >= "3.8.1" and python_version < "4.0" and (sys_platform == "win32" or platform_system == "Windows")
tzlocal==5.2 ; python_full_version >= "3.8.1" and python_version < "4.0"
urllib3==2.2.3 ; python_full_version >= "3.8.1" and python_version < "4.0"
whitenoise==6.7.0 ; python_full_version >= "3.8.1" and python_version < "4.0"

0 comments on commit ba33747

Please sign in to comment.