2025-11-10 20:06:38 +03:00

92 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.http import HttpResponse, HttpResponseNotFound
from django.shortcuts import render
from .models import *
from django.shortcuts import render, redirect
from django.contrib import messages
from .models import CallbackRequest # Импортируем из models, а не forms
from .forms import CallbackForm
menu = [
{'title': "Главная", 'url_name': 'home'},
{'title': "Проекты", 'url_name': 'solution'},
{'title': "Компетенции", 'url_name': 'ability'},
{'title': "Отзывы", 'url_name': 'recall'},
{'title': "Обо мне", 'url_name': 'about'}
]
def index(request):
posts = Home.objects.filter(is_published=True)
context = {
'posts': posts,
'menu': menu,
'title': "Главная страница",
'form': CallbackForm()
}
return render(request, 'programmer/index.html', context=context)
def about(request):
context = {
'menu': menu,
'title': "Обо мне"
}
return render(request, 'programmer/about.html', context=context)
def solution(request):
posts = Solution.objects.filter(is_published=True)
context = {
'posts': posts,
'menu': menu,
'title': "Проекты"
}
return render(request, 'programmer/solution.html', context=context)
def ability(request):
posts = Competence.objects.filter(is_published=True)
context = {
'posts': posts,
'menu': menu,
'title': "Компетенции"
}
return render(request, 'programmer/competence.html', context=context)
def recall(request):
posts = Recall.objects.filter(is_published=True)
context = {
'posts': posts,
'menu': menu,
'title': "Отзывы"
}
return render(request, 'programmer/recall.html', context=context)
def show_post(request, post_id):
return HttpResponse(f"Отображение № {post_id}")
def pageNotFound(request, exception):
return HttpResponseNotFound('<h1>Страница не найдена</h1>')
def callback_request(request):
if request.method == 'POST':
form = CallbackForm(request.POST)
if form.is_valid():
# Сохраняем заявку через форму
form.save()
messages.success(request, '✅ Ваша заявка успешно отправлена! Я свяжусь с вами в ближайшее время.')
return redirect('home')
else:
# Если форма невалидна, показываем ошибки
for field, errors in form.errors.items():
for error in errors:
messages.error(request, f'❌ Ошибка в поле {form.fields[field].label}: {error}')
return redirect('home')
# Если GET запрос, просто показываем главную страницу
return redirect('home')