Skip to content
Open

Dist #18

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
67ce2af
Added media file settings
Dina-Tolkina Feb 21, 2024
e2f4eac
Added the models and set up the admin.
Dina-Tolkina Feb 26, 2024
b02a0ce
I connected a DB to the catalog, user registration
Dina-Tolkina Feb 28, 2024
e15b16a
Delete catalog.html
Dina-Tolkina Mar 1, 2024
bdf2403
Delete reg.html
Dina-Tolkina Mar 1, 2024
fff7592
Delete auth.html
Dina-Tolkina Mar 1, 2024
5e68f54
Delete settings.py
Dina-Tolkina Mar 3, 2024
6ccf5a9
Delete admin.py
Dina-Tolkina Mar 3, 2024
bbfee97
Delete forms.py
Dina-Tolkina Mar 3, 2024
029bc0b
Delete models.py
Dina-Tolkina Mar 3, 2024
b19d8cb
Delete urls.py
Dina-Tolkina Mar 3, 2024
caf7e32
Delete views.py
Dina-Tolkina Mar 3, 2024
22baf29
Update settings.py
Dina-Tolkina Mar 3, 2024
be4e7ad
Update urls.py
Dina-Tolkina Mar 3, 2024
71b6a7b
Update models.py
Dina-Tolkina Mar 3, 2024
a51026a
Update views.py
Dina-Tolkina Mar 3, 2024
75ffd40
add
Dina-Tolkina Mar 3, 2024
17d21ac
add
Dina-Tolkina Mar 3, 2024
1aa3042
Update views.py
Dina-Tolkina Mar 4, 2024
7a7e9b8
Update user_edit.html
Dina-Tolkina Mar 4, 2024
4a784e5
Update views.py
Dina-Tolkina Mar 5, 2024
f230829
Update views.py
Dina-Tolkina Mar 7, 2024
ecda3b9
Update main.html
Dina-Tolkina Mar 7, 2024
9d85ed1
fasdf
Mar 27, 2024
24daca7
fasdfasdf
Mar 27, 2024
4ba7320
Update user.html
Dina-Tolkina Apr 1, 2024
ac9f3ba
Update basket.html
Dina-Tolkina Apr 1, 2024
03ad560
Update forms.py
Dina-Tolkina Apr 1, 2024
1aa0d43
Update views.py
Dina-Tolkina Apr 1, 2024
caaa338
Update catalog.html
Dina-Tolkina Apr 1, 2024
da2c06b
fdasfaf
josiren Apr 16, 2024
2380cd2
fixed at all pages
Apr 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified config/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified config/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified config/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified config/__pycache__/settings.cpython-312.pyc
Binary file not shown.
Binary file modified config/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified config/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified config/__pycache__/wsgi.cpython-311.pyc
Binary file not shown.
Binary file modified config/__pycache__/wsgi.cpython-312.pyc
Binary file not shown.
34 changes: 30 additions & 4 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'phonenumber_field',
'petapp',
]

Expand Down Expand Up @@ -77,8 +78,12 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'Pet_store',
'USER': 'postgres',
'PASSWORD': '111',
'HOST': '192.168.27.4',
'PORT': 5432,
}
}

Expand All @@ -105,7 +110,7 @@
# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'ru-RU'

TIME_ZONE = 'UTC'

Expand All @@ -119,9 +124,30 @@

STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILELS_DIRS = []
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
STATICFILES_DIRS = []

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'
LOGIN_URL = '/auth/'


AUTHENTICATION_BACKENDS = [
'petapp.authentication.EmailAuthBackend',
# 'django.contrib.auth.backends.ModelBackend',
]

# PASSWORD_HASHERS = [
# "django.contrib.auth.hashers.PBKDF2PasswordHasher",
# "django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher",
# "django.contrib.auth.hashers.Argon2PasswordHasher",
# "django.contrib.auth.hashers.BCryptSHA256PasswordHasher",
# "django.contrib.auth.hashers.ScryptPasswordHasher",
# ]

