Django

Code

Changeset 765

Show
Ignore:
Timestamp:
10/02/05 12:55:03 (3 years ago)
Author:
rjwittams
Message:

Merge to r764. Fix 684, also allow overloading indivual fields templates in the admin.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/new-admin/django/core/defaulttags.py

    r741 r765  
    229229 
    230230class IncludeNode(template.Node): 
    231     def __init__(self, template_path): 
     231    def __init__(self, template_path_var): 
    232232        self.template_path_var = template_path_var 
    233233 
    234234    def render(self, context): 
    235235         try: 
    236              template_path = template.resolve(self.template_path_var, context) 
     236             template_path = template.resolve_variable(self.template_path_var, context) 
     237             print "IncludeNode rendering %s" % template_path  
    237238             t = template_loader.get_template(template_path) 
    238239             return t.render(context) 
    239          except: 
     240         except Exception, e: 
     241             print e 
    240242             return '' # Fail silently for invalid included templates. 
    241243 
  • django/branches/new-admin/django/core/meta/__init__.py

    r748 r765  
    10361036    this_id = getattr(self, self._meta.pk.column) 
    10371037    cursor = db.db.cursor() 
    1038     cursor.execute("DELETE FROM %s WHERE %s_id = %%s" % (m2m_table, rel.object_name.lower()), [this_id]) 
    1039     sql = "INSERT INTO %s (%s_id, %s_id) VALUES (%%s, %%s)" % (m2m_table, rel.object_name.lower(), rel_opts.object_name.lower()) 
    1040     cursor.executemany(sql, [(this_id, i) for i in id_list]) 
     1038    delete_stmt = "DELETE FROM %s WHERE %s_id = %%s" % (m2m_table, rel.object_name.lower()) 
     1039    cursor.execute(delete_stmt, [this_id]) 
     1040    insert_stmt = "INSERT INTO %s (%s, %s) VALUES (%%s, %%s)" % (m2m_table, rel.pk.column, rel_opts.pk.column) 
     1041    cursor.executemany(insert_stmt, [(this_id, i) for i in id_list]) 
    10411042    db.db.commit() 
    10421043 
     
    14891490    return man 
    14901491 
    1491 def manipulator_init(opts, add, change, self, obj_key=None): 
     1492def manipulator_init(opts, add, change, self, obj_key=None, follow=None): 
    14921493    if change: 
    14931494        assert obj_key is not None, "ChangeManipulator.__init__() must be passed obj_key parameter." 
  • django/branches/new-admin/django/templatetags/admin_modify.py

    r741 r765  
    88from django.views.admin.main import AdminBoundField 
    99import re 
     10 
     11word_re = re.compile('[A-Z][a-z]+') 
     12 
     13def class_name_to_underscored(name): 
     14    return '_'.join([ s.lower() for s in word_re.findall(name)[:-1] ]) 
     15 
    1016 
    1117class IncludeAdminScriptNode(template.Node): 
     
    4450        context.pop()  
    4551        return output; 
    46 #         t = ['<div class="submit-row">'] 
    47            
    48 #         if not is_popup: 
    49 #               if has_delete_permission and (change or show_delete): 
    50 #                  t.append('<p class="float-left"><a href="delete/" class="deletelink">Delete</a></p>') 
    51 #               if change and save_as: 
    52 #                  t.append('<input type="submit" value="Save as new" name="_saveasnew" %s/>' %  onclick_attrib) 
    53 #                if (not save_as or add): 
    54 #                  t.append('<input type="submit" value="Save and add another" name="_addanother" %s/>' %  onclick_attrib) 
    55 #               t.append('<input type="submit" value="Save and continue editing" name="_continue" %s/>' %  onclick_attrib ) 
    56 #         t.append('<input type="submit" value="Save" class="default" %s/>' %  onclick_attrib) 
    57 #         t.append('</div>\n') 
    58           
    59 #         return ''.join(t) 
    60  
    61  
    62  
    6352 
    6453class AdminFieldBoundNode(template.Node): 
     
    10493 
    10594    def render(self, context): 
     95     
    10696        bound_field = template.resolve_variable(self.bound_field_var, context) 
    10797        add = context['add'] 
     
    110100        context.push() 
    111101        context['bound_field'] = bound_field 
    112         t = template_loader.get_template("admin_field_widget") 
    113         output =  t.render(context) 
     102        klass = bound_field.field.__class__ 
     103        t = None 
     104        while klass: 
     105            try:  
     106                field_class_name = klass.__name__ 
     107                template_name = "widget/%s" % \ 
     108                    class_name_to_underscored(field_class_name) 
     109             
     110                t = template_loader.get_template(template_name) 
     111                break 
     112            except template.TemplateDoesNotExist:  
     113                klass = (len(klass.__bases__) > 0) and klass.__bases__[0] or None 
     114         
     115        if t == None: 
     116            t = template_loader.get_template("widget/default") 
     117        
     118        output = t.render(context) 
    114119        context.pop() 
    115            
    116120        return output 
    117  
    118          
    119121 
    120122class FieldWrapper(object): 
     
    260262] 
    261263 
    262 word = re.compile('[A-Z][a-z]+') 
     264 
    263265def register_one_arg_tag(node): 
    264     tag_name = '_'.join([ s.lower() for s in word.findall(node.__name__)[:-1] ]
     266    tag_name = class_name_to_underscored(node.__name__
    265267    parse_func = curry(do_one_arg_tag, node) 
    266268    template.register_tag(tag_name, parse_func)