feat: redirect to passed-in url when submit todo

This commit is contained in:
raiots 2023-01-05 22:57:42 +08:00
parent 97a5e22795
commit b0433783c8
2 changed files with 12 additions and 5 deletions

View File

@ -11,6 +11,7 @@ from django.http import HttpResponse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
import django.utils.timezone as timezone import django.utils.timezone as timezone
from django.utils.http import url_has_allowed_host_and_scheme
from django.views import View from django.views import View
from django.db import connection from django.db import connection
# Create your views here. # Create your views here.
@ -365,7 +366,8 @@ class TodoListView(View):
my_todo = Todo.objects.filter(main_executor=request.user, deadline__year=year, deadline__month=month) my_todo = Todo.objects.filter(main_executor=request.user, deadline__year=year, deadline__month=month)
my_sub_todo = Todo.objects.filter(sub_executor=request.user, deadline__year=year, deadline__month=month) my_sub_todo = Todo.objects.filter(sub_executor=request.user, deadline__year=year, deadline__month=month)
date = str(year) + '' + str(month) + '' date = str(year) + '' + str(month) + ''
context = {'my_todo': my_todo, 'my_sub_todo': my_sub_todo, 'date': date} current_path = request.get_full_path()
context = {'my_todo': my_todo, 'my_sub_todo': my_sub_todo, 'date': date, 'current_path': current_path}
return render(request, 'tasks/todolist.html', context) return render(request, 'tasks/todolist.html', context)
@ -375,7 +377,8 @@ class GroupTodoList(View):
group_todo = Todo.objects.filter(main_executor__department=request.user.department, deadline__year=year, group_todo = Todo.objects.filter(main_executor__department=request.user.department, deadline__year=year,
deadline__month=month).order_by('related_task_id', 'deadline') deadline__month=month).order_by('related_task_id', 'deadline')
date = str(year) + '' + str(month) + '' date = str(year) + '' + str(month) + ''
context = {'group_todo': group_todo, 'date': date} current_path = request.get_full_path()
context = {'group_todo': group_todo, 'date': date, 'current_path': current_path}
return render(request, 'tasks/group_todolist.html', context) return render(request, 'tasks/group_todolist.html', context)
@ -425,9 +428,13 @@ class TodoEntryView(View):
def post(self, request, pk): def post(self, request, pk):
todo_detail = Todo.objects.get(id=pk) todo_detail = Todo.objects.get(id=pk)
form = TodoForm(instance=todo_detail, data=request.POST) form = TodoForm(instance=todo_detail, data=request.POST)
redirect_to = request.GET.get('next')
if form.is_valid(): if form.is_valid():
form.save() form.save()
return redirect('tasks:todolist') if url_has_allowed_host_and_scheme(redirect_to, None):
return redirect(redirect_to)
else:
return redirect('tasks:todolist')
# return redirect('tasks:todo_detail', pk=pk) # return redirect('tasks:todo_detail', pk=pk)

View File

@ -97,7 +97,7 @@
</td> </td>
<td style="text-align: center"><textarea style="overflow:hidden; width: 100%" readonly="readonly">{{ todo.complete_note }}</textarea></td> <td style="text-align: center"><textarea style="overflow:hidden; width: 100%" readonly="readonly">{{ todo.complete_note }}</textarea></td>
<td style="text-align: center">{{ todo.quality_mark|default:'' }}</td> <td style="text-align: center">{{ todo.quality_mark|default:'' }}</td>
<td><a href="{% url 'tasks:todo_detail' pk=todo.id %}">填报</a> </td> <td><a href="{% url 'tasks:todo_detail' pk=todo.id %}?next={{ current_path }}">填报</a> </td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -150,7 +150,7 @@
</td> </td>
<td style="text-align: center"><textarea style="overflow:hidden; width:100%" readonly="readonly">{{ todo.complete_note }}</textarea></td> <td style="text-align: center"><textarea style="overflow:hidden; width:100%" readonly="readonly">{{ todo.complete_note }}</textarea></td>
<td style="text-align: center">{{ todo.quality_mark|default:'' }}</td> <td style="text-align: center">{{ todo.quality_mark|default:'' }}</td>
<td><a href="{% url 'tasks:todo_detail' pk=todo.id %}">填报</a> </td> <td><a href="{% url 'tasks:todo_detail' pk=todo.id %}?next={{ current_path }}">填报</a> </td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>