Игорь Надеин 6fb2cdcea0 feat: enhance Employee model and integrate Telegram/WhatsApp bot
- Add birth_date, created_at/updated_at to Employee; remove username field
- Introduce EmployeeAction for tracking HR events and is_actually_active/status properties
- Create BotSubscriber model (OneToOne relation) for TG/WA binding
- Implement Aiogram-based Telegram bot:
  • request contact to bind by phone or @username
  • department selection keyboard from DEPARTMENTS dict
  • async ORM via sync_to_async, custom filters for bound & active employees
- Update profile view & template:
  • show “Bind Telegram/WhatsApp” button only when not already bound
  • preview avatar on upload
- Remove registration tokens in favor of contact-based auth
- Clean up templates, forms and add avatar validation mixin
2025-07-30 08:15:53 +03:00

40 lines
1.4 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.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Q
from django.views.generic import ListView
from .models import Document, DocumentAcknowledgement
class DocumentListView(LoginRequiredMixin, ListView):
model = Document
template_name = 'documents/document_list.html'
context_object_name = 'documents'
paginate_by = 20
def get_queryset(self):
user = self.request.user
return (
Document.objects
.filter(Q(sent_to_all=True) | Q(recipients=user))
.distinct()
.order_by('-uploaded_at')
)
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
user = self.request.user
# получаем id документов, с которыми пользователь уже ознакомился
acked = DocumentAcknowledgement.objects.filter(user=user) \
.values_list('document_id', flat=True)
ctx['acked_ids'] = set(acked)
return ctx
from django.shortcuts import get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
@login_required
def acknowledge_document(request, pk):
doc = get_object_or_404(Document, pk=pk)
DocumentAcknowledgement.objects.get_or_create(document=doc, user=request.user)
return redirect('documents:document_list')