Source code for superdjango.contrib.errors.views

# Imports

from django.conf import settings
from django.http import Http404
import os
from superdjango.patterns import PATTERN_UUID
from superdjango.views import DetailView, ListView, LoginRequiredMixin, ModelViewSet, TemplateView, ViewSet
from superdjango.shortcuts import get_model
from .utils import CSVDatabase, CSVError

# Exports

__all__ = (
    "CSVErrorDetail",
    "CSVErrorList",
    "CSVErrorViewSet",
    "ModelErrorDetail",
    "ModelErrorList",
    "ModelErrorViewSet",
)

# Views


[docs]class CSVErrorDetail(LoginRequiredMixin, TemplateView): """Load detail from an error collected by the CSV backend.""" pattern_name = "captured_error_detail" pattern_value = "detail/%s/" % PATTERN_UUID template_name = "errors/captured_error_detail.html"
[docs] def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) file_path = os.path.join(settings.SUPERDJANGO_ERROR_CAPTURE_OUTPUT_PATH, "current.csv") db = CSVDatabase(file_path) db.load() error = db.fetch(str(self.kwargs['uuid'])) if error is None: raise Http404() context['error'] = error return context
[docs]class CSVErrorList(LoginRequiredMixin, TemplateView): """Load errors collected by the CSV backend.""" pattern_name = "captured_error_list" pattern_value = "" template_name = "errors/captured_error_list.html"
[docs] def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) file_path = os.path.join(settings.SUPERDJANGO_ERROR_CAPTURE_OUTPUT_PATH, "current.csv") db = CSVDatabase(file_path) db.load() context['errors'] = db return context
[docs]class ModelErrorDetail(LoginRequiredMixin, DetailView): """Load detail from an error collected by the Model backend.""" context_object_name = "error" pattern_name = "captured_error_detail" pattern_value = "detail/%s/" % PATTERN_UUID template_name = "errors/captured_error_detail.html"
[docs] @classmethod def get_model(cls): """Override to provide developer-defined model.""" return get_model(settings.SUPERDJANGO_ERROR_CAPTURE_MODEL_NAME, raise_exception=False)
[docs]class ModelErrorList(LoginRequiredMixin, ListView): """Load errors collected by the Model backend.""" context_object_name = "errors" pattern_name = "captured_error_list" pattern_value = "" template_name = "errors/captured_error_list.html"
[docs] @classmethod def get_model(cls): """Override to provide developer-defined model.""" return get_model(settings.SUPERDJANGO_ERROR_CAPTURE_MODEL_NAME, raise_exception=False)
# View Sets
[docs]class CSVErrorViewSet(ViewSet): """Collects views for displaying errors logged to CSV.""" views = [ CSVErrorDetail, CSVErrorList, ]
[docs]class ModelErrorViewSet(ModelViewSet): """Collects views for displaying errors logged to the database.""" views = [ ModelErrorDetail, ModelErrorList, ]