...
 
Commits (2)
{% load wikify %}
<li class="node node--file">
<a href="{% url 'pad-read' mode='r' slug=pad.display_slug %}">
{{ pad.display_slug }}
{{ pad.display_slug|stripPath:folderPath|dewikify }}
{{ pad.title }}{% if pad.is_public %} (public){% endif %}
</a>
......
......@@ -2,4 +2,8 @@
<li class="node node--folder">
<a href="{% url 'manage' folder|addPath:folderPath %}">{{ folder }}</a>
<div class="node__actions">
<a href="{% url 'folder-rename' folder|addPath:folderPath %}" class="button button--rename">rename</a>
</div>
</li>
......@@ -8,6 +8,9 @@ class ContactForm(forms.Form):
subject = forms.CharField(max_length=100, label=_("Subject"))
message = forms.CharField(widget=forms.Textarea(), label=_("Message"))
class RenameFolderForm(forms.Form):
old_name = forms.CharField(label=_("Old name"), required=False)
new_name = forms.CharField(label=_("New name"), required=False)
class PadRename(forms.Form):
pk = forms.HiddenInput()
......
{% extends "base.html" %}
{% load i18n %}
{% block extra_styles %}
<link rel="stylesheet" href="{% url 'css-screen' %}" type="text/css" media="screen">
<link rel="stylesheet" href="{% url 'css-print' %}" type="text/css" media="print">
{% endblock %}
{% block title %}
<h1>{{ title }}</h1>
{% endblock %}
{% block content %}
<form action="{% url 'folder-rename' %}" method="post">
{% csrf_token %}
Old folder name: "{{ form.old_name.value }}"<br />
{{ form.old_name.as_hidden }}
{{ form.new_name }}
<input class="submit" type="submit" value="{% trans "Rename" %}" />
</form>
<legend></legend>
{% endblock %}
......@@ -12,7 +12,11 @@
</section>
<ul id="pads_list" class="manage_list">
{% for folder in folders %}
<li><a href="{% url 'manage' folder|addPath:folderPath %}">&#128448; {{ folder }}</a></li>
<li><a href="{% url 'manage' folder|addPath:folderPath %}">&#128448; {{ folder }}</a>
<section class="actions">
<a href="{% url 'folder-rename' folder|addPath:folderPath %}" class="button button--rename">rename</a>
</section>
</li>
{% endfor %}
{% for pad in tree.pads %}
<li>
......@@ -35,4 +39,4 @@
<section class="pad-list--actions">
<a href="{% url 'pad-create' folderPathString %}">+ create pad</a>
</section>
{% endblock %}
\ No newline at end of file
{% endblock %}
......@@ -17,6 +17,8 @@ urlpatterns = [
path('css-slide/', views.css_slide, name='css-slide'),
path('create/', views.padCreate, name='pad-create'),
path('create/<path:prefix>/', views.padCreate, name='pad-create'),
path('rename-folder/', views.RenameFolderView.as_view(), name='folder-rename'),
path('rename-folder/<path:prefix>/', views.RenameFolderView.as_view(), name='folder-rename'),
path('rename/<int:pk>/', views.padRename, name='pad-rename'),
path('delete/<int:pk>/', views.padDelete, name='pad-delete'),
path('public/<int:pk>/', views.padPublic, name='pad-public'),
......
......@@ -46,6 +46,11 @@ from generator.management.commands.generate import generate as generateStatic
from . import forms as ethertoffForms
from ethertoff.forms import RenameFolderForm
from django.views.generic.edit import FormView
from django.urls import reverse_lazy
# By default, the homepage is the pad called ‘start’ (props to DokuWiki!)
try:
HOME_PAD = settings.HOME_PAD
......@@ -297,6 +302,31 @@ def padRename(request, pk):
context
)
class RenameFolderView(FormView):
template_name = 'folder-rename.html'
form_class = RenameFolderForm
success_url = reverse_lazy('manage')
def get_initial(self):
"""Return the initial data to use for forms on this view."""
old_name = self.kwargs.get("prefix", "")
old_name = old_name.replace('/', settings.PAD_NAMESPACE_SEPARATOR)
old_name = old_name.strip(":") # avoids leading and trailing "::"
self.initial.update({"old_name": old_name})
self.initial.update({"new_name": old_name})
return super().get_initial()
def form_valid(self, form):
old_name = form.cleaned_data.get('old_name')
new_name = form.cleaned_data.get('new_name')
for pad in Pad.objects.filter(display_slug__startswith=old_name):
current_display_slug = pad.display_slug
new_display_slug = new_name + current_display_slug[len(old_name):]
pad.display_slug = new_display_slug
pad.save()
return super().form_valid(form)
@login_required(login_url='/etherpad')
def padPublic(request, pk):
"""Delete a given pad
......