diff options
Diffstat (limited to 'notice')
-rw-r--r-- | notice/admin.py | 1 | ||||
-rw-r--r-- | notice/models.py | 11 | ||||
-rw-r--r-- | notice/static/css/list_notice.css | 84 | ||||
-rw-r--r-- | notice/templates/notice/list_notice.html | 50 | ||||
-rw-r--r-- | notice/urls.py | 16 | ||||
-rw-r--r-- | notice/views.py | 25 |
6 files changed, 186 insertions, 1 deletions
diff --git a/notice/admin.py b/notice/admin.py index bed31e4..6dcd819 100644 --- a/notice/admin.py +++ b/notice/admin.py @@ -19,4 +19,5 @@ class NoticeAdmin(admin.ModelAdmin): ## register to admin admin.site.register(Notice, NoticeAdmin) admin.site.register(NoticeCategory) +admin.site.register(NoticeAttachment) diff --git a/notice/models.py b/notice/models.py index af2e648..f5201d5 100644 --- a/notice/models.py +++ b/notice/models.py @@ -28,6 +28,15 @@ class Notice(models.Model): def __unicode__(self): return u'Notice at %s' % self.pubtime.isoformat() + def show_pubtime(self): + # used in 'list_notice.html' template + return self.pubtime.strftime('%Y-%m-%d') + + def get_attachment_list(self): + # used in 'list_notice.html' template, + # because 'GenericRelatedObjectManager' is not iterable + return list(self.attachments.all()) + class NoticeCategory(models.Model): """ @@ -45,6 +54,8 @@ class NoticeCategory(models.Model): class NoticeAttachment(models.Model): + title = models.CharField(_("Title"), max_length=100) + description = models.TextField(_("Description")) attachment = models.FileField(upload_to='notice/attachments', verbose_name=_("Attachment")) content_type = models.ForeignKey(ContentType) diff --git a/notice/static/css/list_notice.css b/notice/static/css/list_notice.css new file mode 100644 index 0000000..79cb1d1 --- /dev/null +++ b/notice/static/css/list_notice.css @@ -0,0 +1,84 @@ +/* + * css for 'list_notice.html' + * + * based on 'docs.css' Examples section from bootstrap 3 + */ + +.notice-title { + position: relative; + padding: 0px 15px 0px 15px; + margin: 0 -15px 15px; + /* background-color: #fafafa; */ + background-color: #f4f8fa; + border-color: #e5e5e5 #eee #eee; + border-style: solid; + border-width: 1px 0; + -webkit-box-shadow: inset 0 3px 6px rgba(0,0,0,.05); + box-shadow: inset 0 3px 6px rgba(0,0,0,.05); +} + +/* Tweak display of the code snippets when following an example */ +.notice-title + .notice-content { + margin: -15px -15px 15px; + border-width: 0 0 1px; + border-radius: 0; +} + +/* Make the examples and snippets not full-width */ +@media (min-width: 768px) { + .notice-title { + margin-right: 0; + margin-left: 0; + background-color: #f4f8fa; + border-color: #ddd; + border-width: 1px; + border-radius: 4px 4px 0 0; + -webkit-box-shadow: none; + box-shadow: none; + } + .notice-title + .notice-content { + margin-top: -16px; + margin-right: 0; + margin-left: 0; + border-width: 1px; + /* + border-bottom-right-radius: 4px; + border-bottom-left-radius: 4px; + */ + } + .notice-content + .notice-attachment { + margin-top: -16px; + margin-right: 0; + margin-left: 0; + border-width: 1px; + border-radius: 0 0 4px 4px; + } +} + +/* Undo width of container */ +.notice-title .container { + width: auto; +} + +.notice-content { + padding: 9px 14px; + margin-bottom: 14px; + background-color: #f7f7f9; + border: 1px solid #e1e1e8; + /* border-radius: 4px; */ +} + +.notice-attachment { + padding: 9px 14px; + margin-bottom: 14px; + background-color: #ffffff; + border: 1px solid #e1e1e8; + border-radius: 4px; +} + +/* remove 'ul' margin-bottom */ +.notice-attachment ul { + margin-bottom: 0; +} + + diff --git a/notice/templates/notice/list_notice.html b/notice/templates/notice/list_notice.html new file mode 100644 index 0000000..77d194c --- /dev/null +++ b/notice/templates/notice/list_notice.html @@ -0,0 +1,50 @@ +{% extends 'base.html' %} +{% load staticfiles %} +{% load url from future %} +{% load i18n %} +{% load bootstrap3 %} + +{# template to show notice list #} + +{% block title %} +全部通知 | 2014 SKA Summer School +{% endblock %} + +{% block css_extra %} + <link href="{% static 'css/list_notice.css' %}" rel="stylesheet"> +{% endblock %} + +{% block content %} + <div class="container"> + <h2>全部通知</h2> + <br> + {% for notice in object_list %} + <div class="notice-title"> + <h3>{{ notice.title }} {% if notice.is_important %}<span class="label label-primary">重要</span>{% endif %}</h3> + <p>{{ notice.show_pubtime }}, {{ notice.category.category_name }}</p> + </div> + <div class="notice-content"> + {{ notice.contents }} + </div> + {% if notice.attachments %} + <div class="notice-attachment"> + <ul class="list-unstyled"> + {% for attachment in notice.get_attachment_list %} + <li> + 附件{{ forloop.counter }}: + <a href="{{ attachment.attachment.url }}">{{ attachment.title }}</a> + </li> + {% endfor %} + </ul> + </div> + {% endif %} + <br> + {% empty %} + <div class="alert alert-info"> + 暂时没有通知,多谢您的关注…… + </div> + {% endfor %} + </div> +{% endblock %} + +{# vim: set ts=8 sw=2 tw=0 fenc=utf-8 ft=htmldjango.html: #} diff --git a/notice/urls.py b/notice/urls.py new file mode 100644 index 0000000..9362213 --- /dev/null +++ b/notice/urls.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# +# urls.py for app 'page' +# + +from django.conf.urls import patterns, include, url + +from notice.views import ListNoticeView + + +urlpatterns = patterns('', + # notice list view + url(r'^list/$', ListNoticeView.as_view(), + name='list_notice'), +) + diff --git a/notice/views.py b/notice/views.py index 91ea44a..eb6b0b1 100644 --- a/notice/views.py +++ b/notice/views.py @@ -1,3 +1,26 @@ +# -*- coding: utf-8 -*- + from django.shortcuts import render +from django.views.generic.list import ListView + +from notice.models import Notice + + +class ListNoticeView(ListView): + """ + class-based view to show list of notice + """ + queryset = Notice.objects.all() # default order by '-pubtime' + template_name = 'notice/list_notice.html' + # allow queryset/model returns no object, otherwise 404error raised + allow_empty = True + + def get_context_data(self, **kwargs): + """ + add 'user' context + """ + context = super(ListNoticeView, self).get_context_data(**kwargs) + user = self.request.user + context['user'] = user + return context -# Create your views here. |