Commits

Arnaud Grausem  committed d4ad6e0

Calendar in monthly and daily views displays now activities by week

  • Participants
  • Parent commits e0f0b2d

Comments (0)

Files changed (10)

File media/css/daily.css

     line-height: 27px;
 }
 
-#daily div.day, #daily div.daygr
+#daily div.day
 {
     text-align: center;
 }

File media/css/style.css

     width: 200px;
 }
 
-div.daygr 
+div.last
 {
-    color: #DDDDDD;
+    opacity: 0.25;
 }
 
 input.error, select.error 

File templates/timesheet/includes/day/calendar.html

 {% for line in calendar.calendar %}
 <tr>
     {% for day in line.week %}
-	{% ifequal day.reference.date|date:"m" actual.date|date:"m" %}
-	    <td id="{{ day.reference }}" onclick="change_date('{{ day.reference }}','daily')" 
-    		class="{% ifequal day.reference.date actual.date %}selected{% endifequal %}">
-		{% include "timesheet/includes/day/day.html" %}
-	    </td>
-	{% else %}
-	    <td>
-		{% include "timesheet/includes/day/not_day.html" %}
-	    </td>
-	{% endifequal %}
+    <td id="{{ day.reference }}" onclick="change_date('{{ day.reference }}','daily')" 
+        class="{% ifequal day.reference.date actual.date %}selected{% endifequal %}">
+        <div class="cal_cell {% ifequal day.reference.date actual.date %}selected{% endifequal %}
+            {% ifequal day.reference.date|date:"m" actual.date|date:"m" %}actual{% else %}last{% endifequal %}">
+            <div class="day{% ifequal today.date day.reference.date %} today{% endifequal %}{% if day.time %} activity{% endif %}">
+                {{ day.reference.date|date:"j" }}
+            </div>
+        </div>
+    </td>
     {% endfor  %}
 </tr>
 {% endfor %}

File templates/timesheet/includes/day/day.html

-{% load i18n %}
-
-<div class="cal_cell {% ifequal day.reference.date actual.date %}selected{% endifequal %}">
-    <div class="day{% ifequal today.date day.reference.date %} today{% endifequal %}{% if day.time %} activity{% endif %}">
-        {{ day.reference.date|date:"j" }}
-    </div>
-</div>

File templates/timesheet/includes/day/not_day.html

-{% load i18n %}
-
-<div id="cal_cell">
-    <div class="daygr">{{ day.reference.date|date:"j" }}</div>
-</div>

File templates/timesheet/includes/month/calendar.html

 {% for line in calendar.calendar %}
 <tr>
     {% for day in line.week %}
-	{% ifequal day.reference.date|date:"m" actual.date|date:"m" %}
-	    <td id="{{ day.reference }}" onclick="change_date('{{ day.reference }}','monthly')"> 
-		{% include "timesheet/includes/month/day.html" %}
-	    </td>
-	{% else %}
-	    <td>
-		{% include "timesheet/includes/month/not_day.html" %}
-	    </td>
-	{% endifequal %}
+    <td id="{{ day.reference }}" onclick="change_date('{{ day.reference }}','monthly')"> 
+        <div class="cal_cell{% ifequal day.reference.date actual.date %} selected{% endifequal %}{% ifequal today.date day.reference.date %} today{% endifequal %} {% ifequal day.reference.date|date:"m" actual.date|date:"m" %}actual{% else %}last{% endifequal %}">
+            <div class="day">{{ day.reference.date|date:"j" }}</div>
+            <div class='hours'>
+                {% if day.time %}
+                <span id='{{ day.reference.date|date:"j" }}'>{{ day.time }}</span>
+                {% endif %}
+            </div>
+        </div>
+    </td>
     {% endfor  %}
-	    <td class="total">{{ line.total }}</td>
+    <td class="total">{{ line.total }}</td>
 </tr>
 {% endfor %}
 </tbody>

File templates/timesheet/includes/month/day.html

-{% load i18n %}
-
-<div class="cal_cell{% ifequal day.reference.date actual.date %} selected{% endifequal %}{% ifequal today.date day.reference.date %} today{% endifequal %}">
-    <div class="day">{{ day.reference.date|date:"j" }}</div>
-    <div class='hours'>
-        {% if day.time %}
-        <span id='{{ day.reference.date|date:"j" }}'>{{ day.time }}</span>
-        {% endif %}
-    </div>
-</div>

File templates/timesheet/includes/month/not_day.html

-{% load i18n %}
-
-<div id="cal_cell">
-    <div class="daygr">{{ day.reference.date|date:"j" }}</div>
-</div>

File thot/timesheet/views.py

     request.session['day'] = ref_date
     request.session['viewly'] = 'daily'
     request.session['view'] = 'day'
-    activities = Activity.objects.filter(user=request.user, date__year=year,
-        date__month=month).select_related()
+    activities = Activity.objects.filter(
+        user=request.user, 
+        date__year=year,
+        week__in=ref_date.month_weeks_range()
+    ).select_related()
     day_activities = activities.filter(date__day=day)
     tasks = Task.objects.ordered(request.user)
     calendar = ref_date.calendar()
     request.session['viewly'] = 'monthly'
     request.session['view'] = 'month'
     activities = Activity.objects.filter(
-        user=request.user, date__year=year, date__month=month
+        user=request.user, date__year=year, 
+        week__in=ref_date.month_weeks_range()
     ).select_related()
     day_activities = activities.filter(date__day=day)
     calendar = ref_date.calendar()

File thot/utils/datelib.py

             month:self.date.month,
             day:self.date.day
         }
+
+    def month_weeks_range(self):
+        """List the weeks number of a month
+        """
+        begin = datetime.date(self.date.year, self.date.month, 1)
+        is_leap = self.date.year % 400 == 0 or \
+            (self.date.year %4 == 0 and self.date.year % 100 != 0)
+        end_day = 31 if self.date.month in (1, 3, 5, 7, 8, 10, 12) \
+            else 30 if self.date.month in (2, 4, 6, 9, 11) \
+            else 29 if self.date.month == 2 and is_leap \
+            else 28
+        end = datetime.date(self.date.year, self.date.month, end_day)
+        return range(begin.isocalendar()[1], end.isocalendar()[1]+1)
     
     def dajax_dict(self):
         """