Permalink
Browse files

add dashboard/link

  • Loading branch information...
whtsky
whtsky committed Jul 24, 2012
1 parent 3f25ae4 commit e24355c564264ecd9dc6afd72fb8b738ba8cc356
Showing with 118 additions and 1 deletion.
  1. +46 −0 handlers/dashboard.py
  2. +1 −0 init_db.py
  3. +1 −0 locale/zh_CN.csv
  4. +23 −0 templates/base.html
  5. +45 −0 templates/dashboard/link.html
  6. +2 −1 urls.py
View
@@ -0,0 +1,46 @@
+#coding=utf-8
+
+from bson.objectid import ObjectId
+from . import BaseHandler as _BaseHandler
+
+
+class BaseHandler(_BaseHandler):
+ def prepare(self):
+ self.check_role(role_min=3)
+ super(BaseHandler, self).prepare()
+
+
+class LinkHandler(BaseHandler):
+ def get(self):
+ self.render('dashboard/link.html')
+
+ def post(self):
+ name = self.get_argument('name', None)
+ link = self.get_argument('link', None)
+ title = self.get_argument('title', '')
+ priority = int(self.get_argument('priority', 1))
+ if not (name and link and priority):
+ self.flash('Please fill the required field')
+ if link and self.db.links.find_one({'link': link.lower()}):
+ self.flash('This link has been registered')
+ if self.messages:
+ self.redirect('/dashboard/link')
+ self.db.links.insert({
+ 'name': name,
+ 'link': link,
+ 'title': title,
+ 'priority': priority,
+ })
+ self.redirect('/dashboard/link')
+
+
+class RemoveLinkHandler(BaseHandler):
+ def get(self, link_id):
+ self.db.links.remove(ObjectId(link_id))
+ self.redirect('/dashboard/link')
+
+
+handlers = [
+ (r'/dashboard/link', LinkHandler),
+ (r'/dashboard/link/(\w+)/remove', RemoveLinkHandler),
+]
View
@@ -10,3 +10,4 @@
db.topics.create_index([('last_reply_time', -1), ('node', 1)])
db.replies.create_index([('topic', 1), ('index', 1)])
db.notifications.create_index([('to', 1), ('created', 1)])
+db.links.create_index([('priority', -1)])
View
@@ -5,6 +5,7 @@
"Save",保存
"Admin",管理
"SuperAdmin",总管理
+"Links",链接
"Recent Topics",最近更新
"Site status",站点统计
View
@@ -47,6 +47,19 @@
<li><a href="/account/signin?next={{ url_escape(request.uri) }}">{{ _("Signin") }}</a></li>
{% else %}
<li><a href="/member/{{ current_user['name'] }}">{{ current_user['name'] }}</a></li>
+ {% if current_user['role'] == 3 %}
+ <ul class="nav">
+ <li class="dropdown">
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ _("Dashboard") }}
+ <b class="caret"></b>
+ </a>
+ <ul class="dropdown-menu">
+ <li><a href="/dashboard/link">{{ _("Link") }}</a></li>
+ </ul>
+ </li>
+ </ul>
+
+ {% end %}
<ul class="nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ _("Create Topic") }}
@@ -142,6 +155,16 @@
{% end %}
</div>
{% end %}
+ {% if handler.db.links.count() %}
+ <div class="box">
+ <header>{{ _("Links") }}</header>
+ <ul>
+ {% for l in handler.db.links.find(sort=[('priority', -1)]) %}
+ <li><a href="{{ l['link'] }}" title="{{ l['title'] }}" >{{ l['name'] }}</a></li>
+ {% end %}
+ </ul>
+ </div>
+ {% end %}
<div class="box">
<header>{{ _("Site status") }}</header>
<ul>
@@ -0,0 +1,45 @@
+{% extends '../base.html' %}
+
+{% block content %}
+<div class="box">
+ <header>{{ _("Links") }}</header>
+ <table class="table">
+ <thead>
+ <tr>
+ <th>{{ _("Priority") }}</th>
+ <th>{{ _("Name") }}</th>
+ <th>{{ _("Link") }}</th>
+ <th>{{ _("Title") }}</th>
+ <th>{{ _("Action") }}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for link in handler.db.links.find(sort=[('priority', -1)]) %}
+ <tr>
+ <td>{{ link['priority'] }}</td>
+ <td>{{ link['name'] }}</td>
+ <td>{{ link['link'] }}</td>
+ <td>{{ link['title'] }}</td>
+ <td><a href="/dashboard/link/{{ link['_id'] }}/remove" class="btn btn-danger">{{ _("Remove") }}</a></td>
+ </tr>
+ {% end %}
+ </tbody>
+ </table>
+</div>
+{% end %}
+
+{% block sidebar %}
+<div class="box">
+ <header>{{ _("Add Link") }}</header>
+ <form method="post">
+ <fieldset>
+ {% raw xsrf_form_html() %}
+ <input type="text" class="input-medium" id="priority" name="priority" placeholder="priority.optional.">
+ <input type="text" class="input-medium" id="name" name="name" placeholder="name" required>
+ <input type="text" class="input-medium" name="title" placeholder="title.optional." >
+ <input type="text" class="input-medium" id="link" name="link" placeholder="http://" required><br />
+ <button type="submit" class="btn btn-primary">{{ _("Save") }}</button>
+ </fieldset>
+ </form>
+</div>
+{% end %}
View
@@ -1,4 +1,4 @@
-from handlers import account, member, node, topic
+from handlers import account, member, node, topic, dashboard
__all__ = ['handlers', 'ui_modules']
@@ -7,6 +7,7 @@
handlers.extend(member.handlers)
handlers.extend(node.handlers)
handlers.extend(topic.handlers)
+handlers.extend(dashboard.handlers)
ui_modules = {}
ui_modules.update(**node.ui_modules)

0 comments on commit e24355c

Please sign in to comment.