Enable simple search of tasks
This commit is contained in:
parent
bf7dc911b1
commit
6e032b22bb
4 changed files with 21 additions and 4 deletions
|
@ -76,7 +76,7 @@ class AddExternalItemForm(ModelForm):
|
||||||
exclude = ('list', 'created_date', 'due_date', 'created_by', 'assigned_to',)
|
exclude = ('list', 'created_date', 'due_date', 'created_by', 'assigned_to',)
|
||||||
|
|
||||||
|
|
||||||
class SearchForm(ModelForm):
|
class SearchForm(forms.Form):
|
||||||
"""Search."""
|
"""Search."""
|
||||||
|
|
||||||
q = forms.CharField(
|
q = forms.CharField(
|
||||||
|
|
|
@ -20,10 +20,11 @@
|
||||||
<p><strong><a href="{% url 'todo-task_detail' f.id %}">{{ f.title }}</a></strong><br />
|
<p><strong><a href="{% url 'todo-task_detail' f.id %}">{{ f.title }}</a></strong><br />
|
||||||
|
|
||||||
<span class="minor">
|
<span class="minor">
|
||||||
On list: <a href="{% url 'todo-incomplete_tasks' f.list.id f.list.slug %}">{{ f.list }}</a><br />
|
On list: <a href="{% url 'todo-incomplete_tasks' f.list.id f.list.slug %}">{{ f.list.name }}</a><br />
|
||||||
Assigned to: {{ f.assigned_to }} (created by: {{ f.created_by }})<br />
|
Assigned to: {{ f.assigned_to }} (created by: {{ f.created_by }})<br />
|
||||||
Complete: {{ f.completed|yesno:"Yes,No" }}
|
Complete: {{ f.completed|yesno:"Yes,No" }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -9,6 +9,7 @@ urlpatterns = patterns(
|
||||||
url(r'^(?P<list_id>\d{1,4})/(?P<list_slug>[\w-]+)/completed$', 'todo.views.view_list', {'view_completed': 1},
|
url(r'^(?P<list_id>\d{1,4})/(?P<list_slug>[\w-]+)/completed$', 'todo.views.view_list', {'view_completed': 1},
|
||||||
name='todo-completed_tasks'),
|
name='todo-completed_tasks'),
|
||||||
url(r'^add_list/$', 'todo.views.add_list', name="todo-add_list"),
|
url(r'^add_list/$', 'todo.views.add_list', name="todo-add_list"),
|
||||||
|
url(r'^search-post/$', 'todo.views.search_post', name="todo-search-post"),
|
||||||
url(r'^search/$', 'todo.views.search', name="todo-search"),
|
url(r'^search/$', 'todo.views.search', name="todo-search"),
|
||||||
url(r'^$', 'todo.views.list_lists', name="todo-lists"),
|
url(r'^$', 'todo.views.list_lists', name="todo-lists"),
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from todo.models import Item, List, Comment
|
from todo.models import Item, List, Comment
|
||||||
from todo.forms import AddListForm, AddItemForm, EditItemForm, AddExternalItemForm
|
from todo.forms import AddListForm, AddItemForm, EditItemForm, AddExternalItemForm, SearchForm
|
||||||
from todo import settings
|
from todo import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
@ -40,6 +40,7 @@ def list_lists(request):
|
||||||
Homepage view - list of lists a user can view, and ability to add a list.
|
Homepage view - list of lists a user can view, and ability to add a list.
|
||||||
"""
|
"""
|
||||||
thedate = datetime.datetime.now()
|
thedate = datetime.datetime.now()
|
||||||
|
searchform = SearchForm(auto_id=False)
|
||||||
|
|
||||||
# Make sure user belongs to at least one group.
|
# Make sure user belongs to at least one group.
|
||||||
group_count = request.user.groups.all().count()
|
group_count = request.user.groups.all().count()
|
||||||
|
@ -374,6 +375,20 @@ def add_list(request):
|
||||||
return render_to_response('todo/add_list.html', locals(), context_instance=RequestContext(request))
|
return render_to_response('todo/add_list.html', locals(), context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@user_passes_test(check_user_allowed)
|
||||||
|
def search_post(request):
|
||||||
|
"""
|
||||||
|
Redirect POST'd search param to query GET string
|
||||||
|
"""
|
||||||
|
if request.POST:
|
||||||
|
q = request.POST.get('q')
|
||||||
|
url = reverse('todo-search') + "?q=" + q
|
||||||
|
print(url)
|
||||||
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@user_passes_test(check_user_allowed)
|
@user_passes_test(check_user_allowed)
|
||||||
def search(request):
|
def search(request):
|
||||||
"""
|
"""
|
||||||
|
@ -396,7 +411,7 @@ def search(request):
|
||||||
# In that case we still need found_items in a queryset so it can be "excluded" below.
|
# In that case we still need found_items in a queryset so it can be "excluded" below.
|
||||||
found_items = Item.objects.all()
|
found_items = Item.objects.all()
|
||||||
|
|
||||||
if request.GET['inc_complete'] == "0":
|
if 'inc_complete' in request.GET:
|
||||||
found_items = found_items.exclude(completed=True)
|
found_items = found_items.exclude(completed=True)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue