from .models import Notification

def global_context(request):
    if not request.user.is_authenticated:return {'samshaf_role':None,'new_notifications':0}
    if request.user.is_superuser:role='admin'
    else:
        try:role=request.user.samshaf_profile.role
        except Exception:role='none'
    # فقط یک count ساده در هر بار بارگذاری صفحه، بدون polling
    try:new_count=Notification.objects.filter(recipient=request.user,is_read=False).count()
    except Exception:new_count=0
    return {'samshaf_role':role,'new_notifications':new_count}
