Skip to content

Commit

Permalink
Merge pull request #419 from ReYaNOW/code_refactoring_in_views
Browse files Browse the repository at this point in the history
Разнес вюхи по отдельным пакетам, вынес одинаковый код в миксин
  • Loading branch information
fey authored Jun 10, 2024
2 parents f60bfe6 + 9cc1628 commit 57ec712
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 104 deletions.
6 changes: 3 additions & 3 deletions contributors/admin/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib import admin
from django.urls import path

from contributors import views
from contributors.views.config import collect_data, show_repos


class CustomAdminSite(admin.AdminSite):
Expand All @@ -17,12 +17,12 @@ def get_urls(self):
custom_urls = [
path(
'contributors/config/',
self.admin_view(views.config.show_repos),
self.admin_view(show_repos),
name='config',
),
path(
'contributors/config/collect_data',
self.admin_view(views.config.collect_data),
self.admin_view(collect_data),
name='collect_data',
),
]
Expand Down
14 changes: 7 additions & 7 deletions contributors/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
),
path(
'leaderboard/commits',
views.leaderboard_commits.ListView.as_view(),
views.leaderboards.CommitsListView.as_view(),
name='leaderboard_commits',
),
path(
'leaderboard/pull-requests',
views.leaderboard_prs.ListView.as_view(),
views.leaderboards.PrsListView.as_view(),
name='leaderboard_prs',
),
path(
'leaderboard/issues',
views.leaderboard_issues.ListView.as_view(),
views.leaderboards.IssuesListView.as_view(),
name='leaderboard_issues',
),
path(
Expand Down Expand Up @@ -90,14 +90,14 @@
name='project_details',
),
path(
"issues/",
'issues/',
views.issues.ListView.as_view(),
name="open_issues",
name='open_issues',
),
path(
"pull_requests",
'pull_requests',
views.pull_requests.ListView.as_view(),
name="pull_requests_list",
name='pull_requests_list',
),
path('event-handler', views.webhook.EventHandler.as_view()),
path('about', views.about.AboutView.as_view(), name="about"),
Expand Down
28 changes: 14 additions & 14 deletions contributors/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
about,
achievements,
config,
contributor,
contributor_compare,
filters,
home,
landing,
user_settings,
webhook,
)
from contributors.views.contributors_views import (
contributor,
contributor_issues,
contributor_prs,
contributors,
contributors_for_period,
home,
)
from contributors.views.generic_list_views import (
issues,
landing,
leaderboard_commits,
leaderboard_issues,
leaderboard_prs,
organization,
organizations,
project,
projects,
leaderboards,
pull_requests,
repositories,
repository,
user_settings,
webhook,
)
from contributors.views.organizations_views import organization, organizations
from contributors.views.projects_views import project, projects
from contributors.views.repositories_views import repositories, repository
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
ContributorTotalStatMixin,
)

# This was done to fix: WPS 226 Found string literal over-use: id > 4
ID = 'id'


class DetailView(
ContributorTotalStatMixin, ContributorsJsonMixin, generic.DetailView,
Expand Down Expand Up @@ -49,10 +52,10 @@ def get_context_data(self, **kwargs):
context['summary'] = Contribution.objects.filter(
contributor=self.object,
).aggregate(
commits=Count('id', filter=Q(type='cit')),
pull_requests=Count('id', filter=Q(type='pr')),
issues=Count('id', filter=Q(type='iss')),
comments=Count('id', filter=Q(type='cnt')),
commits=Count(ID, filter=Q(type='cit')),
pull_requests=Count(ID, filter=Q(type='pr')),
issues=Count(ID, filter=Q(type='iss')),
comments=Count(ID, filter=Q(type='cnt')),
)

contributors = Contributor.objects.visible()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from contributors.models import Contributor
from contributors.utils import misc
from contributors.views import contributors
from contributors.views.contributors_views import contributors


class ListView(contributors.ListView):
Expand Down
Empty file.
File renamed without changes.
58 changes: 58 additions & 0 deletions contributors/views/generic_list_views/leaderboards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from django.views import generic

from contributors.models import Contributor
from contributors.views.mixins import (
LeaderboardQueryMixin,
TableSortSearchAndPaginationMixin,
)


class LeaderboardGenericListView(
LeaderboardQueryMixin,
TableSortSearchAndPaginationMixin,
generic.ListView,
):
"""Generic view for inheritance."""

queryset = Contributor.objects.visible().with_contributions()

searchable_fields = ('login', 'name')
paginate_by = 100


class CommitsListView(LeaderboardGenericListView):
"""List of leaders among contributors by commits."""

template_name = (
'contributors_sections/leaderboard/leaderboard_commits.html'
)
sortable_fields = (
'-commits',
'login',
'name',
)
ordering = sortable_fields[0]


class IssuesListView(LeaderboardGenericListView):
"""List of leaders among contributors by issues."""

template_name = 'contributors_sections/leaderboard/leaderboard_issues.html'
sortable_fields = (
'-issues',
'login',
'name',
)
ordering = sortable_fields[0]


class PrsListView(LeaderboardGenericListView):
"""List of leaders among contributors by pull requests."""

template_name = 'contributors_sections/leaderboard/leaderboard_prs.html'
sortable_fields = (
'-pull_requests',
'login',
'name',
)
ordering = sortable_fields[0]
File renamed without changes.
23 changes: 0 additions & 23 deletions contributors/views/leaderboard_commits.py

This file was deleted.

23 changes: 0 additions & 23 deletions contributors/views/leaderboard_issues.py

This file was deleted.

24 changes: 0 additions & 24 deletions contributors/views/leaderboard_prs.py

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
from django.utils.translation import gettext_lazy as _

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


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

template_name = 'contributors_sections/organizations/organization_details.html' # noqa: E501
template_name = (
'contributors_sections/organizations/organization_details.html'
)
sortable_fields = ( # noqa: WPS317
'name',
'project',
Expand All @@ -20,7 +22,8 @@ class OrgRepositoryList(repositories.ListView):
def get_queryset(self): # noqa: WPS615
"""Get a dataset."""
self.organization = get_object_or_404(
Organization, name=self.kwargs['slug'],
Organization,
name=self.kwargs['slug'],
)
self.queryset = self.queryset.filter(organization=self.organization)
return super().get_queryset()
Expand Down
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from contributors.models import Contribution, Project
from contributors.utils import misc
from contributors.views import repositories
from contributors.views.repositories_views import repositories


class ProjectRepositoryList(repositories.ListView):
Expand Down
File renamed without changes.
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.shortcuts import get_object_or_404

from contributors.models import Repository
from contributors.views import contributors
from contributors.views.contributors_views import contributors


class RepoContributorList(contributors.ListView):
Expand Down

0 comments on commit 57ec712

Please sign in to comment.