@@ -58,13 +58,10 @@ def getbaselineexecutables():
5858 }]
5959 executables = Executable .objects .select_related ('project' )
6060 revs = Revision .objects .exclude (tag = "" ).select_related ('branch__project' )
61- maxlen = getattr (settings , 'TIMELINE_EXECUTABLE_NAME_MAX_LEN' , 20 )
6261 for rev in revs :
6362 # Add executables that correspond to each tagged revision.
6463 for exe in [e for e in executables if e .project == rev .branch .project ]:
65- exestring = str (exe )
66- if len (exestring ) > maxlen :
67- exestring = str (exe )[0 :maxlen ] + "..."
64+ exestring = get_sanitized_executable_name_for_timeline_view (exe )
6865 name = exestring + " " + rev .tag
6966 key = str (exe .id ) + "+" + str (rev .id )
7067 baseline .append ({
@@ -116,7 +113,6 @@ def getcomparisonexes():
116113 for proj in Project .objects .all ():
117114 executables = []
118115 executablekeys = []
119- maxlen = getattr (settings , 'COMPARISON_EXECUTABLE_NAME_MAX_LEN' , 20 )
120116 # add all tagged revs for any project
121117 for exe in baselines :
122118 if exe ['key' ] != "none" and exe ['executable' ].project == proj :
@@ -134,9 +130,7 @@ def getcomparisonexes():
134130 # because we already added tagged revisions
135131 if rev .tag == "" :
136132 for exe in Executable .objects .filter (project = proj ):
137- exestring = str (exe )
138- if len (exestring ) > maxlen :
139- exestring = str (exe )[0 :maxlen ] + "..."
133+ exestring = get_sanitized_executable_name_for_comparison_view (exe )
140134 name = exestring + " latest"
141135 if branch .name != 'default' :
142136 name += " in branch '" + branch .name + "'"
@@ -260,3 +254,47 @@ def get_stats_with_defaults(res):
260254 if res .q3 is not None :
261255 q3 = res .q3
262256 return q1 , q3 , val_max , val_min
257+
258+
259+ def get_sanitized_executable_name_for_timeline_view (executable ):
260+ """
261+ Return sanitized executable name which is used in the sidebar in the
262+ Timeline and Changes view.
263+
264+ If the name is longer than settings.TIMELINE_EXECUTABLE_NAME_MAX_LEN,
265+ the name will be truncated to that length and "..." appended to it.
266+
267+ :param executable: Executable object.
268+ :type executable: :class:``codespeed.models.Executable``
269+
270+ :return: ``str``
271+ """
272+ maxlen = getattr (settings , 'TIMELINE_EXECUTABLE_NAME_MAX_LEN' , 20 )
273+
274+ exestring = str (executable )
275+ if len (exestring ) > maxlen :
276+ exestring = str (executable )[0 :maxlen ] + "..."
277+
278+ return exestring
279+
280+
281+ def get_sanitized_executable_name_for_comparison_view (executable ):
282+ """
283+ Return sanitized executable name which is used in the sidebar in the
284+ comparision view.
285+
286+ If the name is longer than settings.COMPARISON_EXECUTABLE_NAME_MAX_LEN,
287+ the name will be truncated to that length and "..." appended to it.
288+
289+ :param executable: Executable object.
290+ :type executable: :class:``codespeed.models.Executable``
291+
292+ :return: ``str``
293+ """
294+ maxlen = getattr (settings , 'COMPARISON_EXECUTABLE_NAME_MAX_LEN' , 22 )
295+
296+ exestring = str (executable )
297+ if len (exestring ) > maxlen :
298+ exestring = str (executable )[0 :maxlen ] + "..."
299+
300+ return exestring
0 commit comments