Merge lp:~cjohnston/summit/add-summit-index-redirect into lp:summit

Proposed by Chris Johnston
Status: Merged
Approved by: Chris Johnston
Approved revision: 544
Merged at revision: 544
Proposed branch: lp:~cjohnston/summit/add-summit-index-redirect
Merge into: lp:summit
Diff against target: 212 lines (+109/-47)
4 files modified
summit/common/templates/common/index.html (+0/-35)
summit/common/templates/common/no_summit.html (+30/-0)
summit/common/tests.py (+61/-2)
summit/common/views.py (+18/-10)
To merge this branch: bzr merge lp:~cjohnston/summit/add-summit-index-redirect
Reviewer Review Type Date Requested Status
Joe Talbott Approve
Review via email: mp+163250@code.launchpad.net

Commit message

Removes the landing page and does an automatic redirect to the next summit

Description of the change

This creates a redirect so that when hitting / you are redirected to the next summit event.

Also provides an error page if there is no summit.

To post a comment you must log in.
544. By Chris Johnston <email address hidden>

Add no_summit.html

Revision history for this message
Joe Talbott (joetalbott) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'summit/common/templates/common/index.html'
2--- summit/common/templates/common/index.html 2012-04-23 14:07:02 +0000
3+++ summit/common/templates/common/index.html 1970-01-01 00:00:00 +0000
4@@ -1,35 +0,0 @@
5-{% extends "base.html" %}
6-{% load datetime %}
7-
8-{% block page_name %}Home{%endblock %}
9-{% block extrahead %}
10-{{ block.super }}
11-{% endblock %}
12-
13-{% block sub_nav %}{% endblock %}
14-
15-{% block content %}
16-<div class="row">
17-<article class="span-12">
18- {% if summit %}
19- <h1><a href="/{{ summit.name }}">{{ summit.title }} &rsaquo;</a></h1>
20- {% include "schedule/summit_info.html" %}
21- {% else %}
22- <p>No summits registered.</p>
23- {% endif %}
24-</article>
25-</div>
26-{% endblock %}
27-{% block closure %}
28-<style>
29-/* Mobile-friendly styles */
30-@media screen and (max-width: 960px) {
31- .span-4, footer, #main-nav, footer .logo-ubuntu, .nav-secondary { display: none; }
32- #page-header { text-align: center; }
33- #page-header a { height: 24px; line-height: 1; float: none; display: inline; }
34- .span-8, .span-9, .span-3, .span-12 { width: 100%; }
35- #fb-root * { width: auto; }
36-}
37-</style>
38-{% endblock %}
39-
40
41=== added file 'summit/common/templates/common/no_summit.html'
42--- summit/common/templates/common/no_summit.html 1970-01-01 00:00:00 +0000
43+++ summit/common/templates/common/no_summit.html 2013-05-10 13:47:31 +0000
44@@ -0,0 +1,30 @@
45+{% extends "base.html" %}
46+
47+{% block page_name %}Home{%endblock %}
48+{% block extrahead %}
49+{{ block.super }}
50+{% endblock %}
51+
52+{% block sub_nav %}{% endblock %}
53+
54+{% block content %}
55+<div class="row">
56+<article class="span-12">
57+ <h1>No summit found!</h1>
58+ <p>If you believe you have found this page in error, please <a href="https://bugs.launchpad.net/summit/+filebug">File a bug</a>.</p>
59+</article>
60+</div>
61+{% endblock %}
62+{% block closure %}
63+<style>
64+/* Mobile-friendly styles */
65+@media screen and (max-width: 960px) {
66+ .span-4, footer, #main-nav, footer .logo-ubuntu, .nav-secondary { display: none; }
67+ #page-header { text-align: center; }
68+ #page-header a { height: 24px; line-height: 1; float: none; display: inline; }
69+ .span-8, .span-9, .span-3, .span-12 { width: 100%; }
70+ #fb-root * { width: auto; }
71+}
72+</style>
73+{% endblock %}
74+
75
76=== modified file 'summit/common/tests.py'
77--- summit/common/tests.py 2013-05-09 19:24:33 +0000
78+++ summit/common/tests.py 2013-05-10 13:47:31 +0000
79@@ -18,11 +18,12 @@
80 import datetime
81 from django import test as djangotest
82 from model_mommy import mommy as factory
83+from django.core.urlresolvers import reverse
84+from django.contrib.sites.models import Site
85+
86 from summit.schedule.fields import NameField
87-
88 from summit.schedule.models import Summit
89 from summit.common.models import Menu
90-from django.contrib.sites.models import Site
91
92 # Monkey-patch our NameField into the types of fields that the factory
93 # understands. This is simpler than trying to subclass the Mommy
94@@ -106,3 +107,61 @@
95 'href="/today/uds-test/" title="Today">Today</a>',
96 0,
97 )
98+
99+
100+class IndexRedirectTestCase(djangotest.TestCase):
101+
102+ def test_index_redirects_correct_summit(self):
103+ """
104+ Test that when loading / it redirects to the newest summit event
105+ """
106+ site = factory.make_one(Site, id=1)
107+ summit1 = factory.make_one(
108+ Summit,
109+ name='uds-test1',
110+ date_start='2011-05-10',
111+ date_end='2011-05-15',
112+ )
113+ summit1.sites.add(site)
114+ summit2 = factory.make_one(
115+ Summit,
116+ name='uds-test2',
117+ date_start='2013-05-10',
118+ date_end='2013-05-15',
119+ )
120+ summit2.sites.add(site)
121+ summit3 = factory.make_one(
122+ Summit,
123+ name='uds-test3',
124+ date_start='2012-05-10',
125+ date_end='2012-05-15',
126+ )
127+ summit3.sites.add(site)
128+ index = self.client.get(
129+ reverse(
130+ 'summit.common.views.index',
131+ ),
132+ )
133+ response = reverse(
134+ 'summit.schedule.views.summit',
135+ args=(summit2.name,)
136+ )
137+ self.assertRedirects(
138+ index,
139+ response,
140+ )
141+ response = self.client.get(response)
142+ self.assertContains(response, summit2.title)
143+
144+ def test_no_summit_no_redirect(self):
145+ """
146+ Tests that if a summit does not exist, the index page displays a
147+ no summit page, not redirects
148+ """
149+ index = self.client.get(
150+ reverse(
151+ 'summit.common.views.index',
152+ ),
153+ )
154+ self.assertEqual(index.status_code, 200)
155+ self.assertTemplateUsed(index, 'common/no_summit.html')
156
157=== modified file 'summit/common/views.py'
158--- summit/common/views.py 2013-02-26 19:31:21 +0000
159+++ summit/common/views.py 2013-05-10 13:47:31 +0000
160@@ -14,10 +14,11 @@
161 # You should have received a copy of the GNU Affero General Public License
162 # along with this program. If not, see <http://www.gnu.org/licenses/>.
163
164-from django.shortcuts import render_to_response
165+from django.shortcuts import render_to_response, redirect
166 from django.template.loader import render_to_string
167 from django.template import RequestContext
168 from django.http import HttpResponse
169+from django.core.urlresolvers import reverse
170
171 from summit.schedule.models import Summit
172
173@@ -35,14 +36,22 @@
174 def index(request):
175 try:
176 summit = Summit.on_site.all().order_by('-date_start')[0]
177+ print summit.name
178+ args = [summit.name, ]
179+ return redirect(
180+ reverse(
181+ "summit.schedule.views.summit",
182+ args=args,
183+ ),
184+ )
185 except IndexError:
186- summit = Summit(name='no-summit', title='No Summit')
187-
188- context = {
189- 'summit': summit,
190- }
191- return render_to_response("common/index.html", context,
192- context_instance=RequestContext(request))
193+ #summit = Summit(name='no-summit', title='No Summit')
194+
195+ #context = {
196+ #'summit': summit,
197+ # }
198+ return render_to_response("common/no_summit.html")
199+
200
201 def login_failure(request, message, status=403,
202 template_name='login_failure.html',
203@@ -56,8 +65,7 @@
204 context['solution'] = 'Try logging in again using your Yubikey'
205 elif isinstance(exception, MissingUsernameViolation):
206 context['solution'] = 'You will need to create a <a href="https://launchpad.net/people/+me">Launchpad profile</a> to use The Summit Scheduler'
207-
208+
209 data = render_to_string(template_name, context,
210 context_instance=RequestContext(request))
211 return HttpResponse(data, status=status)
212-

Subscribers

People subscribed via source and target branches