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
=== removed file 'summit/common/templates/common/index.html'
--- summit/common/templates/common/index.html 2012-04-23 14:07:02 +0000
+++ summit/common/templates/common/index.html 1970-01-01 00:00:00 +0000
@@ -1,35 +0,0 @@
1{% extends "base.html" %}
2{% load datetime %}
3
4{% block page_name %}Home{%endblock %}
5{% block extrahead %}
6{{ block.super }}
7{% endblock %}
8
9{% block sub_nav %}{% endblock %}
10
11{% block content %}
12<div class="row">
13<article class="span-12">
14 {% if summit %}
15 <h1><a href="/{{ summit.name }}">{{ summit.title }} &rsaquo;</a></h1>
16 {% include "schedule/summit_info.html" %}
17 {% else %}
18 <p>No summits registered.</p>
19 {% endif %}
20</article>
21</div>
22{% endblock %}
23{% block closure %}
24<style>
25/* Mobile-friendly styles */
26@media screen and (max-width: 960px) {
27 .span-4, footer, #main-nav, footer .logo-ubuntu, .nav-secondary { display: none; }
28 #page-header { text-align: center; }
29 #page-header a { height: 24px; line-height: 1; float: none; display: inline; }
30 .span-8, .span-9, .span-3, .span-12 { width: 100%; }
31 #fb-root * { width: auto; }
32}
33</style>
34{% endblock %}
35
360
=== added file 'summit/common/templates/common/no_summit.html'
--- summit/common/templates/common/no_summit.html 1970-01-01 00:00:00 +0000
+++ summit/common/templates/common/no_summit.html 2013-05-10 13:47:31 +0000
@@ -0,0 +1,30 @@
1{% extends "base.html" %}
2
3{% block page_name %}Home{%endblock %}
4{% block extrahead %}
5{{ block.super }}
6{% endblock %}
7
8{% block sub_nav %}{% endblock %}
9
10{% block content %}
11<div class="row">
12<article class="span-12">
13 <h1>No summit found!</h1>
14 <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>
15</article>
16</div>
17{% endblock %}
18{% block closure %}
19<style>
20/* Mobile-friendly styles */
21@media screen and (max-width: 960px) {
22 .span-4, footer, #main-nav, footer .logo-ubuntu, .nav-secondary { display: none; }
23 #page-header { text-align: center; }
24 #page-header a { height: 24px; line-height: 1; float: none; display: inline; }
25 .span-8, .span-9, .span-3, .span-12 { width: 100%; }
26 #fb-root * { width: auto; }
27}
28</style>
29{% endblock %}
30
031
=== modified file 'summit/common/tests.py'
--- summit/common/tests.py 2013-05-09 19:24:33 +0000
+++ summit/common/tests.py 2013-05-10 13:47:31 +0000
@@ -18,11 +18,12 @@
18import datetime18import datetime
19from django import test as djangotest19from django import test as djangotest
20from model_mommy import mommy as factory20from model_mommy import mommy as factory
21from django.core.urlresolvers import reverse
22from django.contrib.sites.models import Site
23
21from summit.schedule.fields import NameField24from summit.schedule.fields import NameField
22
23from summit.schedule.models import Summit25from summit.schedule.models import Summit
24from summit.common.models import Menu26from summit.common.models import Menu
25from django.contrib.sites.models import Site
2627
27# Monkey-patch our NameField into the types of fields that the factory28# Monkey-patch our NameField into the types of fields that the factory
28# understands. This is simpler than trying to subclass the Mommy29# understands. This is simpler than trying to subclass the Mommy
@@ -106,3 +107,61 @@
106 'href="/today/uds-test/" title="Today">Today</a>',107 'href="/today/uds-test/" title="Today">Today</a>',
107 0,108 0,
108 )109 )
110
111
112class IndexRedirectTestCase(djangotest.TestCase):
113
114 def test_index_redirects_correct_summit(self):
115 """
116 Test that when loading / it redirects to the newest summit event
117 """
118 site = factory.make_one(Site, id=1)
119 summit1 = factory.make_one(
120 Summit,
121 name='uds-test1',
122 date_start='2011-05-10',
123 date_end='2011-05-15',
124 )
125 summit1.sites.add(site)
126 summit2 = factory.make_one(
127 Summit,
128 name='uds-test2',
129 date_start='2013-05-10',
130 date_end='2013-05-15',
131 )
132 summit2.sites.add(site)
133 summit3 = factory.make_one(
134 Summit,
135 name='uds-test3',
136 date_start='2012-05-10',
137 date_end='2012-05-15',
138 )
139 summit3.sites.add(site)
140 index = self.client.get(
141 reverse(
142 'summit.common.views.index',
143 ),
144 )
145 response = reverse(
146 'summit.schedule.views.summit',
147 args=(summit2.name,)
148 )
149 self.assertRedirects(
150 index,
151 response,
152 )
153 response = self.client.get(response)
154 self.assertContains(response, summit2.title)
155
156 def test_no_summit_no_redirect(self):
157 """
158 Tests that if a summit does not exist, the index page displays a
159 no summit page, not redirects
160 """
161 index = self.client.get(
162 reverse(
163 'summit.common.views.index',
164 ),
165 )
166 self.assertEqual(index.status_code, 200)
167 self.assertTemplateUsed(index, 'common/no_summit.html')
109168
=== modified file 'summit/common/views.py'
--- summit/common/views.py 2013-02-26 19:31:21 +0000
+++ summit/common/views.py 2013-05-10 13:47:31 +0000
@@ -14,10 +14,11 @@
14# You should have received a copy of the GNU Affero General Public License14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.15# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17from django.shortcuts import render_to_response17from django.shortcuts import render_to_response, redirect
18from django.template.loader import render_to_string18from django.template.loader import render_to_string
19from django.template import RequestContext19from django.template import RequestContext
20from django.http import HttpResponse20from django.http import HttpResponse
21from django.core.urlresolvers import reverse
2122
22from summit.schedule.models import Summit23from summit.schedule.models import Summit
2324
@@ -35,14 +36,22 @@
35def index(request):36def index(request):
36 try:37 try:
37 summit = Summit.on_site.all().order_by('-date_start')[0]38 summit = Summit.on_site.all().order_by('-date_start')[0]
39 print summit.name
40 args = [summit.name, ]
41 return redirect(
42 reverse(
43 "summit.schedule.views.summit",
44 args=args,
45 ),
46 )
38 except IndexError:47 except IndexError:
39 summit = Summit(name='no-summit', title='No Summit')48 #summit = Summit(name='no-summit', title='No Summit')
4049
41 context = {50 #context = {
42 'summit': summit,51 #'summit': summit,
43 }52 # }
44 return render_to_response("common/index.html", context,53 return render_to_response("common/no_summit.html")
45 context_instance=RequestContext(request))54
4655
47def login_failure(request, message, status=403,56def login_failure(request, message, status=403,
48 template_name='login_failure.html',57 template_name='login_failure.html',
@@ -56,8 +65,7 @@
56 context['solution'] = 'Try logging in again using your Yubikey'65 context['solution'] = 'Try logging in again using your Yubikey'
57 elif isinstance(exception, MissingUsernameViolation):66 elif isinstance(exception, MissingUsernameViolation):
58 context['solution'] = 'You will need to create a <a href="https://launchpad.net/people/+me">Launchpad profile</a> to use The Summit Scheduler'67 context['solution'] = 'You will need to create a <a href="https://launchpad.net/people/+me">Launchpad profile</a> to use The Summit Scheduler'
59 68
60 data = render_to_string(template_name, context,69 data = render_to_string(template_name, context,
61 context_instance=RequestContext(request))70 context_instance=RequestContext(request))
62 return HttpResponse(data, status=status)71 return HttpResponse(data, status=status)
63

Subscribers

People subscribed via source and target branches