Commits

Nikolaj Sjujskij committed d009783

Split out HTML-class concatenation in separate function

Comments (0)

Files changed (2)

 app = Flask(__name__)
 
 from defaults import *
-from utils import dictify, get_tckt_title
+from utils import concatenate_dict, dictify, get_tckt_title
 
 
 def other_colour(colour):
     if today_day:
         day_classes.setdefault(today_day, []).append('today')
 
-    for day, class_list in day_classes.items():
-        day_classes[day] = ' '.join(class_list)
-
     context = {
                'devs': DEVLIST,
                'devlist': DEVS,
                'month_name': calendar.month_name[month],
                'month': month,
                'year': year if year != today.year else "",
-               'day_classes': day_classes,
+               'day_classes': concatenate_dict(day_classes),
                'opened': opened,
                'closed': closed,
                }
     reporter = DEVS.get(tckt_dict['reporter'], tckt_dict['reporter'])
     return '{0} ({1})'.format(reporter, created_on.strftime("%d.%m.%Y"))
 
+
+def concatenate_dict(listdict):
+    ''' Concatenates values in dictionary of list of strings
+
+    {'key': ['val1', 'val2', ...], ...}
+     ->
+    {'key': 'val1 val2 ...', ...}
+
+    Used for determining list of HTML classes
+    '''
+    for key, val_list in listdict.items():
+        listdict[key] = ' '.join(val_list)
+    return listdict
+
 if __name__ == "__main__":
     test = ({'key': 'val1', 'otherkey': 'otherval1'},
             {'key': 'val2', 'otherkey': 'otherval2'},