cal: span events across week's days
authorTero Marttila <terom@fixme.fi>
Sat, 08 Jan 2011 23:17:16 +0200
changeset 39 4f331cfc76a4
parent 38 673475e05e3d
child 40 30a0a0fa8c54
cal: span events across week's days
static/cal.css
svv/cal.py
--- a/static/cal.css	Sat Jan 08 22:55:01 2011 +0200
+++ b/static/cal.css	Sat Jan 08 23:17:16 2011 +0200
@@ -62,10 +62,28 @@
     height: 1em;
 }
 
-/* The days are separated by borders */
+/* Each event is visible as its own block */
+table.calendar tbody tr.week-data td.event a
+{
+    display: block;
+
+    background-color: #A6C6E3;
+
+    padding: 4px;
+
+    /* Rounded corner for cosmetic effect */
+    border-radius: 4px;
+    -moz-border-radius: 6px;
+    
+    text-align: center;
+}
+
+/* Borders ? */
 table.calendar tbody td
 {
     border: 1px solid #d8d8d8;
 
     border-style: none solid;
 }
+
+
--- a/svv/cal.py	Sat Jan 08 22:55:01 2011 +0200
+++ b/svv/cal.py	Sat Jan 08 23:17:16 2011 +0200
@@ -152,16 +152,23 @@
 
         # each even on its own row for now
         for order in orders :
-            yield tags.tr(class_='week-data')(
-                (
-                    tags.td(
-                        tags.a(href=self.url_for(urls.OrderView, id=order.id))(order.event_name)
+            # start/end date for this week
+            start = min(date for date in week if order.on_date(date))
+            end = max(date for date in week if order.on_date(date))
+            
+            # as vector into week
+            leading = (start - min(week)).days
+            length = (end - start).days + 1
+            trailing = (max(week) - end).days
 
-                    ) if order.on_date(date) else (
-                        tags.td("")
+            log.debug("Event %r from %r -> %r", order.event_name, start, end)
 
-                    )
-                ) for date in week
+            yield tags.tr(class_='week-data')(
+                [tags.td("")] * leading,
+                tags.td(colspan=length, class_='event')(
+                    tags.a(href=self.url_for(urls.OrderView, id=order.id))(order.event_name)
+                ),
+                [tags.td("")] * trailing,
             )
 
     def render_calendar (self, month) :