как создать страницу с отображением ошибки и что бы можно было бы вернуться назад
get_token:
def get_message_token(self) -> str:
""" Get message token from database """
_name = "get_message_token"
try:
company_object = userModels.Company.objects.get(
id=self.meeting["company"])
token = models.MessageToken.objects.get(
company=company_object).token
libenv._debug(
f"[*] {__name__}: {_name}: \
Company {company_object} assigned token: {token}")
return token
except models.MessageToken.DoesNotExist:
token = models.MessageToken.objects.get(is_default=True).token
libenv._debug(
f"[*] {__name__}: {_name}: \
Default token assigned for \
{self.meeting['company']}: {token.token}")
return token
except Exception as e:
raise e
views.py;
class GuestMeetingCreateView(LoginRequiredMixin, CreateView):
model = models.Meeting
form_class = forms.GuestMeetingForm
template_name = "meeting/_form_add_participant.html"
success_url = reverse_lazy("meeting:list")
permission_required = "meeting.add_meeting"
permission_denied_message = _("warning_message_no_add_permission")
permission_denied_page = "base.html"
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
if hasattr(self, 'request'):
kwargs.update({'user': self.request.user})
return kwargs
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.company = self.request.user.company_id
self.object.contact_person = self.request.user
return super().form_valid(form)
def get(self, request, *args, **kwargs):
if request.user.has_perm(self.permission_required):
return super().get(request, *args, **kwargs)
else:
return render(
request,
self.permission_denied_page,
messages.warning(
request,
self.permission_denied_message
)
)
def post(self, request, *args, **kwargs):
if request.user.has_perm(self.permission_required):
return super().post(request, *args, **kwargs)
else:
return render(
request,
self.permission_denied_page,
messages.warning(
request,
self.permission_denied_message
)
)
forms.py;
class GuestMeetingForm(forms.ModelForm):
"""
**Class representing web form
with information from Meeting for Guest model.**
"""
attendee = forms.ModelChoiceField(queryset=None, label=_("attendee"))
class Meta:
model = models.Meeting
def save(self, commit: bool = True) -> Any:
_name = 'save'
meeting_object = super().save(commit=False)
libenv._debug(f'[*] {__name__}: {_name}: {meeting_object}')
if commit:
numregGenerator = self.NumRegFactory(meeting_object)
meeting_object.registration_number = numregGenerator.generate_registration_number( # noqa: E501
meeting_type=f"G{meeting_object.meeting_type}")
meeting_object.save()
self.create_nda(self.populate_nda(meeting_object.get_guest()))
return meeting_object