Mercurial > public > sg101
comparison weblinks/views.py @ 1148:176d1550bf25
Convert weblinks to V3 design.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 01 Dec 2016 21:02:31 -0600 |
parents | e932f2ecd4a7 |
children |
comparison
equal
deleted
inserted
replaced
1147:4879df353104 | 1148:176d1550bf25 |
---|---|
35 categories = Category.objects.all() | 35 categories = Category.objects.all() |
36 total_links = Link.public_objects.all().count() | 36 total_links = Link.public_objects.all().count() |
37 return render(request, 'weblinks/index.html', { | 37 return render(request, 'weblinks/index.html', { |
38 'categories': categories, | 38 'categories': categories, |
39 'total_links': total_links, | 39 'total_links': total_links, |
40 'top_menu': 'categories', | |
41 'V3_DESIGN': True, | |
40 }) | 42 }) |
41 | 43 |
42 ####################################################################### | 44 ####################################################################### |
43 | 45 |
44 def new_links(request): | 46 def new_links(request): |
51 raise Http404 | 53 raise Http404 |
52 | 54 |
53 return render(request, 'weblinks/link_summary.html', { | 55 return render(request, 'weblinks/link_summary.html', { |
54 'page': the_page, | 56 'page': the_page, |
55 'title': 'Newest Links', | 57 'title': 'Newest Links', |
58 'top_menu': 'new', | |
59 'V3_DESIGN': True, | |
56 }) | 60 }) |
57 | 61 |
58 ####################################################################### | 62 ####################################################################### |
59 | 63 |
60 def popular_links(request): | 64 def popular_links(request): |
66 except InvalidPage: | 70 except InvalidPage: |
67 raise Http404 | 71 raise Http404 |
68 return render(request, 'weblinks/link_summary.html', { | 72 return render(request, 'weblinks/link_summary.html', { |
69 'page': the_page, | 73 'page': the_page, |
70 'title': 'Popular Links', | 74 'title': 'Popular Links', |
75 'top_menu': 'popular', | |
76 'V3_DESIGN': True, | |
71 }) | 77 }) |
72 | 78 |
73 ####################################################################### | 79 ####################################################################### |
74 | 80 |
75 @login_required | 81 @login_required |
88 else: | 94 else: |
89 add_form = AddLinkForm() | 95 add_form = AddLinkForm() |
90 | 96 |
91 return render(request, 'weblinks/add_link.html', { | 97 return render(request, 'weblinks/add_link.html', { |
92 'add_form': add_form, | 98 'add_form': add_form, |
99 'top_menu': 'add', | |
100 'V3_DESIGN': True, | |
93 }) | 101 }) |
94 | 102 |
95 ####################################################################### | 103 ####################################################################### |
96 | 104 |
97 @login_required | 105 @login_required |
98 def add_thanks(request): | 106 def add_thanks(request): |
99 return render(request, 'weblinks/add_link.html') | 107 return render(request, 'weblinks/add_link.html', { |
108 'V3_DESIGN': True, | |
109 'top_menu': 'add', | |
110 }) | |
100 | 111 |
101 ####################################################################### | 112 ####################################################################### |
102 | 113 |
103 # Maps URL component to database field name for the links table: | 114 # Maps URL component to database field name for the links table: |
104 | 115 |
130 | 141 |
131 return render(request, 'weblinks/view_links.html', { | 142 return render(request, 'weblinks/view_links.html', { |
132 's' : sort, | 143 's' : sort, |
133 'category' : cat, | 144 'category' : cat, |
134 'page' : the_page, | 145 'page' : the_page, |
146 'V3_DESIGN': True, | |
135 }) | 147 }) |
136 | 148 |
137 ####################################################################### | 149 ####################################################################### |
138 | 150 |
139 def _visit_link(request, link): | 151 def _visit_link(request, link): |
148 link = get_object_or_404(Link, pk = link_id) | 160 link = get_object_or_404(Link, pk = link_id) |
149 return _visit_link(request, link) | 161 return _visit_link(request, link) |
150 | 162 |
151 ####################################################################### | 163 ####################################################################### |
152 | 164 |
153 @require_POST | |
154 def random_link(request): | 165 def random_link(request): |
155 ids = Link.public_objects.values_list('id', flat=True) | 166 if request.method == 'POST': |
156 if not ids: | 167 ids = Link.public_objects.values_list('id', flat=True) |
157 raise Http404 | 168 if not ids: |
158 id = random.choice(ids) | 169 raise Http404 |
159 random_link = Link.public_objects.get(pk=id) | 170 the_id = random.choice(ids) |
160 return _visit_link(request, random_link) | 171 random_link = Link.public_objects.get(pk=the_id) |
172 return _visit_link(request, random_link) | |
173 | |
174 return render(request, 'weblinks/random_link.html', { | |
175 'top_menu': 'random', | |
176 'V3_DESIGN': True, | |
177 }) | |
161 | 178 |
162 ####################################################################### | 179 ####################################################################### |
163 | 180 |
164 @require_POST | 181 @require_POST |
165 def report_link(request, link_id): | 182 def report_link(request, link_id): |
185 link = get_object_or_404(Link, pk=id) | 202 link = get_object_or_404(Link, pk=id) |
186 if not link.is_public: | 203 if not link.is_public: |
187 raise Http404 | 204 raise Http404 |
188 return render(request, 'weblinks/link_detail.html', { | 205 return render(request, 'weblinks/link_detail.html', { |
189 'link': link, | 206 'link': link, |
207 'V3_DESIGN': True, | |
190 }) | 208 }) |