Commits

Dimitris Glezos  committed 1f43651

trivial: Moved truncate template tags to txcommon app.

  • Participants
  • Parent commits fcd336d

Comments (0)

Files changed (4)

File templates/projects/component_submit_new_file.html

 {% load i18n %}
 {% load statistics %}
+{% load truncate %}
 <div class="generic_form">
 {% url component_submit_new_file component.project.slug component.slug as file_submit_url %}
 <span class="i16 add submit_button buttonized" title="{% trans "Send a new translation for this component." %}">{% trans "Add a new translation" %}</span>

File translations/templates/project_stats_table.html

 {% load i18n %}
 {% load statistics %}
+{% load truncate %}
 <table class="stats_comp">
    <thead>
     <tr>

File translations/templatetags/statistics.py

     return {'stat': stat,
             'pos': pos_from_stat(stat, width),}
 
-
-@register.filter  
-def truncate_chars(value, max_length):
-    """
-    Truncates a string after a certain number of characters.
-    """
-    if len(value) > max_length:  
-        truncd_val = value[:max_length-1]  
-        if value[max_length] != " ":  
-            truncd_val = truncd_val[:truncd_val.rfind(" ")]  
-        return  truncd_val + "..."  
-    return value  
-
-@register.filter  
-def truncate_chars_middle(value, max_length):
-    """
-    Truncate a string putting dots in the its middle after a certain number of 
-    characters.
-    """
-    value_length = len(value)
-    if value_length > max_length:
-        max_first = max_length/2
-        div_rest = max_length%2
-        truncd_val = value[:max_first-2+div_rest]
-        truncd_val2 = value[-(max_first-1):] 
-        return truncd_val + "..." + truncd_val2  
-    return value

File txcommon/templatetags/truncate.py

+"""
+Template tags to make strings shorter in various ways.
+"""
+
+from django import template
+
+register = template.Library()
+
+
+@register.filter  
+def truncate_chars(value, max_length):
+    """
+    Truncates a string after a certain number of characters.
+    """
+    max_length = int(max_length)
+    if len(value) > max_length:  
+        truncd_val = value[:max_length-1]  
+        if value[max_length] != " ":  
+            truncd_val = truncd_val[:truncd_val.rfind(" ")]  
+        return  truncd_val + "..."  
+    return value  
+
+@register.filter  
+def truncate_chars_middle(value, max_length):
+    """
+    Truncate a string putting dots in the its middle after a certain number of 
+    characters.
+    """
+    max_length = int(max_length)
+    value_length = len(value)
+    if value_length > max_length:
+        max_first = max_length/2
+        div_rest = max_length%2
+        truncd_val = value[:max_first-2+div_rest]
+        truncd_val2 = value[-(max_first-1):] 
+        return truncd_val + "..." + truncd_val2  
+    return value