This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathviews.py
104 lines (96 loc) · 3.49 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.views.generic import date_based, list_detail, create_update
from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.conf import settings
from chiplog.models import Entry
from chiplog.forms import EntryForm
@login_required
def entry_list(request, page=0):
"""
Dual-purpose view: add new Entries / view paginated list of Entires.
"""
if request.POST:
form = EntryForm(data=request.POST)
if form.is_valid():
form.save()
# request.user.message_set.create(message="Entry created.")
return HttpResponseRedirect(reverse('chiplog_index'))
else:
return render_to_response('chiplog/entry_form.html', {'form': form})
else:
return list_detail.object_list(
request,
queryset = Entry.objects.all(),
template_object_name = 'entry',
paginate_by = 10,
page = page,
extra_context = { 'form': EntryForm }
)
@login_required
def tagged_list(request, tag):
"""
All entries for a particular tag.
"""
return list_detail.object_list(
request,
queryset = Entry.objects.filter(tags__icontains=tag),
template_name = 'chiplog/entry_tagged.html',
template_object_name = 'entry',
extra_context = { 'tag': tag }
)
@login_required
def entry_detail(request, object_id):
return list_detail.object_detail(
request,
object_id = object_id,
queryset = Entry.objects.all(),
template_object_name = 'entry'
)
@login_required
def entry_delete(request, object_id):
return create_update.delete_object(
request,
object_id = object_id,
model = Entry,
post_delete_redirect = reverse('chiplog_index'),
template_object_name = 'entry',
)
@login_required
def entry_create(request):
return create_update.create_object(
request,
model = Entry,
post_save_redirect = reverse('chiplog_index'),
)
@login_required
def entry_update(request, object_id):
return create_update.update_object(
request,
object_id = object_id,
model = Entry,
# post_save_redirect = request.POST['referrer'],
template_object_name = 'entry',
)
@login_required
def search(request):
if request.GET:
try:
query = request.GET['q']
except KeyError:
# If they use the wrong query string (?s instead of ?q).
message = 'Something has gone wrong, champ. Try again.'
context = { 'message':message }
return render_to_response('chiplog/entry_search.html', context, context_instance=RequestContext(request))
if len(query) != 0:
entry_list = Entry.objects.filter(body__icontains=query)
context = { 'entry_list': entry_list, 'query':query }
return render_to_response('chiplog/entry_search.html', context, context_instance=RequestContext(request))
else:
message = 'Search term was too vague. Please try again.'
context = { 'message':message }
return render_to_response('chiplog/entry_search.html', context, context_instance=RequestContext(request))
else:
return render_to_response('chiplog/entry_search.html', {}, context_instance=RequestContext(request))