Changeset 516

Show
Ignore:
Timestamp:
01/27/10 15:46:10 (6 weeks ago)
Author:
olivier
Message:

make the dl_field template tag more django-like

Location:
trunk/telemeta
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/telemeta/templates/telemeta_default/collection_detail.html

    r513 r516  
    4545        {% block general_info %} 
    4646            <dl class="listing"> 
    47                 {% dl_field collection.title %} 
    48                 {% dl_field collection.alt_title %} 
    49                 {% dl_field collection.creator %} 
     47                {% dl_field collection "title" %} 
     48                {% dl_field collection "alt_title" %} 
     49                {% dl_field collection "creator" %} 
    5050                {% if collection.recorded_from_year %} 
    5151                <dt>{% trans "Recording year" %}</dt> 
    5252                <dd>{{ collection.recorded_from_year }} {{ collection.recorded_to_year|prepend:" - "  }}</dd> 
    5353                {% endif %} 
    54                 {% dl_field collection.year_published %} 
     54                {% dl_field collection "year_published" %} 
    5555            </dl> 
    5656        {% endblock general_info %} 
     
    6262                <div> 
    6363                    <dl class="listing"> 
    64                     {% dl_field collection.countries join with ", " %} 
    65                     {% dl_field collection.ethnic_groups join with ", " %} 
     64                    {% dl_field collection "countries" join with ", " %} 
     65                    {% dl_field collection "ethnic_groups" join with ", " %} 
    6666                    </dl> 
    6767                </div> 
     
    7777                        {% if collection.collector_is_creator %} 
    7878                          {% if collection.creator %} 
    79                           <dt>{% trans "Collector" %}</dt><dd>{{ collector.creator }}</dd> 
     79                          <dt>{% trans "Collector" %}</dt><dd>{{ collection.creator }}</dd> 
    8080                          {% endif%} 
    8181                        {% else %} 
    82                         {% dl_field collection.collector %} 
     82                        {% dl_field collection "collector" %} 
    8383                        {% endif %} 
    84                         {% dl_field collection.publisher %} 
    85                         {% dl_field collection.publisher_collection %} 
    86                         {% dl_field collection.publisher_serial %} 
    87                         {% dl_field collection.booklet_author %} 
    88                         {% dl_field collection.external_references %} 
    89                         {% dl_field collection.doctype_code %} 
    90                         {% dl_field collection.public_access %} 
    91                         {% dl_field collection.legal_rights %} 
     84                        {% dl_field collection "publisher" %} 
     85                        {% dl_field collection "publisher_collection" %} 
     86                        {% dl_field collection "publisher_serial" %} 
     87                        {% dl_field collection "booklet_author" %} 
     88                        {% dl_field collection "external_references" %} 
     89                        {% dl_field collection "doctype_code" %} 
     90                        {% dl_field collection "public_access" %} 
     91                        {% dl_field collection "legal_rights" %} 
    9292                    </dl> 
    9393                </div> 
     
    101101                <div> 
    102102                    <dl class="listing"> 
    103                         {% dl_field collection.acquisition_mode %} 
    104                         {% dl_field collection.cnrs_contributor %} 
    105                         {% dl_field collection.metadata_writer %} 
    106                         {% dl_field collection.booklet_description %} 
    107                         {% dl_field collection.publishing_status %} 
    108                         {% dl_field collection.alt_ids %} 
    109                         {% dl_field collection.comment %} 
    110                         {% dl_field collection.metadata_writer %} 
    111                         {% dl_field collection.travail %} 
    112                         {% dl_field collection.items_done %} 
     103                        {% dl_field collection "acquisition_mode" %} 
     104                        {% dl_field collection "cnrs_contributor" %} 
     105                        {% dl_field collection "metadata_writer" %} 
     106                        {% dl_field collection "booklet_description" %} 
     107                        {% dl_field collection "publishing_status" %} 
     108                        {% dl_field collection "alt_ids" %} 
     109                        {% dl_field collection "comment" %} 
     110                        {% dl_field collection "metadata_writer" %} 
     111                        {% dl_field collection "travail" %} 
     112                        {% dl_field collection "items_done" %} 
    113113                    </dl> 
    114114                </div> 
     
    122122                <div> 
    123123                    <dl class="listing"> 
    124                         {% dl_field collection.code %} 
    125                         {% dl_field collection.old_code %} 
     124                        {% dl_field collection "code" %} 
     125                        {% dl_field collection "old_code" %} 
    126126                        <dt>{% trans "Media type" %}</dt><dd>{% trans "Audio" %}</dd> 
    127                         {% dl_field collection.approx_duration %} 
    128                         {% dl_field collection.computed_duration %} 
    129                         {% dl_field collection.physical_items_num %} 
     127                        {% dl_field collection "approx_duration" %} 
     128                        {% dl_field collection "computed_duration" %} 
     129                        {% dl_field collection "physical_items_num" %} 
    130130                        <dt>{% trans "Number of items" %}</dt><dd>{{ collection.items.count }}</dd> 
    131                         {% dl_field collection.physical_format %} 
    132                         {% dl_field collection.ad_conversion %} 
     131                        {% dl_field collection "physical_format" %} 
     132                        {% dl_field collection "ad_conversion" %} 
    133133                    </dl> 
    134134                </div> 
  • trunk/telemeta/templatetags/telemeta_utils.py

    r512 r516  
    9999 
    100100class DescriptionListFieldNode(template.Node): 
    101     def __init__(self, variable, join_with = None): 
    102         cut   = variable.split('.') 
    103         self.model  = template.Variable('.'.join(cut[:-1])) 
    104         self.member = cut[-1] 
     101    def __init__(self, model, attr, join_with = None): 
     102        self.model  = model 
     103        self.member = attr 
    105104        self.join_with = join_with 
    106105 
     
    108107        try: 
    109108            model = self.model.resolve(context) 
    110             label = html.escape(capfirst(unicode(model.field_label(self.member)))) 
     109            if isinstance(self.member, template.Variable): 
     110                member = self.member.resolve(context) 
     111            else: 
     112                member = self.member 
     113            label = html.escape(capfirst(unicode(model.field_label(member)))) 
    111114            try: 
    112                 value = getattr(model, self.member) 
     115                value = getattr(model, member) 
    113116            except AttributeError: 
    114117                value = '<ERROR: no such field>' 
     
    135138    join_with = None 
    136139    try: 
    137         tag_name, variable = cut 
     140        tag_name, model, attr = cut 
    138141    except ValueError: 
    139142        try: 
    140             tag_name, variable, arg3, arg4, arg5  = cut 
     143            tag_name, model, attr, arg3, arg4, arg5  = cut 
    141144            if arg3 == 'join' and arg4 == 'with'and arg5[0] == arg5[-1] and arg5[0] in ('"', "'"): 
    142145                join_with = arg5[1:-1] 
     
    147150                                               % token.contents.split()[0]) 
    148151 
    149     return DescriptionListFieldNode(variable, join_with=join_with) 
     152    if attr[0] == attr[-1] and attr[0] in ('"', "'"): 
     153        attr = attr[1:-1] 
     154    else: 
     155        attr = template.Variable(attr) 
     156    model = template.Variable(model) 
     157    return DescriptionListFieldNode(model, attr, join_with=join_with) 
    150158 
    151159@register.filter