Commits

Benoit Chesneau  committed b505418

manage page deletion.

  • Participants
  • Parent commits 1aa68e1

Comments (0)

Files changed (5)

File couchit/urls.py

     'home': views.home,
     'show_page': views.show_page,
     'edit_page': views.edit_page,
+    'delete_page': views.delete_page,
     'history_page': views.history_page,
     'revision_page': views.revision_page,
     'diff_page': views.diff_page,
     Rule('/<pagename>/revision/<nb_revision>', endpoint='revision_page'),
     Rule('/<pagename>/history', endpoint='history_page'),
     Rule('/<pagename>/edit', endpoint='edit_page'),
+    Rule('/<pagename>/delete', endpoint='delete_page'),
     Rule('/<pagename>/diff', endpoint='diff_page'),
     Rule('/', defaults={'pagename': 'home' }, endpoint='show_page'),
     Rule('/<pagename>', endpoint='show_page')

File couchit/views.py

     
     return render_response('page/show.html', page=page, pages=pages, lexers=LEXERS_CHOICE)
 
-def edit_page(request=None, pagename=None):
+def edit_page(request, pagename=None):
     if pagename is None:
         pagename ='Home'
     
     
     return render_response('page/edit.html', page=page)
   
-  
+def delete_page(request, pagename):
+    if pagename == 'Home': #security reason
+        return redirect(url_for('show_page', pagename='Home'))
+    
+    page = get_page(local.db, request.site.id, pagename)
+    if not page or page.id is None:
+        raise NotFound
+    
+    del local.db[page.id]
+    
+    if local.site_url:
+        redirect_url = local.site_url
+    else:
+        redirect_url = '/'
+    return redirect(redirect_url)
+    
+
 def history_page(request=None, pagename=None):
     if pagename is None:
         pagename ='Home'

File static/css/src/layout.css

     padding-left: 20px;
 }
 
-.page_delete {
+#page_delete {
 
     background: transparent url(../../img/icon_delete.png) 0 0 no-repeat;
     padding-left: 20px;

File static/js/src/page.js

             Event.stop(e);
             self.tabs.setActiveTab("pview");
             return false;
-        })
+        });
+        
+        var page_delete = $('page_delete');
+        
+        if (page_delete)
+            page_delete.observe('click', function(e) {
+                Event.stop(e);
+                var y = window.confirm("Are you sure you want to delete this page?\n\n"+
+                    "Click OK to continue, or click Cancel to stay on this page.");
+                if (!y) {
+                    return false;
+                }
+                document.location.href=this.href;
+            }, false);
         
     },
     

File templates/page/show.html

             <h2>{{ page.title }}</h2>
             <ul class="page_infos">
                 <li><time title="GMT" datetime="{{ page.updated|rfc3339 }}">{{ page.updated|formatdatetime }}</time></li>
+                {% if page.title != "Home" %}
+                <li><a id="page_delete" href="{{ url_for('delete_page', pagename=page.title|replace(" ", "_")) }}">delete</a></li>   
+                {% endif %}
                 <li class="last"><a class="page_history" href="{{ url_for('show_page', pagename=page.title|replace(" ", "_")) }}/history">history</a></li>
             </ul>
         </header>