Skip to content

Have truncatewords/2 ignore tuples (e.g. timestamp) and truncatewords/3 ... #40

Merged
merged 2 commits into from Aug 20, 2012

2 participants

@runejuhl

...ignore atoms (e.g. null or undefined).

@evanmiller

Hmm. Why is this necessary? Why are tuples being passed to truncatewords in the first place?

@runejuhl

Both tuples and atoms are passed in cb_admin. I figured that people would use truncatewords as you have done yourself, so it'd be better to have truncatewords not choke on them.
The error given was really quite unheplful, which had me baffled for a bit...

From cb_admin/src/view/model/show.html:

        {% for attr_name, attr_val in val.attributes %}
        {% ifequal "id" attr_name %}
        <td><strong><a href="{% url action="show" record_id=attr_val %}">{{ attr_val }}</a></strong></td>
        {% else %}
        {% if "_time" in attr_name %}
        <td id="{{ val.id }}-{{ attr_name }}">{{ attr_val|date:"N j, Y, P" }}</td>
        {% else %}
        <td id="{{ val.id }}-{{ attr_name }}">{{ attr_val|truncatewords:8 }}</td>
        {% endif %}
        {% endifequal %}
        {% endfor %}

Note that the above code handles time, but only when the column is named *_time. I'm using timestamp_*.

One could argue that atoms should be converted to lists and truncated, but my reasoning is that it doesn't make sense to truncate atoms. Consider truncated versions of 'this_is_a_really_important_atom' and 'this_is_totally_nonimportant' :)

@evanmiller
@runejuhl

Ok. I'll update it accordingly. I'll have a look at cb_admin as well, when I have the time.

@evanmiller evanmiller merged commit 2f8504a into erlydtl:master Aug 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.