changeset 2267:9c177f0ba6c3

Added fqname support to rename view.
author Ashutosh Singla <ashu1461@gmail.com>
date Wed, 11 Sep 2013 22:59:20 +0530
parents dea5f965ae8b
children 9ad7a108b511
files MoinMoin/apps/frontend/views.py MoinMoin/items/__init__.py
diffstat 2 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Wed Sep 11 19:25:24 2013 +0530
+++ b/MoinMoin/apps/frontend/views.py	Wed Sep 11 22:59:20 2013 +0530
@@ -57,7 +57,7 @@
 from MoinMoin.constants.itemtypes import ITEMTYPE_DEFAULT
 from MoinMoin.constants.chartypes import CHARS_UPPER, CHARS_LOWER
 from MoinMoin.util import crypto
-from MoinMoin.util.interwiki import url_for_item, split_fqname
+from MoinMoin.util.interwiki import url_for_item, split_fqname, CompositeName
 from MoinMoin.search import SearchForm
 from MoinMoin.search.analyzers import item_name_analyzer
 from MoinMoin.security.textcha import TextCha, TextChaizedForm
@@ -601,7 +601,7 @@
         item = Item.create(item_name)
     except AccessDenied:
         abort(403)
-    if not flaskg.user.may.write(item_name):
+    if not flaskg.user.may.write(item.fqname):
         abort(403)
     if isinstance(item, NonExistent):
         abort(404, item_name)
@@ -616,12 +616,14 @@
             target = form['target'].value
             comment = form['comment'].value
             try:
+                fqname = CompositeName(item.fqname.namespace, item.fqname.field, target)
                 item.rename(target, comment)
-                return redirect(url_for_item(target))
+                return redirect(url_for_item(fqname))
             except NameNotUniqueError as e:
                 flash(str(e), "error")
     return render_template(item.rename_template,
                            item=item, item_name=item_name,
+                           fqname=item.fqname,
                            form=form,
     )
 
--- a/MoinMoin/items/__init__.py	Wed Sep 11 19:25:24 2013 +0530
+++ b/MoinMoin/items/__init__.py	Wed Sep 11 22:59:20 2013 +0530
@@ -416,7 +416,8 @@
                         child_newname = None
                     else:  # rename
                         child_newname = new_prefix + child_oldname[old_prefixlen:]
-                    item = Item.create(child_oldname)
+                    old_fqname = CompositeName(self.fqname.namespace, self.fqname.field, child_oldname)
+                    item = Item.create(old_fqname.fullname)
                     item._save(item.meta, item.content.data,
                                name=child_newname, action=action, comment=comment, delete=delete)
 
@@ -424,8 +425,9 @@
         """
         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))
+        fqname = CompositeName(self.fqname.namespace, self.fqname.field, name)
+        if flaskg.storage.get_item(**fqname.query):
+            raise NameNotUniqueError(L_("An item named %s already exists in the namespace %s." % (name, fqname.namespace)))
         return self._rename(name, comment, action=u'RENAME')
 
     def delete(self, comment=u''):