Re: plotting queryset objects into a calendar

2007-02-12 Thread Patrick J. Anderson

On Mon, 12 Feb 2007 17:54:55 +, Patrick J. Anderson wrote:

> On Mon, 12 Feb 2007 13:06:19 +, Patrick J. Anderson wrote:
> 
>> I want to plot my milestones into a 28-week calendar using Django. What
>> would be the best approach to doing that?
>> 
>> I have the following code:
>> 
>> 
>> [dashboardcalendar.py (custom template tag)]
>> 
>> from datetime import datetime, timedelta
>> from django.template import Library,Node
>> 
>> register = Library()
>> 
>> 
>> def plot_calendar(context):
>> """
>> Plot milestones into an XHTML calendar
>> 
>> Calendar starts today and ends at the end of day range defined by days 
>> (default = 28)
>> """
>> 
>> week = [datetime.today() + timedelta(days = n) for n in range(7)]
>> week_days = [d.strftime("%A") for d in week]
>> 
>> # calendar_milestones is a list of Milestone model objects
>> # with date_close (date) attribute
>> 
>> if context.has_key('calendar_milestones'):
>> milestones = context['calendar_milestones']
>> else:
>> milestones = None
>> 
>> if not context.has_key('weeks'):
>> days = int(context['weeks']) * 7
>> else:
>> days = 28
>> 
>> dates = []
>> 
>> for n in range(days):
>> date = datetime.today() + timedelta(days=n)
>> dates.append(date)
>>
>> return {
>> 'week_days': week_days,
>> 'calendar_days': dates,
>> 'calendar_milestones': milestones,
>> }
>> 
>> register.inclusion_tag('dashboard/widgets/calendar.html', 
>>takes_context = True)(plot_calendar)
>> 
>> 
>> 
>> and my template:
>> 
>> [dashboard/widget/calendar.html (customfilters: isSunday, isFirstofMonth,
>> isOverdue)]
>> 
>> {% load customfilters %}
>> 
>> {% if week_days %}
>> 
>> > class="calendar">
>> Milestones due in the next 4 weeks
>> 
>> 
>> {% for w in week_days %}
>> {{ w }}
>> {% endfor %}   
>> 
>> 
>> 
>> 
>> {% if calendar_days %}
>>  {% for d in calendar_days %}
>>  {% if forloop.counter0|divisibleby:7 %}
>>  {% if not forloop.first %}{% endif %}
>>  {% if not forloop.last %}{% endif %}
>>  {% endif %}
>>  {% if forloop.first %}
>>  
>>  TODAY
>>  
>>  
>>  {% else %}
>>  {% if d|isSunday %}{% else %}{% endif %}
>>  {% if d|isFirstOfMonth %}> class="black">{{ d|date:"j N" }}{% else %}{{ d|date:"j" }}{% endif 
>> %}
>>  
>>  
>>  {% endif %}
>>  
>>  
>>  {% endfor %}
>> {% else %}
>>  
>>  
>>  Can't create calendar cells because 
>> I don't know the day range
>>  
>>  
>> {% endif %}
>> 
>> 
>> 
>> {% endif %}
>> 
>> 
>> {% if calendar_milestones %}
>>  
>>  {% for m in calendar_milestones %}
>>  {% if m.date_close|isOverdue %}{% else %}{% 
>> endif %}
>>  {{ m.date_close|date:"j F" }} | {{ m.name }} ({{ m.project.name 
>> }})
>>  {% endfor %}
>>  
>> {% endif %}
>> 
>> 
>> 
> Can someone look at this code and tell me if I'm on the right track here?
> 
> This is a part of my modified version of my dashboardcalendar.py inclusion
> tag I posted before, where I want to create a 2-dimensional list where
> each item contains a datetime object and possibly a list of milestones due
> on that date, which come from a Milestone queryset?
> 
> 
> # create list of datetime objects in range(days)
> 
> dates = []
> [dates.append(datetime.today() + timedelta(days=n)) for n in
> range(days)]
> 
> # create a 2-dimensional list of objects # containing a datetime
> object and any related milestones 
> 
> calendar_date_data = [] for k, v in enumerate(dates):
> d = []
> d.append(v)
> [d.append(m) for m in milestones if m.date_close == v.isoformat()]
> calendar_date_data.append(d)
> 
> return {
> ...
> 'calendar_days': calendar_date_data,
> ...
> }
> 
> 
> 
It seemed that I was on the right track, but I needed to modify a few
things to make it work. Not sure if this is the fastest way to process it,
but it does the job right now, and I'm building a prototype, so
optimisation will come later. Here are the changes I made.

[dashboardcalendar.py]
from datetime import date, timedelta
from django.template import Library,Node

register = Library()


def plot_calendar(context):
"""
Plot milestones into an XHTML calendar

Calendar starts today and ends at the end of day range defined by days 
(default = 28)
"""

week = [date.today() + timedelta(days = n) for n in range(7)]
week_days = [d.strftime("%a") for d in week]

if context.

Re: plotting queryset objects into a calendar

2007-02-12 Thread Patrick J. Anderson

On Mon, 12 Feb 2007 13:06:19 +, Patrick J. Anderson wrote:

