Przeglądaj źródła

Get a random color for calendars with no color

Guillaume Ayoub 12 lat temu
rodzic
commit
423feaec2a
1 zmienionych plików z 4 dodań i 3 usunięć
  1. 4 3
      radicale/ical.py

+ 4 - 3
radicale/ical.py

@@ -27,7 +27,8 @@ Define the main classes of a collection as seen from the server.
 
 
 import os
 import os
 import posixpath
 import posixpath
-import uuid
+from uuid import uuid4
+from random import randint
 from contextlib import contextmanager
 from contextlib import contextmanager
 
 
 
 
@@ -102,7 +103,7 @@ class Item(object):
                 self.text = self.text.replace(
                 self.text = self.text.replace(
                     "\nEND:", "\nX-RADICALE-NAME:%s\nEND:" % self._name)
                     "\nEND:", "\nX-RADICALE-NAME:%s\nEND:" % self._name)
         else:
         else:
-            self._name = str(uuid.uuid4())
+            self._name = str(uuid4())
             self.text = self.text.replace(
             self.text = self.text.replace(
                 "\nEND:", "\nX-RADICALE-NAME:%s\nEND:" % self._name)
                 "\nEND:", "\nX-RADICALE-NAME:%s\nEND:" % self._name)
 
 
@@ -442,7 +443,7 @@ class Collection(object):
         """Collection color."""
         """Collection color."""
         with self.props as props:
         with self.props as props:
             if "A:calendar-color" not in props:
             if "A:calendar-color" not in props:
-                props["A:calendar-color"] = "#5ba209"
+                props["A:calendar-color"] = "#%x" % randint(0, 255 ** 3 - 1)
             return props["A:calendar-color"]
             return props["A:calendar-color"]
 
 
     @property
     @property