Spaces:
Paused
Paused
Download utils/views.py from MuhammadTechxone/heedxai: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/MuhammadTechxone/heedxai/resolve/main/utils/views.py
- Command line
-
hf download hf://spaces/MuhammadTechxone/heedxai/utils/views.py
-
curl -L -o views.py https://huggingface.co/spaces/MuhammadTechxone/heedxai/resolve/main/utils/views.py
1.62 kB
| from django.views.generic import FormView, DetailView, ListView | |
| from django.shortcuts import redirect | |
| from django.contrib.auth.mixins import LoginRequiredMixin | |
| from django.core.exceptions import PermissionDenied | |
| from .forms import CheckInForm | |
| from .models import CheckIn | |
| from .services import AnalysisService | |
| class CheckInCreateView(LoginRequiredMixin, FormView): | |
| template_name = 'backend/checkin_form.html' | |
| form_class = CheckInForm | |
| def form_valid(self, form): | |
| service = AnalysisService() | |
| # Match the dictionary structure the Analyzer expects | |
| responses_dict = {'narration': form.cleaned_data['narration']} | |
| checkin = service.perform_full_checkin( | |
| user=self.request.user, | |
| responses_dict=responses_dict | |
| ) | |
| return redirect('checkin-detail', pk=checkin.pk) | |
| class CheckInDetailView(LoginRequiredMixin, DetailView): | |
| model = CheckIn | |
| template_name = 'backend/checkin_detail.html' | |
| context_object_name = 'checkin' | |
| def get_object(self, queryset=None): | |
| """Ensure users can only access their own records.""" | |
| obj = super().get_object(queryset) | |
| if obj.user != self.request.user and not self.request.user.is_staff: | |
| raise PermissionDenied("You do not have permission to view this assessment.") | |
| return obj | |
| class HistoryListView(LoginRequiredMixin, ListView): | |
| model = CheckIn | |
| template_name = 'backend/history.html' | |
| def get_queryset(self): | |
| return CheckIn.objects.filter(user=self.request.user).order_by('-created_at') |