10 changes: 8 additions & 2 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
from django.urls import path
from petapp import views

Expand All @@ -24,9 +26,13 @@
path('catalog/', views.catalog, name='catalog'),
path('contact/', views.contact, name='contact'),
path('about/', views.about, name='about'),
path('auth/', views.auth, name='auth'),
path('auth/', views.email_login, name='auth'),
path('logout/', views.logout_view, name='logout'),
path('reg/', views.reg, name='reg'),
path('basket/', views.basket, name='basket'),
path('user/', views.user, name='user'),
path('user/edit/', views.user_edit, name='user_edit'),
]
path('add_basket/<int:pk>/', views.add_basket, name='add_basket'),
path('basket/addition/<int:product>/<int:basket>/', views.addition_basket, name='addition_basket'),
path('basket/subtraction/<int:product>/<int:basket>/', views.subtraction_basket, name='subtraction_basket'),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Binary file added media/customer/1196210_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/1611870_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/1909392_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/2142738_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/2354864_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/2364084_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/2673344_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/3055444_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/3285991_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/3343295_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/3761615_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/450861_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/6651825_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/6852386_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/7265800_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/862833_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/customer/8671706_avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/products/dOnBAHTBsMc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/products/image_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/products/jN5lfuNTsYs_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified petapp/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified petapp/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified petapp/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file modified petapp/__pycache__/admin.cpython-312.pyc
Binary file not shown.
Binary file modified petapp/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file modified petapp/__pycache__/apps.cpython-312.pyc
Binary file not shown.
Binary file added petapp/__pycache__/authentication.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file added petapp/__pycache__/forms.cpython-311.pyc
Binary file not shown.
Binary file added petapp/__pycache__/forms.cpython-312.pyc
Binary file not shown.
Binary file modified petapp/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified petapp/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file modified petapp/__pycache__/views.cpython-311.pyc
Binary file not shown.
Binary file modified petapp/__pycache__/views.cpython-312.pyc
Binary file not shown.
54 changes: 53 additions & 1 deletion petapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
from django.contrib import admin
from .models import Basket, Customer, Product, Animal_type, Category, Order, OrderDetail, PurchaseHistory, Rating, BasketProduct
from django.utils.safestring import mark_safe

# Register your models here.

admin.site.site_header = "Страница администратора"
admin.site.site_title = "Зоомагазин puffball"
admin.site.index_title = "Администрирование сайта"


class CustomerAdmin(admin.ModelAdmin):
list_display = ('get_last_name', 'get_first_name', 'phone', 'get_email', 'avatar_show')

def get_last_name(self, obj):
return obj.user.last_name
get_last_name.short_description = 'Фамилия'

def get_first_name(self, obj):
return obj.user.first_name
get_first_name.short_description = 'Имя'

def get_email(self, obj):
return obj.user.email
get_first_name.short_description = 'Электронная почта'

def avatar_show(self, obj):
if obj.photo_avatar:
return mark_safe("<img src='{}' width='60' />".format(obj.photo_avatar.url))
return "None"

avatar_show.__name__ = "Картинка"


class ProductAdmin(admin.ModelAdmin):
list_display = ("product_name", "price", "availability", "stock", "image_show")
readonly_fields = ['availability']

def image_show(self, obj):
if obj.photo_product:
return mark_safe("<img src='{}' width='60' />".format(obj.photo_product.url))
return "None"

image_show.__name__ = "Картинка"


admin.site.register(Customer, CustomerAdmin)
admin.site.register(Product, ProductAdmin)
admin.site.register(Animal_type)
admin.site.register(Category)
admin.site.register(Basket)
admin.site.register(BasketProduct)
admin.site.register(Order)
admin.site.register(OrderDetail)
admin.site.register(PurchaseHistory)
admin.site.register(Rating)
15 changes: 15 additions & 0 deletions petapp/authentication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model


User = get_user_model()

