from django.conf import settings from django.core.paginator import Paginator from django.http import Http404 from django.shortcuts import render, get_object_or_404 from django.utils import timezone from django.db.models import Q from django.views.generic import TemplateView, DetailView, ListView from django.views.decorators.http import require_POST from django.views.decorators.csrf import csrf_exempt from django.http import JsonResponse, HttpResponsePermanentRedirect from django.core.files.storage import default_storage from django.core.files.base import ContentFile from django.core.files import File from http import HTTPStatus from core.forms import RequestForm from core.models import (StaticPage, TransportBrand, TransportModel, MachineryBrand, MachineryModel, Review, Video, Article, TransportExperience, MachineryExperience, MainLot, KoreaLot, MachineryLot, FormRequest, StockAuto, City, EngineType, ImportType) from core.mixins import (MainPageReviewsMixin, MainPageVideosMixin, MainPageExperienceMixin, MainPageArticlesMixin, MainPageQuestionsMixin, MainPageJapanLotsMixin, MainPageKoreanLotsMixin, MainPageMachineryLotsMixin, MainPageTruckLotsMixin, AllLotsMixin, AllCatalogLotsMixin, ArticlesSidebarMixin, ReviewsQuerySetMixin, ArticlesQuerySetMixin, BannersSidebarMixin, ExperienceJapanQuerySetMixin, ExperienceKoreaQuerySetMixin, ExperienceMachineryQuerySetMixin, ExperienceAllQuerySetMixin, JapanLotsMixin, KoreanLotsMixin, MachineryLotsMixin, DocumentsMixin, JapanBrandsMixin, KoreaBrandsMixin, MachineryBrandsMixin, ColorMixin, MachineryFilterMixin, MainBrandsMixin, MainMachineryFiltersMixin, TruckBrandsMixin, TruckLotsMixin, MainPageStockAutoMixin, StockAutoQuerySetMixin, TitleMixin, YearsMixin) from core.enums import MaxReviews, MaxVideos, MaxArticles, MaxTransportExperience, MaxMachineryExperience, MaxStockAuto from core.utils import (similar_japan_experience, similar_korea_experience, similar_machinery_experience, quality_japan, quality_korea, quality_machinery, similar_japan, similar_korea, similar_machinery, send_message_to_mail_and_telegram, create_lead, japan_models_available, korea_models_available, machinery_models_available, ) @csrf_exempt def redirect_to(request, to): return HttpResponsePermanentRedirect(to) def handle_404_view(request, exception): response = render(request, '404.html') response.status_code = HTTPStatus.NOT_FOUND return response def handle_500_view(request): response = render(request, '500.html') response.status_code = HTTPStatus.INTERNAL_SERVER_ERROR return response class StaticPageView(DetailView): template_name = 'static_page.html' model = StaticPage context_object_name = 'page' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['title'] = self.object.title context['breadcrumbs'] = { 'second_level': self.object.title, } return context @require_POST def consultation(request): data = {} data['name'] = request.POST.get('name') data['phone'] = request.POST.get('phone') data['budget'] = request.POST.get('budget') data['time'] = request.POST.get('time', 'не определен') data['comment'] = request.POST.get('comment') data['source'] = request.META.get('HTTP_REFERER') data['agreement'] = request.POST.get('agreement') if not data['agreement']: return JsonResponse( {'success': False, 'error': 'No consent to the processing of personal data'}, status=400 ) file = request.FILES.get('file') if file: form = RequestForm(request.POST, request.FILES) if form.is_valid(): new_request = form.save() file_path = f'{settings.DOMAIN}{settings.MEDIA_URL}{new_request.file}' data['file'] = file_path try: status_code = create_lead(data.get('name'), data.get('phone'), data.get('source'), data.get('budget'), data.get('time'), data.get('comment'), data.get('file')) except: status_code = 500 if str(status_code) == '200': status_code = 'успешно' data['code'] = status_code send_message_to_mail_and_telegram(template='consultation.txt', data=data) return JsonResponse({'success': True}, status=200) def get_transport_models(request): brand_id = request.GET.get('brand_id') models_options = '' if brand_id: brand = get_object_or_404(TransportBrand, id=brand_id) for model in TransportModel.objects.filter(brand=brand).distinct(): country = 'не определено' if model.category == '1': country = 'Япония' elif model.category == '2': country = 'Корея' models_options += f'' return JsonResponse({'models': models_options}) def get_experience_transport_models(request): brand_id = request.GET.get('brand_id') category = request.GET.get('category') models_options = '' if brand_id: brand = get_object_or_404(TransportBrand, id=brand_id) for model in TransportModel.objects.filter(Q(transport_experience__isnull=False) & Q(transport_experience__category=category) & Q(transport_experience__brand=brand) & Q(category=category)).distinct(): models_options += f'' return JsonResponse({'models': models_options}) def get_stock_auto_models(request): brand_id = request.GET.get('brand_id') models_options = '' if brand_id: brand = get_object_or_404(TransportBrand, id=brand_id) for model in TransportModel.objects.filter(Q(autos_in_stock__isnull=False) & Q(autos_in_stock__brand=brand)).distinct(): model_category = model.category if not model.category: model_category = '1' models_options += f'' return JsonResponse({'models': models_options}) def get_catalog_transport_models(request): brand_id = request.GET.get('brand_id') category = request.GET.get('category') available_models = [] models_options = '' if brand_id: brand = get_object_or_404(TransportBrand, id=brand_id) if category == '1': available_models = japan_models_available(brand.db_id, request.ip_address) elif category == '2': available_models = korea_models_available(brand.db_id, request.ip_address) if available_models: for model in TransportModel.objects.filter(Q(brand=brand) & Q(category=category) & Q(db_id__in=available_models)).distinct(): models_options += f'' else: for model in TransportModel.objects.filter(Q(brand=brand) & Q(category=category)).distinct(): models_options += f'' return JsonResponse({'models': models_options}) def get_catalog_truck_models(request): brand_id = request.GET.get('brand_id') available_models = [] models_options = '' if brand_id: brand = get_object_or_404(TransportBrand, id=brand_id) available_models = japan_models_available(brand.db_id, request.ip_address, True) if available_models: for model in TransportModel.objects.filter(Q(brand=brand) & Q(category='1') & Q(db_id__in=available_models) & Q(db_id__in=settings.TRUCK_MODELS)).distinct(): models_options += f'' else: for model in TransportModel.objects.filter(Q(brand=brand) & Q(category='1') & Q(db_id__in=settings.TRUCK_MODELS)).distinct(): models_options += f'' return JsonResponse({'models': models_options}) def get_machinery_models(request): brand_id = request.GET.get('brand_id') models_options = '' if brand_id: brand = get_object_or_404(MachineryBrand, id=brand_id) for model in MachineryModel.objects.filter(brand=brand).distinct(): models_options += f'' return JsonResponse({'models': models_options}) def get_catalog_machinery_models(request): brand_id = request.GET.get('brand_id') models_options = '' if brand_id: available_models = [] brand = get_object_or_404(MachineryBrand, id=brand_id) available_models = machinery_models_available(brand.db_id, request.ip_address) if available_models: for model in MachineryModel.objects.filter(Q(brand=brand) & Q(title__in=available_models)).distinct(): models_options += f'' else: for model in MachineryModel.objects.filter(brand=brand).distinct(): models_options += f'' return JsonResponse({'models': models_options}) def get_experience_machinery_models(request): brand_id = request.GET.get('brand_id') models_options = '' if brand_id: brand = get_object_or_404(MachineryBrand, id=brand_id) for model in MachineryModel.objects.filter(Q(transport_experience__isnull=False) & Q(transport_experience__brand=brand)).distinct(): models_options += f'' return JsonResponse({'models': models_options}) @csrf_exempt @require_POST def get_quality_images(request): lot_id = request.POST.get('id') category = request.POST.get('category') try: if category == '1': lot = MainLot.objects.filter(db_id=lot_id).first() if not lot or lot.full_info is False: lot = quality_japan(lot_id, request.ip_address) if lot.cover: image = lot.cover else: image = lot.auction_list elif category == '2': lot = KoreaLot.objects.filter(db_id=lot_id).first() if not lot or lot.full_info is False: lot = quality_korea(lot_id, request.ip_address) image = lot.cover else: lot = MachineryLot.objects.filter(db_id=lot_id).first() if not lot or lot.full_info is False: lot = quality_machinery(lot_id, request.ip_address) image = lot.cover except: image = '#' return JsonResponse({'link': image}) class IndexView(TitleMixin, MainMachineryFiltersMixin, MainBrandsMixin, MainPageReviewsMixin, MainPageVideosMixin, MainPageExperienceMixin, MainPageArticlesMixin, MainPageQuestionsMixin, MainPageJapanLotsMixin, MainPageKoreanLotsMixin, MainPageTruckLotsMixin, MainPageStockAutoMixin, TemplateView, ): template_name = 'index.html' title = 'Главная' class ServicesView(TitleMixin, MainPageReviewsMixin, MainPageExperienceMixin, AllLotsMixin, TemplateView): template_name = 'services.html' title = 'Услуги' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Услуги', } context['page_active'] = 'services' return context class AboutView(TitleMixin, MainPageReviewsMixin, MainPageExperienceMixin, AllLotsMixin, TemplateView): template_name = 'about.html' title = 'О компании' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Компания', } context['page_active'] = 'about' return context class WarningView(TitleMixin, DocumentsMixin, ArticlesSidebarMixin, TemplateView): template_name = 'warning.html' title = 'Остерегайтесь мошенников' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Остерегайтесь мошенников', } context['page_active'] = 'warning' return context class ContactsView(TitleMixin, TemplateView): template_name = 'contacts.html' title = 'Контакты' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Компания', 'second_level_href': 'about', 'third_level': 'Контакты', } context['page_active'] = 'contacts' return context class ReviewsListView(TitleMixin, ReviewsQuerySetMixin, ListView): template_name = 'reviews.html' model = Review context_object_name = 'reviews' paginate_by = MaxReviews.REVIEWS_PAGE title = 'Отзывы' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['all_reviews_count'] = Review.objects.filter(is_active=True).count() context['yandex_reviews_count'] = Review.objects.filter(is_active=True, source='1').count() context['two_gis_reviews_count'] = Review.objects.filter(is_active=True, source='2').count() context['vlru_reviews_count'] = Review.objects.filter(is_active=True, source='3').count() context['breadcrumbs'] = { 'second_level': 'Компания', 'second_level_href': 'about', 'third_level': 'Отзывы', } context['page_active'] = 'reviews' return context class VideosListView(TitleMixin, ListView): template_name = 'video.html' model = Video context_object_name = 'videos' paginate_by = MaxVideos.VIDEOS_PAGE title = 'Видеообзоры' def get_queryset(self): return super().get_queryset().filter(is_active=True) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Компания', 'second_level_href': 'about', 'third_level': 'Видеообзоры', } context['page_active'] = 'video' return context class ArticlesListView(TitleMixin, ArticlesQuerySetMixin, ListView): template_name = 'articles.html' model = Article context_object_name = 'articles' paginate_by = MaxArticles.ARTICLES_PAGE title = 'Новости и статьи' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Компания', 'second_level_href': 'about', 'third_level': 'Новости и статьи', } context['page_active'] = 'articles' return context class ArticleDetailView(AllLotsMixin, BannersSidebarMixin, DetailView): template_name = 'article_details.html' model = Article context_object_name = 'article' def get_queryset(self): return super().get_queryset().select_related('cover') def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Новости и статьи', 'second_level_href': 'articles', 'third_level': self.object.title } context['sidebar_articles'] = Article.objects.filter( Q(is_active=True) & Q(date__lte=timezone.now()) & ~Q(id=self.object.id)).order_by( '?').distinct().select_related('cover')[:MaxArticles.SIDEBAR] return context class AuctionChinaView(TitleMixin, MainPageReviewsMixin, MainPageExperienceMixin, TemplateView): template_name = 'auction_china.html' title = 'Аукцион Китая' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Услуги', 'second_level_href': 'services', 'third_level': 'Автомобили с торговых площадок Китая', } context['page_active'] = 'service_auction_china' return context class AuctionJapanView(TitleMixin, AllLotsMixin, MainPageReviewsMixin, MainPageExperienceMixin, TemplateView): template_name = 'auction_japan.html' title = 'Аукцион Японии' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Услуги', 'second_level_href': 'services', 'third_level': 'Автомобили с торговых площадок Японии', } context['page_active'] = 'service_auction_japan' return context class AuctionKoreaView(TitleMixin, AllLotsMixin, MainPageReviewsMixin, MainPageExperienceMixin, TemplateView): template_name = 'auction_korea.html' title = 'Аукцион Кореи' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Услуги', 'second_level_href': 'services', 'third_level': 'Автомобили с торговых площадок Кореи', } context['page_active'] = 'service_auction_korea' return context class AuctionMachineryView(TitleMixin, AllLotsMixin, MainPageReviewsMixin, MainPageExperienceMixin, TemplateView): template_name = 'auction_machinery.html' title = 'Аукцион спецтехники из Японии' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Услуги', 'second_level_href': 'services', 'third_level': 'Спецтехника с аукционов Японии', } context['page_active'] = 'service_auction_machinery' return context class AuctionVladivostokView(TitleMixin, AllLotsMixin, MainPageReviewsMixin, MainPageExperienceMixin, TemplateView): template_name = 'auction_vladivostok.html' title = 'Доставка автомобилей из Владивостока' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Услуги', 'second_level_href': 'services', 'third_level': 'Доставка автомобилей из Владивостока', } context['page_active'] = 'service_auction_vladivostok' return context class AuctionTaxView(TitleMixin, AllLotsMixin, MainPageReviewsMixin, MainPageExperienceMixin, TemplateView): template_name = 'auction_tax.html' title = 'Ввоз автомобилей под полную пошлину' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Услуги', 'second_level_href': 'services', 'third_level': 'Ввоз автомобилей под полную пошлину', } context['page_active'] = 'service_auction_tax' return context class AllExperienceListView(MainPageReviewsMixin, MainPageVideosMixin, ExperienceAllQuerySetMixin, ListView): template_name = 'experience_all.html' context_object_name = 'lots' paginate_by = MaxTransportExperience.TRANSPORT_PAGE def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Компания', 'second_level_href': 'about', 'third_level': 'Привезенные авто', } context['page_active'] = 'experience_auto' return context class JapanExperienceListView(MainPageReviewsMixin, MainPageVideosMixin, ExperienceJapanQuerySetMixin, ListView): template_name = 'experience_japan.html' model = TransportExperience context_object_name = 'lots' paginate_by = MaxTransportExperience.TRANSPORT_PAGE def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Компания', 'second_level_href': 'about', 'third_level': 'Привезенные авто', } context['page_active'] = 'experience_auto' return context class KoreaExperienceListView(MainPageReviewsMixin, MainPageVideosMixin, ExperienceKoreaQuerySetMixin, ListView): template_name = 'experience_korea.html' model = TransportExperience context_object_name = 'lots' paginate_by = MaxTransportExperience.TRANSPORT_PAGE def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Компания', 'second_level_href': 'about', 'third_level': 'Привезенные авто', } context['page_active'] = 'experience_auto' return context class MachineryExperienceListView(MainPageReviewsMixin, MainPageVideosMixin, ExperienceMachineryQuerySetMixin, ListView): template_name = 'experience_machinery.html' model = MachineryExperience context_object_name = 'lots' paginate_by = MaxMachineryExperience.MACHINERY_PAGE def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Компания', 'second_level_href': 'about', 'third_level': 'Привезенные авто', } return context class TransportExperienceDetailView(MainPageReviewsMixin, DetailView): template_name = 'experience_auto_details.html' model = TransportExperience context_object_name = 'experience' def get_queryset(self): return super().get_queryset().select_related('cover', 'slider') def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Компания', 'second_level_href': 'about', 'third_level': 'Привезенные авто', 'third_level_href': 'experience', 'fourth_level': self.object.title, } if self.object.category == '1': try: context['lots'] = similar_japan_experience(self.object, self.request.ip_address) except: context['lots'] = None else: try: context['lots'] = similar_korea_experience(self.object, self.request.ip_address) except: context['lots'] = None return context class MachineryExperienceDetailView(MainPageReviewsMixin, DetailView): template_name = 'experience_auto_details.html' model = MachineryExperience context_object_name = 'experience' def get_queryset(self): return super().get_queryset().select_related('cover', 'slider') def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Компания', 'second_level_href': 'about', 'third_level': 'Привезенные авто', 'third_level_href': 'experience', 'fourth_level': self.object.title, } try: context['lots'] = similar_machinery_experience(self.object, self.request.ip_address) except: context['lots'] = None return context class LotJapanDetailView(MainPageReviewsMixin, TemplateView): template_name = 'lot_japan.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) lot_id = self.kwargs.get('lot_id') lot_id = lot_id.split('-')[-1] lot = MainLot.objects.filter(db_id=lot_id).first() if not lot or lot.full_info is False: try: lot = quality_japan(lot_id, self.request.ip_address) except: raise Http404('Лот не найден') context['breadcrumbs'] = { 'second_level': 'Автомобили из Японии', 'second_level_href': 'catalog/japan', 'third_level': lot.full_title, } curr_title = 'Закажи' curr_description = None if lot.car_model: curr_title += f' {lot.car_model.brand.title}' curr_title += f' {lot.car_model.title}' curr_description = f'Присмотритесь к {lot.car_model.brand.title} {lot.car_model.title}' if lot.year: curr_title += f' {lot.year} года' if curr_description: curr_description += f' {lot.year} года' if lot.mileage: curr_title += f' с пробегом {lot.mileage} км.' curr_title += ' с аукционов Японии' if curr_description: curr_description += ' - ваш идеальный выбор! Unionauto предлагает большой ассортимент автомобилей и спецтехники с аукционов Японии с доставкой по городам РФ.' context['curr_title'] = curr_title context['curr_description'] = curr_description context['lot'] = lot try: context['lots'] = similar_japan(lot, self.request.ip_address) except: context['lots'] = None return context class LotKoreaDetailView(MainPageReviewsMixin, TemplateView): template_name = 'lot_korea.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) lot_id = self.kwargs.get('lot_id') lot_id = lot_id.split('-')[-1] lot = KoreaLot.objects.filter(db_id=lot_id).first() if not lot or lot.full_info is False: try: lot = quality_korea(lot_id, self.request.ip_address) except: raise Http404('Лот не найден') context['breadcrumbs'] = { 'second_level': 'Автомобили из Кореи', 'second_level_href': 'catalog/korea', 'third_level': lot.full_title, } curr_title = 'Закажи' curr_description = None if lot.car_model: curr_title += f' {lot.car_model.brand.title}' curr_title += f' {lot.car_model.title}' curr_description = f'Присмотритесь к {lot.car_model.brand.title} {lot.car_model.title}' if lot.year: curr_title += f' {lot.year} года' if curr_description: curr_description += f' {lot.year} года' if lot.mileage: curr_title += f' с пробегом {lot.mileage} км.' curr_title += ' с доставкой из Кореи' if curr_description: curr_description += ' - ваш идеальный выбор! Unionauto предлагает большой ассортимент автомобилей и спецтехники прямо из Кореи и Японии с доставкой по городам РФ.' context['curr_title'] = curr_title context['curr_description'] = curr_description context['lot'] = lot try: context['lots'] = similar_korea(lot, self.request.ip_address) except: context['lots'] = None return context class LotMachineryDetailView(MainPageReviewsMixin, TemplateView): template_name = 'lot_machinery.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) lot_id = self.kwargs.get('lot_id') lot_id = lot_id.split('-')[-1] lot = MachineryLot.objects.filter(db_id=lot_id).first() if not lot or lot.full_info is False: try: lot = quality_japan(lot_id, self.request.ip_address) except: raise Http404('Лот не найден') context['breadcrumbs'] = { 'second_level': 'Спецтехника из Японии', 'second_level_href': 'catalog/machinery', 'third_level': lot.full_title, } curr_title = 'Закажи' curr_description = None if lot.machinery_model: curr_title += f' {lot.machinery_model.brand.title}' curr_title += f' {lot.machinery_model.title}' curr_description = f'Присмотритесь к {lot.machinery_model.brand.title} {lot.machinery_model.title}' if lot.year: curr_title += f' {lot.year} года' if curr_description: curr_description += f' {lot.year} года' if lot.mileage: curr_title += f' с пробегом {lot.mileage} км.' curr_title += ' с аукционов Японии' if curr_description: curr_description += ' - ваш идеальный выбор! Unionauto предлагает большой ассортимент автомобилей и спецтехники с аукционов Японии с доставкой по городам РФ.' context['curr_title'] = curr_title context['curr_description'] = curr_description context['lot'] = lot try: context['lots'] = similar_machinery(lot, self.request.ip_address) except: context['lots'] = None return context class LotTruckDetailView(MainPageReviewsMixin, TemplateView): template_name = 'lot_japan.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) lot_id = self.kwargs.get('lot_id') lot_id = lot_id.split('-')[-1] lot = MainLot.objects.filter(db_id=lot_id).first() if not lot or lot.full_info is False: try: lot = quality_japan(lot_id, self.request.ip_address) except: raise Http404('Лот не найден') context['breadcrumbs'] = { 'second_level': 'Грузовики из Японии', 'second_level_href': 'catalog/truck', 'third_level': lot.full_title, } curr_title = 'Закажи' curr_description = None if lot.car_model: curr_title += f' {lot.car_model.brand.title}' curr_title += f' {lot.car_model.title}' curr_description = f'Присмотритесь к {lot.car_model.brand.title} {lot.car_model.title}' if lot.year: curr_title += f' {lot.year} года' if curr_description: curr_description += f' {lot.year} года' if lot.mileage: curr_title += f' с пробегом {lot.mileage} км.' curr_title += ' с аукционов Японии' if curr_description: curr_description += ' - ваш идеальный выбор! Unionauto предлагает большой ассортимент грузовиком и спецтехники с аукционов Японии с доставкой по городам РФ.' context['curr_title'] = curr_title context['curr_description'] = curr_description context['lot'] = lot try: context['lots'] = similar_japan(lot, self.request.ip_address, True) except: context['lots'] = None return context class CatalogAllView(AllCatalogLotsMixin, TemplateView): template_name = 'catalog_all.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Автомобили и спецтехника', } context['page_active'] = 'catalog_all' context[ 'curr_title'] = 'Автомобили и спецтехника из Японии, Кореи и Китая: купить по доступным ценам | Union Auto' context[ 'curr_description'] = 'Хотите купить надежный и качественный автомобиль или спецтехнику по доступной цене? У нас вы найдете большой выбор авто из Японии, Кореи и Китая с аукционов. Доставка, таможенное оформление, гарантия качества.' return context class CatalogJapanView(ColorMixin, JapanBrandsMixin, YearsMixin, JapanLotsMixin, TemplateView): template_name = 'catalog_japan.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Автомобили из Японии', } context['page_active'] = 'catalog_japan' return context class CatalogKoreaView(ColorMixin, KoreaBrandsMixin, YearsMixin, KoreanLotsMixin, TemplateView): template_name = 'catalog_korea.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Автомобили из Кореи', } context['page_active'] = 'catalog_korea' return context class CatalogMachineryView(MachineryFilterMixin, MachineryBrandsMixin, MachineryLotsMixin, TemplateView): template_name = 'catalog_machinery.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Спецтехника из Японии', } context['page_active'] = 'catalog_truck' return context class CatalogTruckView(ColorMixin, TruckBrandsMixin, TruckLotsMixin, TemplateView): template_name = 'catalog_truck.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Грузовики', } context['page_active'] = 'catalog_truck' return context class XMLCarsFeedView(TemplateView): content_type = 'text/xml' template_name = 'feed/cars.xml' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['japan_cars'] = MainLot.objects.filter(full_info=True).all() context['korea_cars'] = KoreaLot.objects.filter(full_info=True).all() context['domain'] = settings.DOMAIN return context class XMLMachineryFeedView(TemplateView): content_type = 'text/xml' template_name = 'feed/machinery.xml' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['machinery'] = MachineryLot.objects.filter(full_info=True).all() context['domain'] = settings.DOMAIN return context class StockAutoDetailView(MainPageReviewsMixin, TemplateView): template_name = 'stock_auto_details.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) try: lot_id = self.kwargs.get('lot_id') lot_id = lot_id.split('-')[-1] except: lot_id = -1 context['stock_auto'] = get_object_or_404(StockAuto, id=lot_id) try: context['lots'] = similar_japan_experience(context['stock_auto'], self.request.ip_address) except: pass context['breadcrumbs'] = { 'second_level': 'Компания', 'second_level_href': 'about', 'third_level': 'Авто в наличии', 'third_level_href': 'stock-auto', 'fourth_level': context['stock_auto'].title, } context['page_active'] = 'stock_auto' if not context.get('lots'): try: context['lots'] = similar_korea_experience(context['stock_auto'], self.request.ip_address) except: pass return context class StockAutoListView(MainPageReviewsMixin, MainPageVideosMixin, StockAutoQuerySetMixin, ListView): template_name = 'catalog_stock_auto.html' model = StockAuto context_object_name = 'lots' paginate_by = MaxStockAuto.TRANSPORT_PAGE def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['breadcrumbs'] = { 'second_level': 'Компания', 'second_level_href': 'about', 'third_level': 'Авто в наличии', } context['page_active'] = 'stock_auto' context['cities'] = City.objects.filter(autos_in_stock__isnull=False).distinct() context['imports'] = ImportType.objects.filter(autos_in_stock__isnull=False).distinct() context['engines'] = EngineType.objects.filter(autos_in_stock__isnull=False).distinct() return context