Site/programmer/context_processors.py

32 lines
1.1 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.conf import settings
from .forms import CallbackForm
def contact_info(request):
return {
'CONTACT_EMAIL': getattr(settings, 'CONTACT_EMAIL', 'it@nserdyuk.ru'),
'CONTACT_PHONE': getattr(settings, 'CONTACT_PHONE', '+7 (960) 469-40-88'),
}
def callback_form(request):
initial = {}
if request.user.is_authenticated:
user = request.user
# Имя: полное имя или логин
initial['name'] = user.get_full_name() or user.username
# Email
initial['email'] = user.email
# Телефон из профиля (если есть)
if hasattr(user, 'profile') and user.profile.phone:
initial['phone'] = user.profile.phone
# Создаём экземпляр формы с initial
form = CallbackForm(initial=initial)
# Для авторизованных пользователей убираем captcha (как у вас в представлениях)
if request.user.is_authenticated and 'captcha' in form.fields:
del form.fields['captcha']
return {'callback_form': form}