This commit is contained in:
Mamalizz
2025-02-08 23:50:46 +03:30
21 changed files with 482 additions and 565 deletions
-437
View File
@@ -1,437 +0,0 @@
from dotenv import load_dotenv
# from http.cookiejar import debug
from pathlib import Path
from datetime import timedelta
import os
from django.templatetags.static import static
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
# TODO CREATE A ENV WITH THIS NAME
### keep the .env name to .env.local if you want to change this name you should change it in here too when you load this env
load_dotenv(".env.local")
DOMAIN = os.getenv("DOMAIN")
API_DOMAIN = os.getenv("API_DOMAIN")
OPENAI_API_KEY = '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'
# TODO update telegram bot token
TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
# TODO update email bullshit
EMAIL_BACKEND = os.getenv("EMAIL_BACKEND")
EMAIL_HOST = os.getenv("EMAIL_HOST")
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD")
DEFAULT_FROM_EMAIL = os.getenv("SECRET_KEY")
SECRET_KEY = os.getenv("SECRET_KEY")
DEBUG = True
# in production lists of allowed hosts and allowed orgins will genrate
# in development every host and orgin will be true
# in prodcution it will use the postgres info you enterd in .env.local
# in development it will use the sqlite
BASE_DIR = Path(__file__).resolve().parent.parent
if DEBUG:
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', DOMAIN, API_DOMAIN]
CSRF_TRUSTED_ORIGINS = [
f"https://{DOMAIN}",
f"http://{DOMAIN}",
f"https://{API_DOMAIN}",
f"http://{API_DOMAIN}",
]
# CORS_ALLOWED_ORIGINS = [f"https://{API_DOMAIN}", f"http://{API_DOMAIN}",
# f"http://{DOMAIN}", f"https://{DOMAIN}", ]
# import re
# CORS_ALLOWED_ORIGIN_REGEXES = [
# re.compile(r'^https?://(?:\w+\.)?{}$'.format(re.escape(API_DOMAIN))),
# re.compile(r'^https?://(?:\w+\.)?{}$'.format(re.escape(DOMAIN))),
# re.compile(r'^https?://(?:\w+\.)?localhost:\d+$'),
# re.compile(r'^https?://(?:\w+\.)?127\.0\.0\.1:\d+$'),
# ]
CORS_ALLOW_ALL_ORIGINS = True
# database postgres
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.getenv("DB_NAME"),
'USER': os.getenv("DB_USER"),
'PASSWORD': os.getenv("DB_PASSWORD"),
'HOST': os.getenv("DB_HOST"),
'PORT': os.getenv("DB_PORT"),
}
}
else:
CORS_ALLOW_ALL_ORIGINS = True
# sqlite database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Application definition
INSTALLED_APPS = [
# unfold theme
"unfold",
"unfold.contrib.filters",
"unfold.contrib.forms",
"unfold.contrib.inlines",
"unfold.contrib.import_export",
"unfold.contrib.guardian",
"unfold.contrib.simple_history",
# django
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# thired party apps
'corsheaders',
'rest_framework',
'drf_spectacular',
'django_cleanup.apps.CleanupConfig',
'django_filters',
'rest_framework_simplejwt',
'rest_framework_simplejwt.token_blacklist',
'rest_framework.authtoken',
'import_export',
# custom apps
'product',
'account',
'ticket',
'chat',
'order',
'home',
'blog',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
"whitenoise.middleware.WhiteNoiseMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'core.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / "templates"],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'core.wsgi.application'
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
MEDIA_URL = '/shop_media/'
MEDIA_ROOT = '/app/media'
STATIC_URL = '/shop_static/'
STATIC_ROOT = '/app/static'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'custom_static'),
BASE_DIR / "core" / "static"
]
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# AUTH_USER_MODEL = 'accounts.User'
REST_FRAMEWORK = {
# 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
'DEFAULT_RENDERER_CLASSES': [
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
],
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
# 'DEFAULT_PERMISSION_CLASSES': [
# 'rest_framework.permissions.IsAuthenticated',
# ],
}
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(days=1),
'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
'ROTATE_REFRESH_TOKENS': True,
'BLACKLIST_AFTER_ROTATION': True,
}
SPECTACULAR_SETTINGS = {
'TITLE': os.getenv("SITE_TITLE"),
'DESCRIPTION': os.getenv("SITE_TITLE"),
'VERSION': '1.0.0',
'SERVE_INCLUDE_SCHEMA': False,
'COMPONENT_SPLIT_REQUEST': True
}
UNFOLD = {
"SITE_TITLE": os.getenv("SITE_TITLE"),
"SITE_HEADER": os.getenv("SITE_HEADER"),
"SITE_URL": DOMAIN,
"THEME": 'dark',
"SITE_SYMBOL": "settings",
"DASHBOARD_CALLBACK": "core.views.dashboard_callback",
"SITE_FAVICONS": [
{
"rel": "icon",
"sizes": "32x32",
"type": "image/svg+xml",
"href": lambda request: static("favicon.svg"),
},
],
"LOGIN": {
"image": lambda request: static("favicon.png"),
},
"BORDER_RADIUS": "8px",
"SHOW_HISTORY": True,
"SHOW_VIEW_ON_SITE": True,
"ENVIRONMENT": "core.settings.environment_callback",
"COLORS": {
"base": {
"50": "250 250 250",
"100": "245 245 245",
"200": "229 229 229",
"300": "212 212 212",
"400": "163 163 163",
"500": "115 115 115",
"600": "82 82 82",
"700": "64 64 64",
"800": "38 38 38",
"900": "23 23 23",
"950": "10 10 10"
},
"primary": {
"50": "240 253 244",
"100": "220 252 231",
"200": "187 247 208",
"300": "134 239 172",
"400": "74 222 128",
"500": "34 197 94",
"600": "22 163 74",
"700": "21 128 61",
"800": "22 101 52",
"900": "20 83 45",
"950": "5 46 22"
},
"font": {
"subtle-light": "var(--color-base-500)", # text-base-500
"subtle-dark": "var(--color-base-400)", # text-base-400
"default-light": "var(--color-base-600)", # text-base-600
"default-dark": "var(--color-base-300)", # text-base-300
"important-light": "var(--color-base-900)", # text-base-900
"important-dark": "var(--color-base-100)", # text-base-100
},
},
"EXTENSIONS": {
"modeltranslation": {
"flags": {
"en": "🇬🇧",
},
},
},
"SIDEBAR": {
"show_search": True,
"show_all_applications": True,
"navigation": [
{
"separator": False, # Top border
"collapsible": False, # Collapsible group of links
"items": [
{
"title": _("داشبرد ادمین"),
"icon": "dashboard",
"link": reverse_lazy("admin:index"),
},
{
"title": _("سفارشات"),
"icon": "shopping_cart",
"link": reverse_lazy("admin:order_ordermodel_changelist"),
"badge": "utils.admin.admin_pending_count",
},
],
},
{
"title": _("محصولات فروشگاه"),
"separator": True,
"collapsible": False,
"items": [
{
"title": _("محصولات"),
"icon": "redeem",
"link": reverse_lazy("admin:product_productmodel_changelist"),
},
{
"title": _("نظرات"),
"icon": "chat",
"link": reverse_lazy("admin:product_commentmodel_changelist"),
},
{
"title": _("قیمت دلار"),
"icon": "payments",
"link": reverse_lazy("admin:product_dollormodel_changelist"),
"badge": "utils.admin.dollor_price",
},
],
},
{
"title": _("سکشن دسته بندی"),
"separator": True,
"collapsible": False,
"items": [
{
"title": _("دسته بندی"),
"icon": "category",
"link": reverse_lazy("admin:product_maincategorymodel_changelist"),
},
{
"title": _("زیر دسته بندی"),
"icon": "category",
"link": reverse_lazy("admin:product_subcategorymodel_changelist"),
}
],
},
{
"title": _("سکشن های نمایشی"),
"separator": True,
"collapsible": True,
"items": [
{
"title": _("اسلاید ها"),
"icon": "slide_library",
"link": reverse_lazy("admin:home_slidermodel_changelist"),
},
{
"title": _("عکس مقایسه"),
"icon": "compare",
"link": reverse_lazy("admin:home_homeimagemodel_changelist"),
}
,
{
"title": _("مقالات و بلاگ ها"),
"icon": "newsmode",
"link": reverse_lazy("admin:blog_blogmodel_changelist"),
}
],
},
{
"title": _("کاربران و مشتریان"),
"separator": True,
"collapsible": True,
"items": [
{
"title": _("کاربران"),
"icon": "person",
"link": reverse_lazy("admin:account_user_changelist"),
},{
"title": _("چت محصول"),
"icon": "chat",
"link": reverse_lazy("admin:chat_productchatmodel_changelist"),
},
{
"title": _("ادرس ها"),
"icon": "contact_mail",
"link": reverse_lazy("admin:account_useraddressmodel_changelist"),
},
],
},
{
"title": _("پشتیبانی و تیکت"),
"separator": True,
"collapsible": True,
"items": [
{
"title": _("تیکت"),
"icon": "confirmation_number",
"link": reverse_lazy("admin:ticket_ticket_changelist"),
},
],
},
],
},
}
AUTH_USER_MODEL = 'account.User'
def environment_callback(request):
return ["نسخه ی توسعه", "success"]
+31 -1
View File
@@ -172,7 +172,13 @@ UNFOLD = {
"title": _("مقالات و بلاگ ها"),
"icon": "newsmode",
"link": reverse_lazy("admin:blog_blogmodel_changelist"),
}
},
{
"title": _("نمایش کیس ها"),
"icon": "devices",
"link": reverse_lazy("admin:home_showcaseslider_changelist"),
},
],
},
@@ -216,6 +222,30 @@ UNFOLD = {
],
},
{
"title": _("بخش تنوع محصول"),
"separator": True,
"collapsible": True,
"items": [
{
"title": _("نوع صفت"),
"icon": "format_list_bulleted_add",
"link": reverse_lazy("admin:product_attributetype_changelist"),
},
{
"title": _("مقدار صفت"),
"icon": "variable_add",
"link": reverse_lazy("admin:product_attributevalue_changelist"),
},
{
"title": _("تنوع محصول"),
"icon": "photo_prints",
"link": reverse_lazy("admin:product_productvariant_changelist"),
},
],
},
],
+1 -1
View File
@@ -1,3 +1,3 @@
*:not(span[class^="material"]){
*:not(span){
font-family: 'IRANYekanXVF' !important;
}
+17
View File
@@ -8,6 +8,23 @@ from unfold.contrib.forms.widgets import ArrayWidget, WysiwygWidget
from django.contrib.postgres.fields import ArrayField
@admin.register(ShowCaseSlider)
class ShowCaseSliderAdmin(ModelAdmin, ImportExportModelAdmin):
import_form_class = ImportForm
export_form_class = ExportForm
search_fields = ['title']
compressed_fields = False
warn_unsaved_form = True
formfield_overrides = {
ArrayField: {
"widget": ArrayWidget,
}
}
@admin.register(SliderModel)
class SliderAdmin(ModelAdmin, ImportExportModelAdmin):
import_form_class = ImportForm
@@ -0,0 +1,27 @@
# Generated by Django 5.1.2 on 2025-02-08 13:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('home', '0003_alter_homeimagemodel_description1_and_more'),
]
operations = [
migrations.CreateModel(
name='ShowCaseSlider',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=30)),
('description', models.CharField(max_length=150)),
('link', models.URLField()),
('image', models.ImageField(upload_to='show_case/')),
],
options={
'verbose_name': 'مدل نمایش کیس',
'verbose_name_plural': 'مدل نمایش کیس ها',
},
),
]
@@ -0,0 +1,33 @@
# Generated by Django 5.1.2 on 2025-02-08 17:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('home', '0004_showcaseslider'),
]
operations = [
migrations.AlterField(
model_name='showcaseslider',
name='description',
field=models.CharField(max_length=150, verbose_name='عنوان'),
),
migrations.AlterField(
model_name='showcaseslider',
name='image',
field=models.ImageField(upload_to='show_case/', verbose_name='عکس'),
),
migrations.AlterField(
model_name='showcaseslider',
name='link',
field=models.URLField(verbose_name='لینک'),
),
migrations.AlterField(
model_name='showcaseslider',
name='title',
field=models.CharField(max_length=30, verbose_name='عنوان'),
),
]
+14 -1
View File
@@ -32,4 +32,17 @@ class HomeImageModel(models.Model):
return f'{self.title1} - {self.title2}'
class Meta:
verbose_name = 'مدل عکس تفاوت خانه'
verbose_name_plural = 'مدل عکس تفاوت خانه'
verbose_name_plural = 'مدل عکس تفاوت خانه'
class ShowCaseSlider(models.Model):
title = models.CharField(max_length=30, verbose_name='عنوان')
description = models.CharField(max_length=150, verbose_name='عنوان')
link = models.URLField(verbose_name='لینک')
image = models.ImageField(upload_to='show_case/', verbose_name='عکس')
def __str__(self):
return self.title
class Meta:
verbose_name = 'مدل نمایش کیس'
verbose_name_plural = 'مدل نمایش کیس ها'
+7 -1
View File
@@ -14,4 +14,10 @@ class SliderSerializer(serializers.ModelSerializer):
class HomeImageSerializer(serializers.ModelSerializer):
class Meta:
model = HomeImageModel
exclude = ('unique_filed',)
exclude = ('unique_filed',)
class ShowCaseSliderSerialzier(serializers.ModelSerializer):
class Meta:
model = ShowCaseSlider
fields = "__all__"
+7 -3
View File
@@ -2,8 +2,8 @@ from django.shortcuts import render
from rest_framework.views import APIView, Response
from product.models import ProductModel, SubCategoryModel, DollorModel
from product.serializers import SubCategorySerializer, DynamicProductSerializer
from .serializers import SliderSerializer, HomeImageSerializer
from .models import SliderModel, HomeImageModel
from .serializers import *
from .models import *
from rest_framework import status
@@ -26,11 +26,15 @@ class HomeView(APIView):
home_image = HomeImageModel.objects.all().first()
home_image_ser = HomeImageSerializer(instance=home_image, context={'request': request})
show_cases = ShowCaseSlider.objects.all()
show_cases_ser = ShowCaseSliderSerialzier(instance=show_cases, many=True, context={'request': request})
response = {
'sliders': slider_ser.data,
'sub_categories': sub_category_ser.data,
'products': product_ser.data,
'difreance_section': home_image_ser.data
'difreance_section': home_image_ser.data,
'show_case_slider': show_cases_ser.data
}
return Response(response, status=status.HTTP_200_OK)
-22
View File
@@ -1,25 +1,3 @@
# #!/usr/bin/env python
# """Django's command-line utility for administrative tasks."""
# import os
# import sys
# def main():
# """Run administrative tasks."""
# os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
# try:
# from django.core.management import execute_from_command_line
# except ImportError as exc:
# raise ImportError(
# "Couldn't import Django. Are you sure it's installed and "
# "available on your PYTHONPATH environment variable? Did you "
# "forget to activate a virtual environment?"
# ) from exc
# execute_from_command_line(sys.argv)
# if __name__ == '__main__':
# main()
import os
import sys
+37 -24
View File
@@ -11,6 +11,15 @@ from unfold.widgets import (
)
from unfold.decorators import action, display
@admin.register(ProductVariant)
class ProductVariantAdmin(ModelAdmin, ImportExportModelAdmin):
import_form_class = ImportForm
export_form_class = ExportForm
autocomplete_fields = ['attributes']
warn_unsaved_form = True
@admin.register(ProductDetailCategory)
class ProductDetailCategoryAdmin(ModelAdmin, ImportExportModelAdmin):
import_form_class = ImportForm
@@ -59,7 +68,7 @@ class AttributeTypeAdmin(ModelAdmin, ImportExportModelAdmin):
class AttributeValueAdmin(ModelAdmin, ImportExportModelAdmin):
import_form_class = ImportForm
export_form_class = ExportForm
search_fields = ['value']
search_fields = ['value', 'attribute_type__name']
compressed_fields = True
warn_unsaved_form = True
@@ -82,7 +91,7 @@ class ProductVariantInLine(StackedInline):
extra = 0
show_change_link = True
tab = True
min_num = 1
autocomplete_fields = ['attributes']
# search_fields = ['']
@@ -112,11 +121,11 @@ class DetailModelAdmin(ModelAdmin, ImportExportModelAdmin):
class DetailModelInLine(StackedInline):
class DetailModelInLine(TabularInline):
model = ProductDetailModel
extra = 0
fields = ['detail', 'detail_category']
show_change_link = True
tab = True
autocomplete_fields = ['detail', 'detail_category']
@@ -128,15 +137,15 @@ class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin):
inlines = [ProductVariantInLine, DetailModelInLine]
readonly_fields = ('slug', )
search_fields = ['name', 'description', ]
list_filter = ['currency', 'show', 'category']
list_filter = ['show', 'category']
autocomplete_fields = ['related_products', 'in_pack_items',]
# compressed_fields = True
warn_unsaved_form = True
list_display = ['display_image', 'display_price', 'view', 'show', 'rating', 'category', 'discount', 'sell']
list_display = ['display_image', 'display_price', 'view', 'show', 'rating', 'category', ]
fieldsets = (
('فیلد های اصلی', {'fields': ('name', 'description', 'price', 'min_price', 'currency', 'discount', 'category', 'related_products', 'show',), "classes": ["tab"],}),
('فیلد های اصلی', {'fields': ('name', 'description', 'category', 'related_products', 'show',), "classes": ["tab"],}),
('فیلد های سيو', {'fields': ('meta_description', 'meta_keywords', 'meta_rating', 'slug'), "classes": ["tab"],}),
('فیلد های مربوط به کاربر', {'fields': ('rating', 'view', 'sell', ), "classes": ["tab"],}),
('فیلد های مربوط به کاربر', {'fields': ('rating', 'view',), "classes": ["tab"],}),
('فیلد های ایتم های پک', {'fields': ('in_pack_items', ), "classes": ["tab"],})
)
@@ -150,25 +159,28 @@ class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin):
}
def display_price(self, obj):
return 1000
return obj.get_toman_price()
display_price.short_description = 'قیمت تومانی'
@display(description='محصول', header=True)
def display_image(self, instance):
if instance.image1:
return [
instance.name,
None,
None,
{
"path": instance.image1.url,
"height": 30,
"width": 30,
"borderless": True,
# "squared": True,
},
]
return ('خالی',)
if instance and instance.variants.first() and instance.variants.first().attributes.first():
image = instance.variants.first().attributes.first().image.url if instance.variants.first().attributes.first().image else None
else:
image = None
return [
instance.name,
None,
None,
{
"path": image,
"height": 30,
"width": 30,
"borderless": True,
# "squared": True,
},
]
# @display(
# description=("نمایش در صفحه ی اصلی"),
# label={
@@ -221,9 +233,9 @@ class SubCategoryModelAdmin(ModelAdmin, ImportExportModelAdmin):
class CommentAdmin(ModelAdmin, ImportExportModelAdmin):
import_form_class = ImportForm
export_form_class = ExportForm
list_display = ['user', 'product', 'display_content','show']
list_display = ['user', 'product', 'display_content','review_status']
search_fields = ['content',]
list_filter = ['show',]
list_filter = ['review_status',]
compressed_fields = True
warn_unsaved_form = True
@@ -232,6 +244,7 @@ class CommentAdmin(ModelAdmin, ImportExportModelAdmin):
"widget": ArrayWidget,
}
}
radio_fields = {'review_status': admin.VERTICAL}
def display_content(self, obj):
return obj.content[0:35] + '...'
display_content.short_description = 'محتوای کامنت'
@@ -0,0 +1,71 @@
# Generated by Django 5.1.2 on 2025-02-06 19:12
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('product', '0015_attributetype_productdetailcategory_attributevalue_and_more'),
]
operations = [
migrations.RemoveField(
model_name='productmodel',
name='currency',
),
migrations.RemoveField(
model_name='productmodel',
name='discount',
),
migrations.RemoveField(
model_name='productmodel',
name='min_price',
),
migrations.RemoveField(
model_name='productmodel',
name='price',
),
migrations.RemoveField(
model_name='productmodel',
name='sell',
),
migrations.AddField(
model_name='productvariant',
name='currency',
field=models.CharField(choices=[('dollor', 'دلار'), ('toman', 'تومان'), ('derham', 'درهم')], default='dollor', max_length=20, verbose_name='نوع ارز'),
preserve_default=False,
),
migrations.AddField(
model_name='productvariant',
name='discount',
field=models.SmallIntegerField(default=0, verbose_name='تخفیف'),
),
migrations.AddField(
model_name='productvariant',
name='min_price',
field=models.PositiveIntegerField(default=1, help_text='این قیمت برای کف قیمتی محصول در نظر گرفته میشود', verbose_name='قیمت کف'),
preserve_default=False,
),
migrations.AddField(
model_name='productvariant',
name='sell',
field=models.IntegerField(default=0, verbose_name='فروش'),
),
migrations.AlterField(
model_name='attributevalue',
name='attribute_type',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='product.attributetype'),
),
migrations.AlterField(
model_name='attributevalue',
name='value',
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='مقدار نوع اتربیوت'),
),
migrations.AlterField(
model_name='productvariant',
name='price',
field=models.PositiveIntegerField(default=0, verbose_name='قیمت'),
),
]
@@ -0,0 +1,28 @@
# Generated by Django 5.1.2 on 2025-02-07 16:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('product', '0016_remove_productmodel_currency_and_more'),
]
operations = [
migrations.RemoveField(
model_name='commentmodel',
name='show',
),
migrations.AddField(
model_name='commentmodel',
name='review_status',
field=models.CharField(default='not_reviwed', max_length=30, verbose_name='نشان دادن کامنت'),
),
migrations.AddField(
model_name='commentmodel',
name='title',
field=models.CharField(default='', max_length=50),
preserve_default=False,
),
]
@@ -0,0 +1,18 @@
# Generated by Django 5.1.2 on 2025-02-08 13:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('product', '0017_remove_commentmodel_show_commentmodel_review_status_and_more'),
]
operations = [
migrations.AlterField(
model_name='commentmodel',
name='review_status',
field=models.CharField(choices=[('reviewed_and_confirmed', 'بررسی و تایید شده'), ('reviewed_and_rejected', 'بررسی شده و رد شده'), ('not_reviwed', 'بررسی نشده')], default='not_reviwed', max_length=30, verbose_name='نشان دادن کامنت'),
),
]
@@ -0,0 +1,40 @@
# Generated by Django 5.1.2 on 2025-02-08 17:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('product', '0018_alter_commentmodel_review_status'),
]
operations = [
migrations.RemoveField(
model_name='productmodel',
name='image1',
),
migrations.RemoveField(
model_name='productmodel',
name='image2',
),
migrations.RemoveField(
model_name='productmodel',
name='image3',
),
migrations.RemoveField(
model_name='productmodel',
name='video',
),
migrations.AddField(
model_name='attributevalue',
name='image',
field=models.ImageField(default='', upload_to='product_images/'),
preserve_default=False,
),
migrations.AddField(
model_name='attributevalue',
name='video',
field=models.FileField(blank=True, null=True, upload_to='product_videos/', verbose_name='ویدیو'),
),
]
@@ -0,0 +1,24 @@
# Generated by Django 5.1.2 on 2025-02-08 19:27
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('product', '0019_remove_productmodel_image1_and_more'),
]
operations = [
migrations.AddField(
model_name='productvariant',
name='max_price',
field=models.PositiveIntegerField(default=0, help_text='این قیمت برای سقف قیمتی محصول در نظر گرفته میشود', verbose_name='قیمت سقف'),
preserve_default=False,
),
migrations.AlterField(
model_name='productvariant',
name='attributes',
field=models.ManyToManyField(related_name='variant', to='product.attributevalue', verbose_name='ویژگی\u200cها'),
),
]
+44 -46
View File
@@ -100,23 +100,9 @@ class InPackItems(models.Model):
class ProductModel(models.Model):
name = models.CharField(max_length=255, verbose_name='نام')
description = models.TextField(verbose_name='توضیحات')
price = models.PositiveIntegerField(default=0, verbose_name='قیمت')
min_price = models.PositiveIntegerField(verbose_name='قیمت کف', help_text='این قیمت برای کف قیمتی محصول در نظر گرفته میشود')
currency_type = (
('dollor', 'دلار'),
('toman', 'تومان'),
('derham', 'درهم')
)
currency = models.CharField(verbose_name='نوع ارز', max_length=20, choices=currency_type)
image1 = models.ImageField(upload_to='product_images/', verbose_name='عکس اول')
image2 = models.ImageField(upload_to='product_images/', blank=True, null=True, verbose_name='عکس دوم')
image3 = models.ImageField(upload_to='product_images/', blank=True, null=True, verbose_name='عکس سوم')
video = models.FileField(upload_to='product_videos/', blank=True, null=True, verbose_name='ویدیو')
rating = models.PositiveIntegerField(default=0, verbose_name='امتیاز')
show = models.BooleanField(default=False, verbose_name='نمایش در خانه')
view = models.IntegerField(default=0, verbose_name='بازدید')
sell = models.IntegerField(default=0, verbose_name='فروش')
discount = models.SmallIntegerField(default=0, verbose_name='تخفیف')
slug = models.SlugField(max_length=50, unique=True, blank=True, null=True, allow_unicode=True,
verbose_name='نام یکتا', help_text="این فیلد را خالی بگذارید")
meta_description = models.CharField(max_length=300, blank=True, null=True, help_text='این فیلد را حتما پر کنید', verbose_name='متا دیسکریپشن')
@@ -127,35 +113,11 @@ class ProductModel(models.Model):
related_products = models.ManyToManyField('self', blank=True, verbose_name='محصولات مرتبط')
in_pack_items = models.ManyToManyField(InPackItems, blank=True, verbose_name='ایتم های داخل پک')
def format_discount_price(self):
discount_price = int(self.price * (100 - self.discount) / 100)
formatted_num = "{:,.0f}".format(discount_price)
return formatted_num
def __str__(self):
return self.name
def get_toman_price(self, dollor_price=None):
if not dollor_price:
dollor_object, _ = DollorModel.objects.get_or_create(unique_filed='unique')
dollor_price = dollor_object.price
dollar_to_dirham = 0.27
if dollor_price is None:
raise ValidationError({"dollor_price": "The 'dollor_price' must be provided in the context for dollar pricing."})
if self.currency == 'toman':
toman_price = self.price
elif self.currency == 'dollor':
toman_price = self.price * dollor_price
elif self.currency == 'derham':
toman_price = self.price * dollor_price * dollar_to_dirham
toman_price = toman_price if toman_price > self.min_price else self.min_price
return toman_price
def get_toman_price_after_discount(self):
return self.get_toman_price() * ((100 - self.discount) / 100)
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.name, allow_unicode=True)
@@ -209,10 +171,16 @@ class ProductDetailModel(models.Model):
class CommentModel(models.Model):
product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, related_name='comments', verbose_name='محصول')
title = models.CharField(max_length=50)
content = models.TextField(verbose_name='محتوای نظر')
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='کاربر')
timestamp = models.DateTimeField(auto_now_add=True, verbose_name='زمان ثبت کامنت')
show = models.BooleanField(default=True, verbose_name='نشان دادن کامنت')
status_types = (
('reviewed_and_confirmed', 'بررسی و تایید شده'),
('reviewed_and_rejected', 'بررسی شده و رد شده'),
('not_reviwed', 'بررسی نشده'),
)
review_status = models.CharField(default='not_reviwed', verbose_name='نشان دادن کامنت', max_length=30, choices=status_types)
class Meta:
verbose_name = 'نظر'
verbose_name_plural = 'نظرات'
@@ -228,10 +196,11 @@ class AttributeType(models.Model):
return self.name
class AttributeValue(models.Model):
attribute_type = models.ForeignKey(AttributeType, on_delete=models.CASCADE)
value = models.CharField(verbose_name='مقدار نوع اتربیوت', max_length=100)
attribute_type = models.ForeignKey(AttributeType, on_delete=models.CASCADE, blank=True, null=True)
value = models.CharField(verbose_name='مقدار نوع اتربیوت', max_length=100, blank=True, null=True)
color = models.CharField(verbose_name='رنک', max_length=7, blank=True, null=True)
image = models.ImageField(upload_to='product_images/')
video = models.FileField(upload_to='product_videos/', blank=True, null=True, verbose_name='ویدیو')
class Meta:
unique_together = ('attribute_type', 'value')
@@ -240,13 +209,42 @@ class AttributeValue(models.Model):
class ProductVariant(models.Model):
product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, related_name='variants', verbose_name='محصول')
attributes = models.ManyToManyField(AttributeValue, verbose_name='ویژگی‌ها')
attributes = models.ManyToManyField(AttributeValue, verbose_name='ویژگی‌ها', related_name='variant')
in_stock = models.PositiveIntegerField(default=0, verbose_name='تعداد موجود')
price = models.PositiveIntegerField(null=True, blank=True, verbose_name='قیمت (اختیاری)')
price = models.PositiveIntegerField(default=0, verbose_name='قیمت')
min_price = models.PositiveIntegerField(verbose_name='قیمت کف', help_text='این قیمت برای کف قیمتی محصول در نظر گرفته میشود')
max_price = models.PositiveIntegerField(verbose_name='قیمت سقف', help_text='این قیمت برای سقف قیمتی محصول در نظر گرفته میشود')
currency_type = (
('dollor', 'دلار'),
('toman', 'تومان'),
('derham', 'درهم')
)
sell = models.IntegerField(default=0, verbose_name='فروش')
currency = models.CharField(verbose_name='نوع ارز', max_length=20, choices=currency_type)
discount = models.SmallIntegerField(default=0, verbose_name='تخفیف')
class Meta:
verbose_name = 'تنوع محصول'
verbose_name_plural = 'تنوع‌های محصول'
def __str__(self):
return f"{self.product.name} - {', '.join(str(attr) for attr in self.attributes.all())}"
return f"{self.product.name} - {', '.join(str(attr) for attr in self.attributes.all())}"
def get_toman_price(self, dollor_price=None):
if not dollor_price:
dollor_object, _ = DollorModel.objects.get_or_create(unique_filed='unique')
dollor_price = dollor_object.price
dollar_to_dirham = 0.27
if dollor_price is None:
raise ValidationError({"dollor_price": "The 'dollor_price' must be provided in the context for dollar pricing."})
if self.currency == 'toman':
toman_price = self.price
elif self.currency == 'dollor':
toman_price = self.price * dollor_price
elif self.currency == 'derham':
toman_price = self.price * dollor_price * dollar_to_dirham
toman_price = toman_price if toman_price > self.min_price else self.min_price
return toman_price
def get_toman_price_after_discount(self):
return self.get_toman_price() * ((100 - self.discount) / 100)
+41 -11
View File
@@ -19,10 +19,38 @@ class ProductDetailSerializer(serializers.ModelSerializer):
exclude = ('product',)
class AttributeTypeSerialzier(serializers.ModelSerializer):
class Meta:
model = AttributeType
fields = "__all__"
class AttributeValueSerialzier(serializers.ModelSerializer):
attribute_type = AttributeTypeSerialzier()
class Meta:
model = AttributeValue
fields = "__all__"
class ProductVariantSerialzier(serializers.ModelSerializer):
attributes = AttributeValueSerialzier(many=True)
price = serializers.SerializerMethodField()
class Meta:
model = ProductVariant
exclude = ('min_price', 'sell', 'currency', 'product')
def get_price(self, obj):
dollor_price = self.context.get('dollor_price')
toman_price = obj.get_toman_price(dollor_price=dollor_price)
return "{:,.0f} تومان".format(toman_price)
class DynamicProductSerializer(serializers.ModelSerializer):
price = serializers.SerializerMethodField()
variants = ProductVariantSerialzier(many=True)
# variants_colors = serializers.SerializerMethodField()
is_new = serializers.SerializerMethodField()
related_products = serializers.SerializerMethodField()
details = ProductDetailSerializer(many=True, read_only=True)
@@ -42,15 +70,17 @@ class DynamicProductSerializer(serializers.ModelSerializer):
model = ProductModel
fields = "__all__"
view_type = {
'list': ['name', 'price', 'image1', 'video', 'rating', 'discount', 'slug', 'category', ],
'instance': ['name', 'description', 'price', 'image1', 'image2', 'image3', 'video', 'rating', 'discount', 'slug', 'meta_description', 'meta_keywords', 'meta_rating', 'category', 'related_products', 'details', 'in_pack_items'],
'chat': ['name', 'description', 'price', 'in_stock', 'discount', ]
'list': ['name', 'rating', 'slug', 'category', 'variants'],
'instance': ['name', 'description', 'rating', 'slug', 'meta_description', 'meta_keywords', 'meta_rating', 'category', 'related_products', 'details', 'in_pack_items', 'variants'],
'chat': ['name', 'description', 'variants']
}
def get_price(self, obj):
dollor_price = self.context.get('dollor_price')
toman_price = obj.get_toman_price(dollor_price=dollor_price)
return "{:,.0f} تومان".format(toman_price)
# def get_variants_colors(self, obj):
# varients = obj.variants.all()
# attributes = AttributeValue.objects.filter(variant__in=varients)
# return AttributeValueForProductListSerialzier(instance=attributes, many=True, context=self.context).data
def get_is_new(self, obj):
return timezone.now() < obj.created_at + timedelta(days=7)
@@ -74,8 +104,8 @@ class DynamicProductSerializer(serializers.ModelSerializer):
class CommentSerializer(serializers.ModelSerializer):
class Meta:
model = CommentModel
fields = "__all__"
read_only_fields = ('show', 'product', 'user')
exclude = ('review_status', )
read_only_fields = ('review_status', 'product', 'user')
class SubCategorySerializer(serializers.ModelSerializer):
product_count = serializers.SerializerMethodField()
+7 -7
View File
@@ -101,7 +101,7 @@ class AllProductsView(APIView):
name="sort",
description=(
"Sort results by one of the following fields:\n"
"`name`, `-name`, `price`, `-price`, `discount`, `-discount`, `created_at`, `-created_at`."
"`name`, `-name`, `price`, `-price`, `created_at`, `-created_at`."
"\nPrefix with `-` for descending order."
),
required=False,
@@ -158,12 +158,12 @@ class AllProductsView(APIView):
# Filter by stock status if `in_stock` is specified
in_stock = request.query_params.get('in_stock', "false") == 'true'
if in_stock:
products = products.filter(in_stock__gt=0)
products = products.filter(variants__in_stock__gt=0)
# Filter by discount if `has_discount` is specified
has_discount = request.query_params.get('has_discount', "false") == 'true'
if has_discount:
products = products.filter(discount__gt=0)
products = products.filter(variants__discount__gt=0)
# Search filter
search_query = request.query_params.get('search', None)
@@ -175,13 +175,13 @@ class AllProductsView(APIView):
price_lte = request.query_params.get('price_lte', None)
if price_gte:
products = products.filter(price__gte=price_gte)
products = products.filter(variants__min_price__gte=price_gte)
if price_lte:
products = products.filter(price__lte=price_lte)
products = products.filter(variants__min_price__lte=price_lte)
# Sorting
sort_by = request.query_params.get('sort', None)
if sort_by in ['name', '-name', 'price', '-price', 'discount', '-discount', 'created_at', '-created_at']:
if sort_by in ['name', '-name', 'price', '-price', 'created_at', '-created_at']:
products = products.order_by(sort_by)
else:
products = products.order_by('name')
@@ -224,7 +224,7 @@ class CommentView(APIView):
)
def get(self, request, pk):
product = get_object_or_404(ProductModel, id=pk)
comments = product.comments.filter(show=True)
comments = product.comments.filter(review_status__in=['not_reviwed', 'reviewed_and_confirmed'])
paginator = self.pagination_class()
paginated_comments = paginator.paginate_queryset(comments, request)
comments_ser = self.serializer_class(instance=paginated_comments, many=True)
+1 -1
View File
@@ -12,7 +12,7 @@ def dollor_price(request):
return str(dollor_object.price)[:2]
def comment_count(request):
return CommentModel.objects.all().count()
return CommentModel.objects.filter(review_status='not_reviwed').count()
def new_ticket_count(request):
return Ticket.objects.filter(status__in=['open', 'in_progress']).count()
+34 -10
View File
@@ -1,24 +1,23 @@
<script setup lang="ts">
// types
// imports
import { Swiper, SwiperSlide } from "swiper/vue";
import type { SwiperClass } from "swiper/react";
import useHomeData from "~/composables/api/home/useHomeData";
type Props = {}
// props
const props = defineProps<Props>();
const {} = toRefs(props);
// state
const { $gsap: gsap } = useNuxtApp();
const { data: homeData } = useHomeData();
const swiper_instance = ref<SwiperClass | null>(null);
const sectionTarget = ref(null);
const isSectionInsideViewport = useElementVisibility(sectionTarget, {
rootMargin: "0% 0px -100% 0px"
});
const swiper_instance = ref<SwiperClass | null>(null);
// methods
@@ -26,10 +25,35 @@ const onSwiper = (swiper: SwiperClass) => {
swiper_instance.value = swiper;
};
// watch
watch(() => isSectionInsideViewport.value, (newValue) => {
if (newValue) {
gsap.fromTo("#header-navbar", {
background: "white",
filter: "invert(0%)"
}, {
background: "transparent",
filter: "invert(100%)"
});
} else {
gsap.fromTo("#header-navbar", {
background: "transparent",
filter: "invert(100%)"
}, {
background: "white",
filter: "invert(0%)"
});
}
});
</script>
<template>
<section class="flex flex-col justify-center gap-4 bg-black h-[150svh] mt-40 relative overflow-hidden">
<section
ref="sectionTarget"
class="flex flex-col justify-center gap-4 bg-black h-[150svh] mt-40 relative overflow-hidden"
>
<div class="w-full flex justify-center items-center relative z-10">
<span class="text-white typo-h-4">