Fix handling mil home page
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 18 Oct 2013 08:09:35 +0000 (10:09 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 22 Oct 2013 07:49:53 +0000 (09:49 +0200)
Defining flat pages in urlpatterns breaks language_switcher behavior

edumed/milurls.py
edumed/templates/base_mil.html
edumed/views.py

index 0b3ea6c..9178dfa 100644 (file)
@@ -1,19 +1,15 @@
 from django.conf.urls import include, url, patterns
 
 from fnpdjango.utils.urls import i18n_patterns
-from .views import MILHomeView
+from .views import mil_home_view
 
 
 urlpatterns = i18n_patterns('',
+    url(r'^$', mil_home_view, name="mil_home"),
     url(r'^kompetencje/', include('curriculum.urls')),
     url(r'^wez-udzial/', include('comment.urls'))
 )
 
-urlpatterns += patterns('',
-    url(r'^$', 'django.contrib.flatpages.views.flatpage', {'url': '/'}, name="mil_home_pl"),
-    url(r'^en/$', 'django.contrib.flatpages.views.flatpage', {'url': '/en/'}, name="mil_home_en")
-)
-
 handler404 = 'edumed.views.mil_404_view'
 
 
index dec800b..e5300e6 100644 (file)
@@ -5,7 +5,7 @@
 {% load i18n %}
 
 {% block top_navigation %}
-    <li><a class="menu-wspolpraca" href="{% if request.LANGUAGE_CODE == 'pl' %}{% url "mil_home_pl" %}{% else %}{% url "mil_home_en" %}{% endif %}">{% trans 'Consultations' %}</a></li>
+    <li><a class="menu-wspolpraca" href="{% url "mil_home" %}">{% trans 'Consultations' %}</a></li>
         <li><a class="menu-kompetencje" href="{% url "curriculum" %}">{% trans 'Competencies' %}</a></li>
         <li><a class="menu-wspolpraca" href="/wez-udzial">{% trans 'Take Part' %}</a></li>
         {% if request.LANGUAGE_CODE == 'pl' %}
index f2fa91f..009f6a0 100755 (executable)
@@ -2,6 +2,7 @@ import os.path
 from django.conf import settings
 from django.views.generic import TemplateView
 from django.views.defaults import page_not_found
+from django.contrib.flatpages.views import flatpage
 from pybb.views import ProfileEditView
 from .forms import AvatarlessEditProfileForm
 
@@ -16,8 +17,8 @@ class HomeView(TemplateView):
         return context
 
 
-class MILHomeView(TemplateView):
-    template_name = 'home_mil.html'
+def mil_home_view(request):
+    return flatpage(request, url = '/' if request.LANGUAGE_CODE == 'pl' else '/en/')
 
 def mil_404_view(request):
     return page_not_found(request, '404_mil.html')