mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
ikiwiki: Add delete command for wikis and blogs.
This commit is contained in:
parent
1464ff3184
commit
18234850ff
@ -22,6 +22,7 @@ Configuration helper for ikiwiki
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
|
||||
@ -58,6 +59,10 @@ def parse_arguments():
|
||||
create_blog = subparsers.add_parser('create-blog', help='Create a blog')
|
||||
create_blog.add_argument('--name', help='Name of new blog')
|
||||
|
||||
# Delete a wiki or blog
|
||||
delete = subparsers.add_parser('delete', help='Delete a wiki or blog.')
|
||||
delete.add_argument('--name', help='Name of wiki or blog to delete.')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@ -73,10 +78,11 @@ def subcommand_enable(_):
|
||||
"""Enable ikiwiki site."""
|
||||
if not os.path.isfile(CONFIG_FILE):
|
||||
setup()
|
||||
|
||||
subprocess.check_output(['a2enmod', 'cgi'])
|
||||
subprocess.check_output(['a2enconf', 'ikiwiki'])
|
||||
subprocess.check_output(['service', 'apache2', 'restart'])
|
||||
subprocess.check_output(['a2enconf', 'ikiwiki'])
|
||||
subprocess.check_output(['service', 'apache2', 'restart'])
|
||||
else:
|
||||
subprocess.check_output(['a2enconf', 'ikiwiki'])
|
||||
subprocess.check_output(['service', 'apache2', 'reload'])
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
@ -86,26 +92,39 @@ def subcommand_disable(_):
|
||||
|
||||
|
||||
def subcommand_get_sites(_):
|
||||
"""Get wikis and blogs"""
|
||||
"""Get wikis and blogs."""
|
||||
sites = os.listdir(WIKI_PATH)
|
||||
print('\n'.join(sites))
|
||||
|
||||
|
||||
def subcommand_create_wiki(arguments):
|
||||
"""Create a wiki"""
|
||||
"""Create a wiki."""
|
||||
subprocess.check_output(['ikiwiki', '-setup', SETUP_WIKI, arguments.name])
|
||||
|
||||
|
||||
def subcommand_create_blog(arguments):
|
||||
"""Create a blog"""
|
||||
"""Create a blog."""
|
||||
subprocess.check_output(['ikiwiki', '-setup', SETUP_BLOG, arguments.name])
|
||||
|
||||
|
||||
def subcommand_delete(arguments):
|
||||
"""Delete a wiki or blog."""
|
||||
wiki_folder = os.path.join(WIKI_PATH, arguments.name)
|
||||
try:
|
||||
shutil.rmtree(wiki_folder)
|
||||
print('Deleted %s' % arguments.name)
|
||||
except FileNotFoundError:
|
||||
print('Error: %s not found.' % arguments.name)
|
||||
exit(1)
|
||||
|
||||
|
||||
def setup():
|
||||
"""Initial setup"""
|
||||
if not os.path.exists(WIKI_PATH):
|
||||
os.makedirs(WIKI_PATH)
|
||||
|
||||
subprocess.check_output(['a2enmod', 'cgi'])
|
||||
|
||||
with open(CONFIG_FILE, 'w') as conffile:
|
||||
conffile.writelines([
|
||||
'Alias /ikiwiki /var/www/ikiwiki\n',
|
||||
|
||||
39
plinth/modules/ikiwiki/templates/ikiwiki_delete.html
Normal file
39
plinth/modules/ikiwiki/templates/ikiwiki_delete.html
Normal file
@ -0,0 +1,39 @@
|
||||
{% extends "base.html" %}
|
||||
{% comment %}
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
{% endcomment %}
|
||||
|
||||
{% load bootstrap %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h3>Delete Wiki/Blog <em>{{ name }}</em></h3>
|
||||
|
||||
<p>Delete this wiki/blog permanently?</p>
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
<input type="submit" class="btn btn-md btn-primary"
|
||||
value="Delete {{ name }}"/>
|
||||
|
||||
<a href="{% url 'ikiwiki:manage' %}" role="button"
|
||||
class="btn btn-md btn-primary">Cancel</a>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
@ -39,7 +39,7 @@
|
||||
<div class="list-group">
|
||||
{% for site in sites %}
|
||||
<div class="list-group-item clearfix">
|
||||
<a href="{% url 'ikiwiki:index' %}"
|
||||
<a href="{% url 'ikiwiki:delete' site %}"
|
||||
class="btn btn-default btn-sm pull-right"
|
||||
role="button" title="Delete site {{ site }}">
|
||||
<span class="glyphicon glyphicon-trash"
|
||||
|
||||
@ -26,5 +26,6 @@ urlpatterns = patterns(
|
||||
'plinth.modules.ikiwiki.views',
|
||||
url(r'^apps/ikiwiki/$', 'index', name='index'),
|
||||
url(r'^apps/ikiwiki/manage/$', 'manage', name='manage'),
|
||||
url(r'^apps/ikiwiki/(?P<name>[\w.@+-]+)/delete/$', 'delete', name='delete'),
|
||||
url(r'^apps/ikiwiki/create/$', 'create', name='create'),
|
||||
)
|
||||
|
||||
@ -22,6 +22,7 @@ Plinth module for configuring ikiwiki
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.shortcuts import redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from gettext import gettext as _
|
||||
|
||||
@ -109,7 +110,8 @@ def create(request):
|
||||
_create_wiki(request, form.cleaned_data['name'])
|
||||
elif form.cleaned_data['type'] == 'blog':
|
||||
_create_blog(request, form.cleaned_data['name'])
|
||||
form = IkiwikiCreateForm(prefix='ikiwiki')
|
||||
|
||||
return redirect(reverse_lazy('ikiwiki:manage'))
|
||||
else:
|
||||
form = IkiwikiCreateForm(prefix='ikiwiki')
|
||||
|
||||
@ -121,9 +123,38 @@ def create(request):
|
||||
|
||||
def _create_wiki(request, name):
|
||||
"""Create wiki."""
|
||||
actions.superuser_run('ikiwiki', ['create-wiki', '--name', name])
|
||||
try:
|
||||
actions.superuser_run('ikiwiki', ['create-wiki', '--name', name])
|
||||
messages.success(request, _('Created wiki %s.') % name)
|
||||
except actions.ActionError as err:
|
||||
messages.error(request, _('Could not create wiki: %s') % err)
|
||||
|
||||
|
||||
def _create_blog(request, name):
|
||||
"""Create blog."""
|
||||
actions.superuser_run('ikiwiki', ['create-blog', '--name', name])
|
||||
try:
|
||||
actions.superuser_run('ikiwiki', ['create-blog', '--name', name])
|
||||
messages.success(request, _('Created blog %s.') % name)
|
||||
except actions.ActionError as err:
|
||||
messages.error(request, _('Could not create blog: %s') % err)
|
||||
|
||||
|
||||
@login_required
|
||||
def delete(request, name):
|
||||
"""Handle deleting wikis/blogs, showing a confirmation dialog first.
|
||||
|
||||
On GET, display a confirmation page.
|
||||
On POST, delete the wiki/blog.
|
||||
"""
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
actions.superuser_run('ikiwiki', ['delete', '--name', name])
|
||||
messages.success(request, _('%s deleted.') % name)
|
||||
except actions.ActionError as err:
|
||||
messages.error(request, _('Could not delete %s: %s') % (name, err))
|
||||
return redirect(reverse_lazy('ikiwiki:manage'))
|
||||
|
||||
return TemplateResponse(request, 'ikiwiki_delete.html',
|
||||
{'title': _('Delete Wiki/Blog'),
|
||||
'subsubmenu': subsubmenu,
|
||||
'name': name})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user