Compare commits
11 Commits
2022808579
...
fix/stackf
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a844132e6 | |||
| 85dcbd8808 | |||
| 5f0df931a7 | |||
| d38d2cd800 | |||
| 6204a57f86 | |||
| 4af4b0c02f | |||
| 6402a5b418 | |||
| 09d66613ea | |||
| b1787200d7 | |||
| 8337f68a01 | |||
| 02fd95fe1f |
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
@@ -31,7 +31,7 @@ pipeline {
|
|||||||
}
|
}
|
||||||
stage('Checkout Code') {
|
stage('Checkout Code') {
|
||||||
steps {
|
steps {
|
||||||
git branch: 'main', credentialsId: 'ssh', url: 'git@github.com:JscorpTech/uzxarid.git'
|
git branch: 'main', credentialsId: 'muhammadvadud', url: 'https://gitea.felixits.uz/uzxarid/backend.git'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Prepare') {
|
stage('Prepare') {
|
||||||
|
|||||||
@@ -5,8 +5,12 @@ CHANNEL_LAYERS = {
|
|||||||
"default": {
|
"default": {
|
||||||
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
||||||
"CONFIG": {
|
"CONFIG": {
|
||||||
"hosts": [(env.str("REDIS_HOST", "redis"), env.int("REDIS_PORT", 6379))],
|
"hosts": [
|
||||||
|
(
|
||||||
|
env.str("REDIS_HOST", "redis"),
|
||||||
|
env.int("REDIS_PORT_6379_TCP_PORT", 6379)
|
||||||
|
)
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# Generated by Django 5.2.7 on 2025-11-27 07:55
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0013_alter_feedback_comment'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='category',
|
||||||
|
name='name_en',
|
||||||
|
field=models.CharField(max_length=255, null=True, verbose_name='Category Name'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='category',
|
||||||
|
name='name_ru',
|
||||||
|
field=models.CharField(max_length=255, null=True, verbose_name='Category Name'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='category',
|
||||||
|
name='name_uz',
|
||||||
|
field=models.CharField(max_length=255, null=True, verbose_name='Category Name'),
|
||||||
|
),
|
||||||
|
]
|
||||||
14
core/apps/api/migrations/0016_merge_20251202_1732.py
Normal file
14
core/apps/api/migrations/0016_merge_20251202_1732.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Generated by Django 5.2.7 on 2025-12-02 12:32
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0014_category_name_en_category_name_ru_category_name_uz'),
|
||||||
|
('api', '0015_alter_adoption_ad'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
]
|
||||||
@@ -1 +1,2 @@
|
|||||||
from .search import * # noqa
|
from .search import * # noqa
|
||||||
|
from .search_ads import * # noqa
|
||||||
|
|||||||
58
core/apps/api/serializers/search/search_ads.py
Normal file
58
core/apps/api/serializers/search/search_ads.py
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
from core.apps.api.models import AdModel
|
||||||
|
|
||||||
|
|
||||||
|
class BaseSearchAdsSerializer(serializers.ModelSerializer):
|
||||||
|
category = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = AdModel
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"image",
|
||||||
|
"category"
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_category(self, obj):
|
||||||
|
request = self.context.get("request")
|
||||||
|
|
||||||
|
lang = request.headers.get("Accept-Language", "uz")
|
||||||
|
lang = lang.split(",")[0].split("-")[0]
|
||||||
|
|
||||||
|
if lang not in ["uz", "ru", "en"]:
|
||||||
|
lang = "uz"
|
||||||
|
|
||||||
|
category = obj.category
|
||||||
|
if not category:
|
||||||
|
return None
|
||||||
|
|
||||||
|
chain = []
|
||||||
|
current = category
|
||||||
|
while current:
|
||||||
|
chain.append(current)
|
||||||
|
current = current.parent
|
||||||
|
|
||||||
|
chain = list(reversed(chain))
|
||||||
|
|
||||||
|
result = None
|
||||||
|
for cat in reversed(chain):
|
||||||
|
result = {
|
||||||
|
"id": cat.id,
|
||||||
|
"name": getattr(cat, f"name_{lang}"),
|
||||||
|
"children": result
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class ListSearchAdsSerializer(BaseSearchAdsSerializer):
|
||||||
|
class Meta(BaseSearchAdsSerializer.Meta): ...
|
||||||
|
|
||||||
|
|
||||||
|
class RetrieveSearchAdsSerializer(BaseSearchAdsSerializer):
|
||||||
|
class Meta(BaseSearchAdsSerializer.Meta): ...
|
||||||
|
|
||||||
|
|
||||||
|
class CreateSearchAdsSerializer(BaseSearchAdsSerializer):
|
||||||
|
class Meta(BaseSearchAdsSerializer.Meta): ...
|
||||||
@@ -1 +1,2 @@
|
|||||||
from .test_search_history import * # noqa
|
from .test_search_history import * # noqa
|
||||||
|
from .test_search_ads import * # noqa
|
||||||
|
|||||||
38
core/apps/api/tests/search/test_search_ads.py
Normal file
38
core/apps/api/tests/search/test_search_ads.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import pytest
|
||||||
|
from django.urls import reverse
|
||||||
|
from rest_framework.test import APIClient
|
||||||
|
|
||||||
|
from core.apps.api.models import AdModel
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def instance(db):
|
||||||
|
return AdModel._baker()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def api_client(instance):
|
||||||
|
client = APIClient()
|
||||||
|
##client.force_authenticate(user=instance.user)
|
||||||
|
return client, instance
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def data(api_client):
|
||||||
|
client, instance = api_client
|
||||||
|
return (
|
||||||
|
{
|
||||||
|
"list": reverse("search-ads-list"),
|
||||||
|
},
|
||||||
|
client,
|
||||||
|
instance,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_list(data):
|
||||||
|
urls, client, _ = data
|
||||||
|
response = client.get(urls["list"])
|
||||||
|
data_resp = response.json()
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert data_resp["status"] is True
|
||||||
1
core/apps/api/translation/__init__.py
Normal file
1
core/apps/api/translation/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .category import * # noqa
|
||||||
10
core/apps/api/translation/category.py
Normal file
10
core/apps/api/translation/category.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from modeltranslation.translator import TranslationOptions, register
|
||||||
|
|
||||||
|
from core.apps.api.models import Category
|
||||||
|
|
||||||
|
|
||||||
|
@register(Category)
|
||||||
|
class CategoryTranslation(TranslationOptions):
|
||||||
|
fields = [
|
||||||
|
"name",
|
||||||
|
]
|
||||||
@@ -1,10 +1,20 @@
|
|||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from rest_framework.routers import DefaultRouter
|
from rest_framework.routers import DefaultRouter
|
||||||
|
|
||||||
from core.apps.api.views import CategoryHomeApiViewSet, CategoryViewSet, HomeAdApiView, SearchHistoryViewSet, \
|
from core.apps.api.views import (
|
||||||
UserLikeViewSet, NotificationViewSet, BannerViewSet, AdsView
|
BannerViewSet,
|
||||||
|
CategoryHomeApiViewSet,
|
||||||
|
CategoryViewSet,
|
||||||
|
HomeAdApiView,
|
||||||
|
NotificationViewSet,
|
||||||
|
SearchAdsViewSet,
|
||||||
|
SearchHistoryViewSet,
|
||||||
|
UserLikeViewSet,
|
||||||
|
AdsView,
|
||||||
|
)
|
||||||
|
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
|
router.register("search-ads", SearchAdsViewSet, basename="search-ads")
|
||||||
router.register("ads", AdsView, basename="ads")
|
router.register("ads", AdsView, basename="ads")
|
||||||
router.register("banner", BannerViewSet, basename="banner")
|
router.register("banner", BannerViewSet, basename="banner")
|
||||||
router.register("notification", NotificationViewSet, basename="notification")
|
router.register("notification", NotificationViewSet, basename="notification")
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
from .search import * # noqa
|
from .search import * # noqa
|
||||||
|
from .search_ads import * # noqa
|
||||||
|
|||||||
48
core/apps/api/views/search/search_ads.py
Normal file
48
core/apps/api/views/search/search_ads.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
from rest_framework import mixins
|
||||||
|
from rest_framework.viewsets import GenericViewSet
|
||||||
|
from django_core.mixins.base import BaseViewSetMixin
|
||||||
|
from drf_spectacular.utils import extend_schema
|
||||||
|
from rest_framework.permissions import AllowAny
|
||||||
|
from core.apps.api.models import AdModel
|
||||||
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
|
from rest_framework.filters import SearchFilter
|
||||||
|
from core.apps.api.serializers.search import (
|
||||||
|
ListSearchAdsSerializer,
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@extend_schema(tags=['Search Ads'])
|
||||||
|
class SearchAdsViewSet(BaseViewSetMixin, mixins.ListModelMixin, GenericViewSet):
|
||||||
|
queryset = AdModel.objects.all().order_by('-created_at')
|
||||||
|
serializer_class = ListSearchAdsSerializer
|
||||||
|
permission_classes = [AllowAny]
|
||||||
|
http_method_names = ['get']
|
||||||
|
filter_backends = [DjangoFilterBackend, SearchFilter]
|
||||||
|
search_fields = ["name"]
|
||||||
|
|
||||||
|
action_permission_classes = {}
|
||||||
|
action_serializer_class = {
|
||||||
|
'list': ListSearchAdsSerializer,
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
queryset = super().get_queryset()
|
||||||
|
|
||||||
|
search_text = self.request.query_params.get('search')
|
||||||
|
|
||||||
|
if search_text:
|
||||||
|
field = f"name"
|
||||||
|
queryset = queryset.filter(**{f"{field}__icontains": search_text})
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
def list(self, request, *args, **kwargs):
|
||||||
|
response = super().list(request, *args, **kwargs)
|
||||||
|
|
||||||
|
if isinstance(response.data, dict) and "results" in response.data:
|
||||||
|
response.data["results"] = response.data["results"][:5]
|
||||||
|
else:
|
||||||
|
response.data = response.data[:5]
|
||||||
|
|
||||||
|
return response
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
from .cache import * # noqa
|
from .cache import * # noqa
|
||||||
from .console import * # noqa
|
from .console import * # noqa
|
||||||
from .core import * # noqa
|
from .core import * # noqa
|
||||||
|
from .language import * # noqa
|
||||||
|
|||||||
8
core/utils/language.py
Normal file
8
core/utils/language.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
def get_request_lang(request):
|
||||||
|
lang = request.headers.get("Accept-Language", "uz")
|
||||||
|
lang = lang.split(",")[0].split("-")[0].lower()
|
||||||
|
|
||||||
|
if lang not in ["uz", "ru", "en"]:
|
||||||
|
lang = "uz"
|
||||||
|
|
||||||
|
return lang
|
||||||
@@ -133,7 +133,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- mode: ingress
|
- mode: ingress
|
||||||
target: 80
|
target: 80
|
||||||
published: ${PORT:?enviromentda PORT topilmadi}
|
published: 8034
|
||||||
protocol: tcp
|
protocol: tcp
|
||||||
volumes:
|
volumes:
|
||||||
- type: bind
|
- type: bind
|
||||||
|
|||||||
Reference in New Issue
Block a user