def external_add(request) -> HttpResponse: """Allow authenticated users who don't have access to the rest of the ticket system to file a ticket in the list specified in settings (e.g. django-todo can be used a ticket filing system for a school, where students can file tickets without access to the rest of the todo system). Publicly filed tickets are unassigned unless settings.DEFAULT_ASSIGNEE exists. Разрешить аутентифицированным пользователям, у которых нет доступа к остальной части системы регистрации, подавать заявки в список, указанный в настройках (например, django-todo может использоваться в системе регистрации заявок для школы, где учащиеся могут подавать заявки без доступа к остальной части системы регистрации заявок). Общедоступные заявки не назначаются, если только не прописана settings.DEFAULT_ASSIGNEE. """ if not settings.TODO_DEFAULT_LIST_SLUG: # We do NOT provide a default in defaults # Мы не предоставляем дефолт по умолчанию raise RuntimeError( "This feature requires TODO_DEFAULT_LIST_SLUG: in settings. See documentation." ) if not TaskList.objects.filter(slug=settings.TODO_DEFAULT_LIST_SLUG).exists(): raise RuntimeError( "There is no TaskList with slug specified for TODO_DEFAULT_LIST_SLUG in settings." ) if request.POST: form = AddExternalTaskForm(request.POST) if form.is_valid(): current_site = Site.objects.get_current() task = form.save(commit=False) task.task_list = TaskList.objects.get(slug=settings.TODO_DEFAULT_LIST_SLUG) task.created_by = request.user if defaults("TODO_DEFAULT_ASSIGNEE"): task.assigned_to = get_user_model().objects.get(username=settings.TODO_DEFAULT_ASSIGNEE) task.save() # Send email to assignee if we have one # Отправьте электронное письмо правопреемнику, если он у нас есть if task.assigned_to: email_subject = render_to_string( "todo/email/assigned_subject.txt", {"task": task.title} ) email_body = render_to_string( "todo/email/assigned_body.txt", {"task": task, "site": current_site} ) try: send_mail( email_subject, email_body, task.created_by.email, [task.assigned_to.email], fail_silently=False, ) except ConnectionRefusedError: messages.warning( request, "Task saved but mail not sent. Contact your administrator." ) messages.success( request, "Your trouble ticket has been submitted. We'll get back to you soon." ) return redirect(defaults("TODO_PUBLIC_SUBMIT_REDIRECT")) else: form = AddExternalTaskForm(initial={"priority": 999}) context = {"form": form} return render(request, "todo/add_task_external.html", context)
def external_add(request) -> HttpResponse: """Allow authenticated users who don't have access to the rest of the ticket system to file a ticket in the list specified in settings (e.g. django-todo can be used a ticket filing system for a school, where students can file tickets without access to the rest of the todo system). Publicly filed tickets are unassigned unless settings.DEFAULT_ASSIGNEE exists. """ if not settings.TODO_DEFAULT_LIST_SLUG: # We do NOT provide a default in defaults raise RuntimeError( "This feature requires TODO_DEFAULT_LIST_SLUG: in settings. See documentation." ) if not TaskList.objects.filter( slug=settings.TODO_DEFAULT_LIST_SLUG).exists(): raise RuntimeError( "There is no TaskList with slug specified for TODO_DEFAULT_LIST_SLUG in settings." ) if request.POST: form = AddExternalTaskForm(request.POST) if form.is_valid(): current_site = Site.objects.get_current() task = form.save(commit=False) task.task_list = TaskList.objects.get( slug=settings.TODO_DEFAULT_LIST_SLUG) task.created_by = request.user if defaults("TODO_DEFAULT_ASSIGNEE"): task.assigned_to = get_user_model().objects.get( username=settings.TODO_DEFAULT_ASSIGNEE) task.save() # Send email to assignee if we have one if task.assigned_to: email_subject = render_to_string( "todo/email/assigned_subject.txt", {"task": task.title}) email_body = render_to_string("todo/email/assigned_body.txt", { "task": task, "site": current_site }) try: send_mail( email_subject, email_body, task.created_by.email, [task.assigned_to.email], fail_silently=False, ) except ConnectionRefusedError: messages.warning( request, _("Task saved but mail not sent. Contact your administrator." )) messages.success( request, _("Your trouble ticket has been submitted. We'll get back to you soon." )) return redirect(defaults("TODO_PUBLIC_SUBMIT_REDIRECT")) else: form = AddExternalTaskForm(initial={"priority": 999}) context = {"form": form} return render(request, "todo/add_task_external.html", context)
def external_add(request) -> HttpResponse: """Allow authenticated users who don't have access to the rest of the ticket system to file a ticket in the list specified in settings (e.g. django-todo can be used a ticket filing system for a school, where students can file tickets without access to the rest of the todo system). Publicly filed tickets are unassigned unless settings.DEFAULT_ASSIGNEE exists. """ if not settings.TODO_DEFAULT_LIST_SLUG: # We do NOT provide a default in defaults raise RuntimeError( "This feature requires TODO_DEFAULT_LIST_SLUG: in settings. See documentation." ) if not TaskList.objects.filter(slug=settings.TODO_DEFAULT_LIST_SLUG).exists(): raise RuntimeError( "There is no TaskList with slug specified for TODO_DEFAULT_LIST_SLUG in settings." ) if request.POST: form = AddExternalTaskForm(request.POST) if form.is_valid(): current_site = Site.objects.get_current() task = form.save(commit=False) task.task_list = TaskList.objects.get(slug=settings.TODO_DEFAULT_LIST_SLUG) task.created_by = request.user if defaults("TODO_DEFAULT_ASSIGNEE"): task.assigned_to = get_user_model().objects.get(username=settings.TODO_DEFAULT_ASSIGNEE) task.save() # Send email to assignee if we have one if task.assigned_to: email_subject = render_to_string( "todo/email/assigned_subject.txt", {"task": task.title} ) email_body = render_to_string( "todo/email/assigned_body.txt", {"task": task, "site": current_site} ) try: send_mail( email_subject, email_body, task.created_by.email, [task.assigned_to.email], fail_silently=False, ) except ConnectionRefusedError: messages.warning( request, "Task saved but mail not sent. Contact your administrator." ) messages.success( request, "Your trouble ticket has been submitted. We'll get back to you soon." ) return redirect(defaults("TODO_PUBLIC_SUBMIT_REDIRECT")) else: form = AddExternalTaskForm(initial={"priority": 999}) context = {"form": form} return render(request, "todo/add_task_external.html", context)