diff --git a/taskapp/locale/ru/LC_MESSAGES/django.po b/taskapp/locale/ru/LC_MESSAGES/django.po index c7b213c..b0ce0b0 100644 --- a/taskapp/locale/ru/LC_MESSAGES/django.po +++ b/taskapp/locale/ru/LC_MESSAGES/django.po @@ -360,3 +360,6 @@ msgstr "Назначенные мной задачи" msgid "All my tasks" msgstr "Все мои задачи" + +msgid "User '%s' does not exist" +msgstr "Абонент с логином '%s' не найден" diff --git a/taskapp/views.py b/taskapp/views.py index 89316ba..5b5bcd7 100644 --- a/taskapp/views.py +++ b/taskapp/views.py @@ -101,7 +101,7 @@ def view(request, task_id): @only_admins def task_add_edit(request, task_id=0): task_id = safe_int(task_id) - uid = request.GET.get('uid') + uid = request.GET.get('uid', 0) selected_abon = None frm = TaskFrm() @@ -119,11 +119,8 @@ def task_add_edit(request, task_id=0): frm = TaskFrm(instance=tsk) selected_abon = tsk.abon - if uid: - selected_abon = get_object_or_404(Abon, username=str(uid)) - - if request.method == 'POST': - try: + try: + if request.method == 'POST': tsk.author = request.user frm = TaskFrm(request.POST, request.FILES, instance=tsk) @@ -150,8 +147,12 @@ def task_add_edit(request, task_id=0): messages.error(request, _('You must select the subscriber')) else: messages.error(request, _('Error in the form fields')) - except TelegramBot.DoesNotExist: - messages.error(request, _('Employee has not yet signed up for notifications')) + elif uid: + selected_abon = Abon.objects.get(username=str(uid)) + except TelegramBot.DoesNotExist: + messages.error(request, _('Employee has not yet signed up for notifications')) + except Abon.DoesNotExist: + messages.warning(request, _("User '%s' does not exist") % str(uid)) return render(request, 'taskapp/add_edit_task.html', { 'form': frm,