Index: /main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py	(revision 7967)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py	(revision 7968)
@@ -508,2 +508,44 @@
         result.append(name)
     return result
+
+def get_sorted_preferred(tuples_iterable, preferred_list):
+    """Get a list of tuples (<TITLE>,<TOKEN>) with values in
+    `preferred_list` put in front.
+
+    The rest of the tuples iterable is returned in orginal order. This
+    is useful for putting default entries on top of (already sorted)
+    lists of choice values, for instance when sorting countries and
+    their code.
+
+    Sample:
+
+    We have a list of tuples with uppercase 'titles' and lowercase
+    'tokens'. This list is already sorted but we want certain values
+    of this list to show up before other values. For instance we want
+    to see the 'C' entry to come first.
+
+      >>> get_sorted_preferred([('A','a'), ('B','b'), ('C','c')],
+      ...                       ['c'])
+      (('C', 'c'), ('A', 'a'), ('B', 'b'))
+
+    i.e. the entry with 'c' as second value moved to head of result.
+
+    We can also require multiple entries at head of list:
+
+      >>> get_sorted_preferred([('A','a'), ('B','b'), ('C','c')],
+      ...                       ['b', 'c'])
+      (('B', 'b'), ('C', 'c'), ('A', 'a'))
+
+    We required the 'b' entry to come before the 'c' entry and then
+    the rest of the input list. That's what we got.
+
+    The result is returned as a tuple of tuples to keep order of values.
+    """
+    result = [None for x in preferred_list]
+    for title, code in tuples_iterable:
+        if code in preferred_list:
+            index = preferred_list.index(code)
+            result[index] = (title, code)
+        else:
+            result.append((title, code))
+    return tuple(result)
