diff --git a/base/middleware.py b/base/middleware.py index 9428ce3efc..490d62859b 100644 --- a/base/middleware.py +++ b/base/middleware.py @@ -1,5 +1,10 @@ +from django.core.cache import cache + from seaserv import get_binding_peerids +from seahub.notifications.models import Notification +from seahub.notifications.utils import refresh_cache + class UseridMiddleware(object): """Store ccnet user ids in request.user.userid_list""" @@ -16,3 +21,30 @@ class UseridMiddleware(object): def process_response(self, request, response): return response + +class InfobarMiddleware(object): + """Query info bar close status, and store into reqeust.""" + + def get_from_db(self): + ret = Notification.objects.all().filter(primary=1) + refresh_cache() + return ret + + def process_request(self, request): + topinfo_close = request.COOKIES.get('topinfo', '') + + cur_note = cache.get('CUR_TOPINFO') if cache.get('CUR_TOPINFO') else \ + self.get_from_db() + if not cur_note: + request.cur_note = None + else: + if str(cur_note[0].id) in topinfo_close.split(','): + request.cur_note = None + else: + request.cur_note = cur_note[0] + + return None + + def process_response(self, request, response): + return response + diff --git a/media/css/seahub.css b/media/css/seahub.css index db511a0283..815191fa1a 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -127,6 +127,12 @@ table img { width:680px; } #footer { color:#999; padding-top:2px; margin:25px auto; border-top:1px solid #DDD; } + +/* info-bar */ +#info-bar { height: 30px; color: #fff; background: #000; } +#info-bar .info { margin: 5px 0 auto 1em; float: left; } +#info-bar .close { margin: 7px 5px auto 0; float: right; background: url(../img/close-16.png); height: 16px; width:16px; } + /* top-bar */ #top-bar { height:20px; padding-bottom:21px; background:#fff url('../img/dropshadow.png') repeat-x center bottom; } .top-bar { height:20px; color:#fff; text-align:right; font-weight:bold; background:#606; } @@ -331,3 +337,6 @@ h2.repo-history { background:transparent url('../img/add.png') scroll no-repeat left 50%; margin-top:2px; } + +/* notification admin */ +.cur-note { color: red; font-size: 75%; } diff --git a/notifications/__init__.py b/notifications/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/notifications/models.py b/notifications/models.py new file mode 100644 index 0000000000..f7122faedf --- /dev/null +++ b/notifications/models.py @@ -0,0 +1,18 @@ +from django.db import models +from django.forms import ModelForm, Textarea + +class Notification(models.Model): + message = models.CharField(max_length=512) + primary = models.BooleanField(default=False) + +class NotificationForm(ModelForm): + """ + Form for adding notification. + """ + class Meta: + model = Notification + fields = ('message', 'primary') + widgets = { + 'message': Textarea(), + } + diff --git a/notifications/templates/notifications/add_notification_form.html b/notifications/templates/notifications/add_notification_form.html new file mode 100644 index 0000000000..d9a82398ec --- /dev/null +++ b/notifications/templates/notifications/add_notification_form.html @@ -0,0 +1,18 @@ +{% extends "admin_base.html" %} +{% block title %}添加通知{% endblock %} +{% block nav_notificationadmin_class %}class="cur"{% endblock %} +{% block main_panel %} +
内容 | +操作 | +
---|---|
{{ note.message }} + {% if note.primary == 1 %} + (当前通知) + {% endif %} + | + {% if note.primary != 1 %} + + {% endif %} + + | +
暂无
+{% endif %} +{% endblock %} + +{% block extra_script %} + +{% endblock %} + diff --git a/notifications/tests.py b/notifications/tests.py new file mode 100644 index 0000000000..501deb776c --- /dev/null +++ b/notifications/tests.py @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff --git a/notifications/urls.py b/notifications/urls.py new file mode 100644 index 0000000000..7d5ff43812 --- /dev/null +++ b/notifications/urls.py @@ -0,0 +1,11 @@ +from django.conf.urls.defaults import patterns, url + +urlpatterns = patterns('notifications.views', +# url(r'^$', 'notification_list', name='notification_list'), + url(r'^add/$', 'notification_add', name='notification_add'), + url(r'^delete/(?P