Commits

Anonymous committed 60433c5

make sure we don't delete home. (nice use of macros)

Comments (0)

Files changed (4)

_design/page/views/all_pages/map.js

 function (doc) {
-    if (doc.itemType == "page" && !doc.is_spam) {
+    if (doc.itemType == "page" && (!doc.is_spam || doc.title == "Home")) {
         emit(doc.site, doc);
     }
 }

_design/page/views/spam/map.js

 function (doc) {
-    if (doc.itemType == "page" && doc.is_spam) {
-        emit(doc.site, doc);
-    }
+  // !code lib/sha256.js
+  
+  if (doc.itemType == "page" && doc.is_spam) {
+    doc.thash = hex_sha256(doc.title);
+    emit(doc.site, doc);
+  }
 }
 #
 
 from datetime import datetime
+from hashlib import sha256
 import os
 import random
 import re
             page.content = content
             page.is_spam = is_spam # flag page
             page.save()
-            redirect_url = url_for('show_page', pagename=pagename)
+            
+            if not page.is_spam and page.title != "Home":
+                redirect_url = url_for('show_page', pagename=pagename)
+            else:
+                redirect_url = url_for('show_spam', pagename=pagename)
             return redirect(redirect_url)
     
     return redirect(url_for('show_page', pagename=pagename, error=error))
     # save new flag
     page.is_spam = not page.is_spam
     page.save()
-    
-    if not page.is_spam:
+
+    if not page.is_spam and page.title != "Home":
         redirect_url = url_for('show_page', pagename=pagename)
     else:
         redirect_url = url_for('show_spam', pagename=pagename)
     pages = request.values.getlist('d')
     docs = []
     for p in pages:
-        docid, rev = p.split('_')
-        docs.append({'_id': docid, '_rev': rev})
+        thash, docid, rev = p.split('_')
+        if thash != sha256("Home").hexdigest(): # make sure we don't delete home
+            docs.append({'_id': docid, '_rev': rev})
     db.bulk_delete(docs)    
     return redirect(url_for('site_spam'))
     

templates/site/spam.html

     <table class="historyTable">
         {% for page  in spam %}
             <tr>
-                <td><input type="checkbox" class="c" name="d" value="{{ page._id }}_{{page._rev}}" /></td>
+                {% if page.title != "Home" %}
+                    <td><input type="checkbox" class="c" name="d" value="{{ page.thash }}_{{ page._id }}_{{page._rev}}" /></td>
+                {% else %}
+                    <td></td>
+                {% endif %}
+                
                 <td><a href="{{ url_for('show_page', cname=site.cname, pagename=page.title|replace(" ", "_")) }}">{{ page.title }}</a></td>
                 <td><time title="GMT" datetime="{{ page.updated|rfc3339 }}">{{ page.updated|formatdatetime }}</time></td>
                 <td class="changes">