af3adeb8ead6 — Oben Sonne 14 years ago
Allow bulk adding/removing of labels to/from pages

Also slightly improve manage view.
M app/diggie/templates/diggie/dg.css +23 -1
@@ 217,9 217,31 @@ div.manage label.deprecated {
     color: #aaa;
 }
 
-div.manage p.ack {
+div.manage input[type="submit"] {
+	width: 5em;
+}
+
+div.manage form p.delete {
+	width: 33%;
+	float: left;
+}
+
+div.manage form p.edit {
+	width: 33%;
+    float: left;
+    text-align: center;
+}
+
+div.manage form p.ack {
+	width: 33%;
+	text-align: right;
     color: #ce5c00;
     font-weight: bold;
+    float: right;
+}
+
+div.manage h1, div.manage h2, div.manage hr {
+	clear: both;
 }
 
 /* page -------------------------------------------------------------------- */

          
M app/diggie/templates/diggie/manage.html +20 -12
@@ 28,12 28,15 @@ 
 {% endfor %}
 </ul>
 {% if pages %}
-<p class="actions">
-<input type="submit" name="pdelete" value="Delete"/>
-or
-<input type="submit" name="pdeprecate" value="Deprecate"/>
-or
-<input type="submit" name="pundeprecate" value="Undeprecate"/>
+<p class="delete">
+<input type="submit" name="pdelete" value="Delete"
+       title="Delete selected pages"/>
+</p>
+<p class="edit">
+<input type="submit" name="pledit" value="Label"
+       title="Label selected pages" />
+<input type="text" name="plnames" value="{{ plnames }}"
+       title="List labels to add (or remove, if prefixed with '-')" />
 </p>
 <p class="ack">
 <input id="id_pageack" type="checkbox" name="pack" />

          
@@ 44,6 47,8 @@ or
 {% endif %}
 </div> <!-- pages -->
 
+<hr/>
+
 <div class="labels">
 <h1>Labels</h1>
 <form action="{% url diggie.views.main %}" method="POST">

          
@@ 64,12 69,15 @@ or
 {% endfor %}
 </ul>
 {% if labels %}
-<p class="actions">
-<input type="submit" name="ldelete" value="Delete"/>
-or
-<input type="submit" name="lrename" value="Rename"/>
-to
-<input type="text" name="lname" value="{{ lname }}" />
+<p class="delete">
+<input type="submit" name="ldelete" value="Delete"
+       title="Delete selected labels"/>
+</p>
+<p class="edit">
+<input type="submit" name="lrename" value="Rename"
+       title="Rename (respectively merge) selected labels" />
+<input type="text" name="lname" value="{{ lname }}"
+       title="New label name"/>
 </p>
 <p class="ack">
 <input id="id_labelack" type="checkbox" name="lack" />

          
M app/diggie/views.py +16 -7
@@ 428,9 428,10 @@ def manage(request):
                 if x.startswith("label_id_")]
         clabels = Label.objects.filter(id__in=cids)
 
-        lname = request.POST.get("lname", "")
+        plnames = request.POST.get('plnames', "").replace(",", " ").split()
+        lname = request.POST.get('lname', "").strip()
 
-        for action in ("pdelete", "pdeprecate", "pundeprecate"):
+        for action in ("pdelete", "pledit"):
             if action in request.POST and "pack" not in request.POST:
                 rqc['errors'].append("Do you know what you are doing?")
 

          
@@ 438,6 439,11 @@ def manage(request):
             if action in request.POST and "lack" not in request.POST:
                 rqc['errors'].append("Do you know what you are doing?")
 
+        if "pledit" in request.POST:
+            for plname in plnames:
+                if not Label.validname(plname.lstrip("-")):
+                    rqc['errors'].append("Label name '%s' contains invalid characters." % plname)
+
         if "lrename" in request.POST:
             if not Label.validname(lname):
                 rqc['errors'].append("Label name contains invalid characters.")

          
@@ 446,22 452,25 @@ def manage(request):
             rqc['errors'].append("Do you really want to delete labels? "
                                  "It looks like your intention was to rename labels ...")
 
+        if plnames and "pdelete" in request.POST:
+            rqc['errors'].append("Do you really want to delete pages? "
+                                 "It looks like your intention was to change labels ...")
 
         if rqc['errors']:
             rqc['clabels'] = clabels
             rqc['cpages'] = cpages
             rqc['lname'] = lname
+            rqc['plnames'] = " ".join(plnames)
             return render_to_response('diggie/manage.html', rqc)
 
         if "pdelete" in request.POST:
             for page in cpages:
                 page.delete()
-        elif "pdeprecate" in request.POST:
+        elif "pledit" in request.POST:
             for page in cpages:
-                page.setdeprecated(True)
-        elif "pundeprecate" in request.POST:
-            for page in cpages:
-                page.setdeprecated(False)
+                anames = " ".join([l for l in plnames if l[0] != "-"])
+                rnames = " ".join([l.lstrip("-") for l in plnames if l[0] == "-"])
+                page.addremovelabels(anames=anames, rnames=rnames)
         elif "ldelete" in request.POST:
             # don't delete labels directly, but indirectly via page edits
             for page in Page.objects.filter(labels__in=clabels):