Commits

Oben Sonne committed af3adeb

Allow bulk adding/removing of labels to/from pages

Also slightly improve manage view.

Comments (0)

Files changed (3)

app/diggie/templates/diggie/dg.css

     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 -------------------------------------------------------------------- */

app/diggie/templates/diggie/manage.html

 {% 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" />
 {% endif %}
 </div> <!-- pages -->
 
+<hr/>
+
 <div class="labels">
 <h1>Labels</h1>
 <form action="{% url diggie.views.main %}" method="POST">
 {% 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" />

app/diggie/views.py

                 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?")
 
             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.")
             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):