-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from Pet-projects-CodePET/feature/counter_user…
…s_projects [+] Создала счетчик пользователей и проектов
- Loading branch information
Showing
11 changed files
with
70 additions
and
14 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
3 changes: 1 addition & 2 deletions
3
src/backend/apps/general/serializers.py → src/backend/api/v1/general/serializers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.urls import path | ||
|
||
from api.v1.general.views import CounterApiView, SectionViewSet | ||
|
||
urlpatterns = [ | ||
path("section", SectionViewSet.as_view({"get": "list"})), | ||
path("counter", CounterApiView.as_view()), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from django.db import connection | ||
from django.utils.decorators import method_decorator | ||
from django.views.decorators.cache import cache_page | ||
from django_filters.rest_framework import DjangoFilterBackend | ||
from rest_framework import generics, viewsets | ||
from rest_framework.response import Response | ||
|
||
from apps.general.models import Section | ||
|
||
from .serializers import SectionSerializer | ||
|
||
|
||
class SectionViewSet(viewsets.ModelViewSet): | ||
"""Текстовая секция на странице""" | ||
|
||
queryset = Section.objects.all() | ||
serializer_class = SectionSerializer | ||
filter_backends = [DjangoFilterBackend] | ||
filterset_fields = ["page_id"] | ||
|
||
|
||
class CounterApiView(generics.RetrieveAPIView): | ||
"""Счетчик проектов и пользователей""" | ||
|
||
@method_decorator(cache_page(600)) | ||
def get(self, request): | ||
with connection.cursor() as cursor: | ||
cursor.execute( | ||
"SELECT count(*) from project_project union all SELECT count(*) from users_user " | ||
) | ||
row = cursor.fetchall() | ||
return Response({"projects": row[0][0], "users": row[1][0]}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/backend/apps/general/migrations/0002_section_page_id.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 5.0.1 on 2024-02-19 20:16 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("general", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="section", | ||
name="page_id", | ||
field=models.IntegerField( | ||
default=0, verbose_name="Идентификатор страницы" | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.