From dbdec551f234c6dfdb992184b715e9af8462433c Mon Sep 17 00:00:00 2001 From: Weitian LI Date: Tue, 3 Jun 2014 11:28:12 +0800 Subject: Show latest import notice at index page. * added 'page.views.IndexView' for 'django_skaschool.urls * updated 'index.html' to display notice at bottom * added '.smallcaps' in 'index.css' for English title --- django_skaschool/urls.py | 5 +++-- page/views.py | 19 ++++++++++++++++++- static/css/index.css | 5 +++++ templates/index.html | 17 ++++++++++++++++- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/django_skaschool/urls.py b/django_skaschool/urls.py index 7830463..60a298a 100644 --- a/django_skaschool/urls.py +++ b/django_skaschool/urls.py @@ -10,13 +10,14 @@ from django.conf.urls.static import static from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.views.generic.base import TemplateView +from page.views import IndexView + urlpatterns = patterns('', # admin url(r'^admin/', include(admin.site.urls)), # index page - url(r'^$', TemplateView.as_view(template_name='index.html'), - name='index'), + url(r'^$', IndexView.as_view(), name='index'), # app 'page' url(r'^page/', include('page.urls')), # app 'notice' diff --git a/page/views.py b/page/views.py index 3af87bb..a777e2f 100644 --- a/page/views.py +++ b/page/views.py @@ -7,8 +7,25 @@ App 'page' views from django.shortcuts import render from django.views.generic.base import TemplateView +from notice.models import Notice -###### class-based views ###### +## IndexView for index page (django_skaschool/urls.py) +class IndexView(TemplateView): + """ + class-based view for index page + """ + template_name = 'index.html' + + def get_context_data(self, **kwargs): + context = super(type(self), self).get_context_data(**kwargs) + # latest important notice (only display single one) + important_notice_all = Notice.objects.filter(is_important=True).order_by('-pubtime') + if important_notice_all: + important_notice = important_notice_all[0] + else: + important_notice = None + context['important_notice'] = important_notice + return context diff --git a/static/css/index.css b/static/css/index.css index 6a2d573..1858ee6 100644 --- a/static/css/index.css +++ b/static/css/index.css @@ -95,7 +95,12 @@ border-color: #E5E5E5; } +.smallcaps { + font-variant: small-caps; +} + footer { color: #CCCCCC; } + diff --git a/templates/index.html b/templates/index.html index 661dbae..16244d4 100644 --- a/templates/index.html +++ b/templates/index.html @@ -11,10 +11,12 @@ {% endblock %} {% block content %} + + {# title and main info #}

第二届 中国SKA暑期学校

暨 中国-新西兰联合SKA暑期学校

-

China-New Zealand Joint SKA Summer School

+

China-New Zealand Joint SKA Summer School


@@ -33,7 +35,20 @@ {% endblock %} {# content #} {% block footer %} + {# display latest important notice #} + {% if important_notice %} +

+
+ + [通知] + {# notice contents #} + {{ important_notice.contents }} +
+
+ {% endif %} +