Skip to content

Commit

Permalink
Merge pull request #527 from inflrscns/admin_panel
Browse files Browse the repository at this point in the history
Admin panel
  • Loading branch information
benjaoming committed Jan 23, 2016
2 parents 4eb42b3 + a556db1 commit 56abf53
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 8 deletions.
21 changes: 14 additions & 7 deletions wiki/templates/wiki/base_site.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

<!-- Le styles -->
<link href="{{ STATIC_URL }}wiki/bootstrap/css/wiki-bootstrap.min.css" rel="stylesheet">

{% render_block "css" %}

<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
Expand All @@ -23,7 +23,7 @@
<body>

{% block wiki_body %}

{% block wiki_navbar %}
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
Expand Down Expand Up @@ -65,6 +65,14 @@
{% trans "Log out" %}
</a>
</li>
{% if user.is_superuser %}
<li>
<a href="{% url 'wiki:deleted_list' %}">
<i class="fa fa-trash-o"></i>
{% trans "Deleted articles" %}
</a>
</li>
{% endif %}
{% if "wiki.plugins.notifications"|plugin_enabled %}
{% include "wiki/plugins/notifications/menubaritem.html" %}
{% endif %}
Expand Down Expand Up @@ -107,10 +115,10 @@

<!-- Reserved for breadcrumbs -->
{% block wiki_breadcrumbs %}{% endblock %}

<!-- Main page contents go here -->
{% block wiki_contents %}{% endblock %}

<footer id="wiki-footer">
<hr />
{% block wiki_footer_logo %}
Expand All @@ -133,7 +141,6 @@
<!-- Optionally enable responsive features in IE8 -->
<script src="{{ STATIC_URL }}wiki/js/respond.min.js"></script>
{% render_block "js" %}

</body>
</html>

33 changes: 33 additions & 0 deletions wiki/templates/wiki/deleted_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% extends "wiki/base.html" %}
{% load i18n wiki_tags sekizai_tags %}

{% block wiki_pagetitle %}{% trans "Admin Panel" %}{% endblock %}

{% block wiki_contents %}

<h1 class="page-header">{% trans "Deleted Articles" %}</h1>
{% if deleted_articles %}
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Page Title" %}</th>
<th>{% trans "Date Deleted" %}</th>
<th>{% trans "Restore Article" %}</th>
</tr>
</thead>
<tbody>
{% for article in deleted_articles %}
<tr>
<td><a href="{{article.get_absolute_url}}">{{ article }}</a></td>
<td> {{article.modified}} </td>
<td><a href="{% url 'wiki:deleted' article_id=article.id %}?restore=1" class="btn btn-default"><span class="fa fa-repeat"></span>
{% trans "Restore" %}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<b> {% trans "No deleted articles to display" %} </b>
{% endif %}

{% endblock %}
28 changes: 28 additions & 0 deletions wiki/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,31 @@ def test_empty_query_string(self):

response = c.get(reverse('wiki:search'), {'q': ''})
self.assertFalse(response.context['articles'])

class DeletedListViewTest(ArticleWebTestBase):

def test_deleted_articles_list(self):
c = self.c

response = c.post(
reverse('wiki:create', kwargs={'path': ''}),
{'title': 'Delete Me', 'slug': 'deleteme', 'content': 'delete me please!'}
)

self.assertRedirects(
response,
reverse('wiki:get', kwargs={'path': 'deleteme/'})
)

response = c.post(
reverse('wiki:delete', kwargs={'path': 'deleteme/'}),
{'confirm': 'on', 'revision': '2'}
)

self.assertRedirects(
response,
reverse('wiki:get', kwargs={'path': ''})
)

response = c.get(reverse('wiki:deleted_list'))
self.assertContains(response, 'Delete Me')
14 changes: 13 additions & 1 deletion wiki/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from wiki.conf import settings
from wiki.core.plugins import registry
from wiki.views import article, accounts
from wiki.views import article, accounts, deleted_list
from wiki.core.utils import get_class_from_str


Expand Down Expand Up @@ -43,9 +43,13 @@ class WikiURLPatterns(object):
login_view_class = accounts.Login
logout_view_class = accounts.Logout

# deleted list view
deleted_list_view_class = deleted_list.DeletedListView

def get_urls(self):
urlpatterns = self.get_root_urls()
urlpatterns += self.get_accounts_urls()
urlpatterns += self.get_deleted_list_urls()
urlpatterns += self.get_revision_urls()
urlpatterns += self.get_article_urls()
urlpatterns += self.get_plugin_urls()
Expand Down Expand Up @@ -76,6 +80,14 @@ def get_root_urls(self):
]
return urlpatterns

def get_deleted_list_urls(self):
urlpatterns = [
url('^_admin/$',
self.deleted_list_view_class.as_view(),
name="deleted_list"),
]
return urlpatterns

def get_accounts_urls(self):
urlpatterns = [
url('^_accounts/sign-up/$',
Expand Down
25 changes: 25 additions & 0 deletions wiki/views/deleted_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.views.generic.base import TemplateView
from django.shortcuts import redirect

from wiki import models

class DeletedListView(TemplateView):

template_name = "wiki/deleted_list.html"

def dispatch(self, request, *args, **kwargs):
# Let logged in super users continue
if not request.user.is_superuser:
return redirect('wiki:root')

return super(DeletedListView, self).dispatch(request, *args, **kwargs)

def get_context_data(self, **kwargs):
article_list = models.Article.objects.all()
deleted_articles = []
for article in article_list:
if(article.current_revision.deleted):
deleted_articles.append(article)
kwargs['deleted_articles'] = deleted_articles
context = super(DeletedListView, self).get_context_data(**kwargs)
return context

0 comments on commit 56abf53

Please sign in to comment.