Commits

p...@ph-laptop  committed d05c8be

Fri Feb 26 20:23:29 MSK 2010

  • Participants
  • Parent commits 8d2408a

Comments (0)

Files changed (5)

File example1/example.sqlite

Binary file modified.

File example1/settings.py

 
 MANAGERS = ADMINS
 
-DATABASES = {
-    'default': {
-        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
-        'NAME': 'example.sqlite',                      # Or path to database file if using sqlite3.
-        'USER': '',                      # Not used with sqlite3.
-        'PASSWORD': '',                  # Not used with sqlite3.
-        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
-        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
-    }
-}
+#DATABASES = {
+#    'default': {
+#        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+#        'NAME': 'example.sqlite',                      # Or path to database file if using sqlite3.
+#        'USER': '',                      # Not used with sqlite3.
+#        'PASSWORD': '',                  # Not used with sqlite3.
+#        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
+#        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
+#    }
+#}
+DATABASE_ENGINE='sqlite3'
+DATABASE_NAME='example.sqlite'
 
 # Local time zone for this installation. Choices can be found here:
 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name

File mpttadmin/__init__.py

         extra_fields = '&nbsp;'.join('<span title="%s">{{ node.%s }}</span>' % (field,field) for field in self.tree_display if not hasattr(self,'tree_title_field') or field!=self.tree_title_field)
         model = '%s.%s' % (self.Meta.model._meta.app_label, self.Meta.model._meta.object_name)
         self._tree_tpl = template.Template("""{% load mptt_tags %}{% full_tree_for_model """+model+""" as nodes %}{% for node,structure in nodes|tree_info %}{% if structure.new_level %}{% if node.is_child_node %}<ul>{% endif %}<li id="n{{node.pk}}">{% else %}</li><li id="n{{node.pk}}">{% endif %}<ins> </ins><a href="{{node.pk}}/">{{ node"""+title_field+""" }}</a>"""+extra_fields+"""{% for level in structure.closed_levels %}</li>{% if node.is_child_node %}</ul>{% endif %}{% endfor %}{% endfor %}""")
+        self._node_tpl = template.Template("""{% for node in nodes %}<li{% if node.is_leaf_node %}{% else %} class="closed"{% endif %} id="n{{node.pk}}"><ins> </ins><a href="{{node.pk}}/">{{ node"""+title_field+""" }}</a>"""+extra_fields+"""</li>{% endfor %}""")
         self._changelist_tpl = template.Template("""{% extends "admin/change_list.html" %}
         {% load mptt_tags %}        
         {% block extrahead %}
 		    'creatable'	: self.has_add_permission(request),
 		    'draggable'	: self.has_change_permission(request, None),
         })
+        root = self._node_tpl.render(template.Context({
+                'nodes':self.Meta.model.tree.root_nodes()
+            }))
 
         context = {
             'module_name': module_name,
             'has_add_permission': self.has_add_permission(request),
             'root_path': self.admin_site.root_path,
             'app_label': app_label,
-            'tree':self._tree_tpl.render(template.Context()),
+            #'tree':self._tree_tpl.render(template.Context()),
+            'tree':root,
             'permissions': permissions,
-            'parent_attr': self._meta.parent_attr,
+            'parent_attr': self.Meta.model._meta.parent_attr,
         }
         context.update(extra_context or {})
         context_instance = template.RequestContext(request, current_app=self.admin_site.name)
         return my_urls + urls
 
     def get_tree(self,request):
-        return HttpResponse(self._tree_tpl.render(template.Context()))
+        if 'id' in request.POST:
+            if int(request.POST['id']):
+                node = get_object_or_404(self.Meta.model,pk=request.POST['id'])
+                nodes = node.get_children()
+            else:
+                nodes = self.Meta.model.tree.root_nodes()
+            c = template.Context({'nodes':nodes})
+            return HttpResponse(self._node_tpl.render(c))
+        else:
+            print 'tree'
+            return HttpResponse(self._tree_tpl.render(template.Context()))
 
     def move_node(self,request):
         if not self.has_change_permission(request, None):

File mpttadmin/media/js/jstree_admin.js

                 ondblclk: function(node, treeobj) {
                     location.href = $(node).attr('id').replace('n','');
                 },
-                onload: function(treeobj) {
+                /*onload: function(treeobj) {
                     treeobj.open_all();
-                },
+                },*/
                 onrename: function(node, treeobj, RB) {
                     var new_name=$(node).children('a:first').text();//.replace(/^\s\s*/, '');
                     treeobj._params={node:node.id.replace('n',''),name:new_name};
 		    n.addClass('search');
 		},
                 ondata: function(data, treeobj) {
-                    if(typeof(treeobj._params)!='undefined'){
-                    treeobj._params={};
+                    treeobj.settings.data.async=true;
                     treeobj.settings.data.opts.url='tree/';
-                    treeobj.settings.data.opts.method='POST';}
+                    //if(typeof(treeobj._params)!='undefined'){
+                    treeobj._params=null;
+                    treeobj.settings.data.opts.url='tree/';
+                    treeobj.settings.data.opts.method='POST';
+                    //}
                     return data;
                 },
                 beforedata: function(node, treeobj) {
-                    return typeof(treeobj._params)!='undefined' && treeobj._params || {};
+                    treeobj.settings.data.async=(typeof(treeobj._params)=='undefined');
+                    return typeof(treeobj._params)!='undefined' && treeobj._params || {'id':($(node).attr('id')?$(node).attr('id').replace('n',''):0)};
                 },
                 onchange : function (node) {
                     document.location.href = $(node).children("a:eq(0)").attr("href");
             data: {
                 type: "html",async: false
             },
+            rules: {
+                multiple:false
+            },
             "types": {
                 "default": permissions
             }
 
 setup(
     name = 'mpttadmin',
-    version = '0.2',
+    version = '0.3',
     author = 'Mikhail Sakhno',
     author_email = 'pawn13@gmail.com',
     description = """jstree admin for mptt models""",