Commits

Ashutosh Singla committed f1d7f77

Fixes 346 (Item Rename allows new name to reuse existing name)

Comments (0)

Files changed (2)

MoinMoin/apps/frontend/views.py

 from MoinMoin.apps.frontend import frontend
 from MoinMoin.forms import (OptionalText, RequiredText, URL, YourOpenID, YourEmail, RequiredPassword, Checkbox,
                             InlineCheckbox, Select, Names, Tags, Natural, Hidden, MultiSelect, Enum)
-from MoinMoin.items import BaseChangeForm, Item, NonExistent
+from MoinMoin.items import BaseChangeForm, Item, NonExistent, NameNotUniqueError
 from MoinMoin.items.content import content_registry
 from MoinMoin import user, util
 from MoinMoin.constants.keys import *
         if form.validate():
             target = form['target'].value
             comment = form['comment'].value
-            item.rename(target, comment)
-            return redirect(url_for_item(target))
+            try:
+                item.rename(target, comment)
+                return redirect(url_for_item(target))
+            except NameNotUniqueError as e:
+                flash(str(e), "error")
     return render_template(item.rename_template,
                            item=item, item_name=item_name,
                            form=form,

MoinMoin/items/__init__.py

 MixedIndexEntry = namedtuple('MixedIndexEntry', 'relname meta hassubitems')
 
 
+class NameNotUniqueError(ValueError):
+    """
+    An item with the same name exists.
+    """
+
+
 class Item(object):
     """ Highlevel (not storage) Item, wraps around a storage Revision"""
     # placeholder values for registry entry properties
         """
         rename this item to item <name> (replace current name by another name in the NAME list)
         """
+        if flaskg.storage[name]:
+            raise NameNotUniqueError(L_("An item named %s already exists." % name))
         return self._rename(name, comment, action=u'RENAME')
 
     def delete(self, comment=u''):