diff --git a/actions/ikiwiki b/actions/ikiwiki index 16cadaeca..3c6afb8c2 100755 --- a/actions/ikiwiki +++ b/actions/ikiwiki @@ -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', diff --git a/plinth/modules/ikiwiki/templates/ikiwiki_delete.html b/plinth/modules/ikiwiki/templates/ikiwiki_delete.html new file mode 100644 index 000000000..dc4726b73 --- /dev/null +++ b/plinth/modules/ikiwiki/templates/ikiwiki_delete.html @@ -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 . +# +{% endcomment %} + +{% load bootstrap %} + +{% block content %} + +

Delete Wiki/Blog {{ name }}

+ +

Delete this wiki/blog permanently?

+ +
+ {% csrf_token %} + + + + Cancel +
+ +{% endblock %} diff --git a/plinth/modules/ikiwiki/templates/ikiwiki_manage.html b/plinth/modules/ikiwiki/templates/ikiwiki_manage.html index aa0051e59..d5fbde7d0 100644 --- a/plinth/modules/ikiwiki/templates/ikiwiki_manage.html +++ b/plinth/modules/ikiwiki/templates/ikiwiki_manage.html @@ -39,7 +39,7 @@
{% for site in sites %}
- [\w.@+-]+)/delete/$', 'delete', name='delete'), url(r'^apps/ikiwiki/create/$', 'create', name='create'), ) diff --git a/plinth/modules/ikiwiki/views.py b/plinth/modules/ikiwiki/views.py index 6343c5286..9a1b84799 100644 --- a/plinth/modules/ikiwiki/views.py +++ b/plinth/modules/ikiwiki/views.py @@ -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})