class EmailAuthBackend(ModelBackend):
def authenticate(self, request, email=None, password=None, **kwargs):
try:
user = User.objects.get(email=email) # Используйте email вместо username
if user.check_password(password):
return user
except User.DoesNotExist:
return None
106 changes: 106 additions & 0 deletions petapp/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import get_user_model
from django.contrib.auth import authenticate
from petapp.authentication import EmailAuthBackend
from petapp.models import *


class createUserForm(forms.ModelForm):
last_name = forms.CharField(label='Фамилия', widget=forms.TextInput(attrs={'class': 'form-input'}))
first_name = forms.CharField(label='Имя', widget=forms.TextInput(attrs={'class': 'form-input'}))
email = forms.EmailField(label='Электронная почта', widget=forms.EmailInput(attrs={'class': 'form-input'}))
password = forms.CharField(label='Пароль', widget=forms.PasswordInput(attrs={'class': 'form-input'}))

class Meta:
model = User
fields = ('last_name', 'first_name', 'email', 'password')


class RegForm(forms.ModelForm):
patronymic = forms.CharField(label='Отчество', widget=forms.TextInput(attrs={'class': 'form-input'}))
phone = forms.CharField(label='Номер телефона', widget=forms.TextInput(attrs={'class': 'form-input', 'pattern': r'(?:\+?[\d]{1,3}[-\.\s]?)?(?:(?:[\(\[])?[\d]{3}(?:[\)\]]|[\.-])[\d]{3})(?:[\.-][\d]{4}|[\.\s]?$)', 'data-mask': "'+7 (ddd) ddd-dd-dd'"}))

class Meta:
model = Customer
fields = ('patronymic', 'phone')



class CombinedRegForm(forms.Form):
def __init__(self, *args, **kwargs):
super(CombinedRegForm, self).__init__(*args, **kwargs)
self.fields['last_name'] = createUserForm().fields['last_name']
self.fields['first_name'] = createUserForm().fields['first_name']
self.fields['patronymic'] = RegForm().fields['patronymic']
self.fields['phone'] = RegForm().fields['phone']
self.fields['email'] = createUserForm().fields['email']
self.fields['password'] = createUserForm().fields['password']

def clean_last_name(self):
last_name = self.cleaned_data.get('last_name')
if len(last_name) < 2:
raise forms.ValidationError('Фамилия должна содержать не менее 2 символов.')
return last_name

def clean_first_name(self):
first_name = self.cleaned_data.get('first_name')
if len(first_name) < 2:
raise forms.ValidationError('Имя должно содержать не менее 2 символов.')
return first_name

def clean_patronymic(self):
patronymic = self.cleaned_data.get('patronymic')
if len(patronymic) < 2:
raise forms.ValidationError('Отчество должно содержать не менее 2 символов.')
return patronymic

def clean(self):
cleaned_data = super().clean()
email = cleaned_data.get('email')
phone = cleaned_data.get('phone')

if Customer.objects.filter(phone=phone).exists():
self.add_error('phone', 'Пользователь с таким номером телефона уже существует.')

if User.objects.filter(email=email).exists():
self.add_error('email', 'Пользователь с такой электронной почтой уже существует.')


def clean_password(self):
password = self.cleaned_data.get('password')
if len(password) < 8:
raise forms.ValidationError('Пароль должен состоять не менее чем из 8 символов.')
if not any(char.isupper() for char in password):
raise forms.ValidationError('Пароль должен содержать хотя бы одну заглавную букву.')
if not any(char.isdigit() for char in password):
raise forms.ValidationError('Пароль должен содержать не менее одной цифры.')
return password


User = get_user_model()

class EmailLoginForm(forms.Form):
email = forms.EmailField(label='Электронная почта', widget=forms.EmailInput(attrs={'class': 'form-input'}))
password = forms.CharField(label='Пароль', widget=forms.PasswordInput(attrs={'class': 'form-input'}))


class PaymentForm(forms.Form):
amount = forms.FloatField(label='Amount to pay', min_value=0)
order_number = forms.CharField(label='Order number', max_length=20)















Loading