> I want to plot my milestones into a 28-week calendar using Django. What
> would be the best approach to doing that?
> 
> I have the following code:
> 
> 
> [dashboardcalendar.py (custom template tag)]
> 
> from datetime import datetime, timedelta
> from django.template import Library,Node
> 
> register = Library()
> 
> 
> def plot_calendar(context):
> """
> Plot milestones into an XHTML calendar
> 
> Calendar starts today and ends at the end of day range defined by days 
> (default = 28)
> """
> 
> week = [datetime.today() + timedelta(days = n) for n in range(7)]
> week_days = [d.strftime("%A") for d in week]
> 
> # calendar_milestones is a list of Milestone model objects
> # with date_close (date) attribute
> 
> if context.has_key('calendar_milestones'):
> milestones = context['calendar_milestones']
> else:
> milestones = None
> 
> if not context.has_key('weeks'):
> days = int(context['weeks']) * 7
> else:
> days = 28
> 
> dates = []
> 
> for n in range(days):
> date = datetime.today() + timedelta(days=n)
> dates.append(date)
>
> return {
> 'week_days': week_days,
> 'calendar_days': dates,
> 'calendar_milestones': milestones,
> }
> 
> register.inclusion_tag('dashboard/widgets/calendar.html', 
>takes_context = True)(plot_calendar)
> 
> 
> 
> and my template:
> 
> [dashboard/widget/calendar.html (customfilters: isSunday, isFirstofMonth,
> isOverdue)]
> 
> {% load customfilters %}
> 
> {% if week_days %}
> 
>  class="calendar">
> Milestones due in the next 4 weeks
> 
> 
> {% for w in week_days %}
> {{ w }}
> {% endfor %}   
> 
> 
> 
> 
> {% if calendar_days %}
>   {% for d in calendar_days %}
>   {% if forloop.counter0|divisibleby:7 %}
>   {% if not forloop.first %}{% endif %}
>   {% if not forloop.last %}{% endif %}
>   {% endif %}
>   {% if forloop.first %}
>   
>   TODAY
>   
>   
>   {% else %}
>   {% if d|isSunday %}{% else %}{% endif %}
>   {% if d|isFirstOfMonth %} class="black">{{ d|date:"j N" }}{% else %}{{ d|date:"j" }}{% endif %}
>   
>   
>   {% endif %}
>   
>   
>   {% endfor %}
> {% else %}
>   
>   
>   Can't create calendar cells because 
> I don't know the day range
>   
>   
> {% endif %}
> 
> 
> 
> {% endif %}
> 
> 
> {% if calendar_milestones %}
>   
>   {% for m in calendar_milestones %}
>   {% if m.date_close|isOverdue %}{% else %}{% 
> endif %}
>   {{ m.date_close|date:"j F" }} | {{ m.name }} ({{ m.project.name 
> }})
>   {% endfor %}
>   
> {% endif %}
> 
> 
> 
Can someone look at this code and tell me if I'm on the right track here?

This is a part of my modified version of my dashboardcalendar.py inclusion
tag I posted before, where I want to create a 2-dimensional list where
each item contains a datetime object and possibly a list of milestones due
on that date, which come from a Milestone queryset?


# create list of datetime objects in range(days)

dates = []
[dates.append(datetime.today() + timedelta(days=n)) for n in
range(days)]

# create a 2-dimensional list of objects # containing a datetime
object and any related milestones 

calendar_date_data = [] for k, v in enumerate(dates):
d = []
d.append(v)
[d.append(m) for m in milestones if m.date_close == v.isoformat()]
calendar_date_data.append(d)

return {
...
'calendar_days': calendar_date_data,
...
}


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



plotting queryset objects into a calendar

2007-02-12 Thread Patrick J. Anderson

I want to plot my milestones into a 28-week calendar using Django. What
would be the best approach to doing that?

I have the following code:


[dashboardcalendar.py (custom template tag)]

from datetime import datetime, timedelta
from django.template import Library,Node

register = Library()


def plot_calendar(context):
"""
Plot milestones into an XHTML calendar

Calendar starts today and ends at the end of day range defined by days 
(default = 28)
"""

week = [datetime.today() + timedelta(days = n) for n in range(7)]
week_days = [d.strftime("%A") for d in week]

# calendar_milestones is a list of Milestone model objects
# with date_close (date) attribute

if context.has_key('calendar_milestones'):
milestones = context['calendar_milestones']
else:
milestones = None

if not context.has_key('weeks'):
days = int(context['weeks']) * 7
else:
days = 28

dates = []

for n in range(days):
date = datetime.today() + timedelta(days=n)
dates.append(date)
   
return {
'week_days': week_days,
'calendar_days': dates,
'calendar_milestones': milestones,
}

register.inclusion_tag('dashboard/widgets/calendar.html', 
   takes_context = True)(plot_calendar)



and my template:

[dashboard/widget/calendar.html (customfilters: isSunday, isFirstofMonth,
isOverdue)]

{% load customfilters %}

{% if week_days %}


Milestones due in the next 4 weeks


{% for w in week_days %}
{{ w }}
{% endfor %}   




{% if calendar_days %}
{% for d in calendar_days %}
{% if forloop.counter0|divisibleby:7 %}
{% if not forloop.first %}{% endif %}
{% if not forloop.last %}{% endif %}
{% endif %}
{% if forloop.first %}

TODAY


{% else %}
{% if d|isSunday %}{% else %}{% endif %}
{% if d|isFirstOfMonth %}{{ d|date:"j N" }}{% else %}{{ d|date:"j" }}{% endif %}


{% endif %}


{% endfor %}
{% else %}


Can't create calendar cells because 
I don't know the day range


{% endif %}



{% endif %}


{% if calendar_milestones %}

{% for m in calendar_milestones %}
{% if m.date_close|isOverdue %}{% else %}{% 
endif %}
{{ m.date_close|date:"j F" }} | {{ m.name }} ({{ m.project.name 
}})
{% endfor %}

{% endif %}


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---