Re: Looking at objects by year, month

2008-05-11 Thread Ryan Vanasse

I ended up using the "divisibleby" filter and that worked out fine.
Thank you for both of your ideas!
I learn so much through this group.

Thank you very much.

Ryan Vanasse

On May 2, 9:27 pm, Pawel Pilitowski <[EMAIL PROTECTED]>
wrote:
> Maybe something like this would help:
>
> in the month loop:
>
> {% if forloop.counter|divisibleby:"2" %}
> 
> {% else %}
> 
> {% endif %}
>
> or try forloop.parentloop.counter if you need to get at it from you
> event loop.
>
> Cheers,
>
> Pawel
>
> On 03/05/2008, at 11:15 AM, Darryl Ross wrote:
>
> RyanVanassewrote:
> > Now, my problem is that for every month, I want a different color of
> > image text...
> >  //blue/orange swap
> > so that on even months i'd have them come from the blue folder and odd
> > months they'd come from the orange folder (or something of that
> > nature). As far as I can tell, none of the default equality comparison
> > tags (if,ifequal, ifchanged?) would be able to select based on odd/
> > even. Count wouldn't work, I think, because it would change for each
> > individual event, instead of monthly.
>
> My first thought was {%cycle%}, but as you said, that would alternate
> for every event, even if one month had multiple events.
>
> What should work instead is to add a property to your Event model,
> which returns a boolean value based on if the month number is odd or
> even, and then you can use the standard if/else tag:
>
>class Event(models.Model):
>  # ...
>  @property
>  def month_is_even(self):
>  return self.start_DateTime.month % 2 and False or True
>
> 
>
> That code is of course making the assumption that start_DateTime can
> never be Null, or you're likely to end up with an exception:
> "NullType has no property month"
>
> Cheers
> Darryl
>
> --
>
> Darryl Ross, VK5FUNE
> Director, AFOYI, "Information Technology Solutions"
> p +61 8 7127 1831
> f +61 8 8425 9607
> e [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Looking at objects by year, month

2008-05-02 Thread Pawel Pilitowski

Maybe something like this would help:

in the month loop:

{% if forloop.counter|divisibleby:"2" %}

{% else %}

{% endif %}

or try forloop.parentloop.counter if you need to get at it from you  
event loop.

Cheers,

Pawel



On 03/05/2008, at 11:15 AM, Darryl Ross wrote:

Ryan Vanasse wrote:
> Now, my problem is that for every month, I want a different color of
> image text...
>  //blue/orange swap
> so that on even months i'd have them come from the blue folder and odd
> months they'd come from the orange folder (or something of that
> nature). As far as I can tell, none of the default equality comparison
> tags (if,ifequal, ifchanged?) would be able to select based on odd/
> even. Count wouldn't work, I think, because it would change for each
> individual event, instead of monthly.

My first thought was {%cycle%}, but as you said, that would alternate  
for every event, even if one month had multiple events.

What should work instead is to add a property to your Event model,  
which returns a boolean value based on if the month number is odd or  
even, and then you can use the standard if/else tag:

   class Event(models.Model):
 # ...
 @property
 def month_is_even(self):
 return self.start_DateTime.month % 2 and False or True




That code is of course making the assumption that start_DateTime can  
never be Null, or you're likely to end up with an exception:  
"NullType has no property month"

Cheers
Darryl

-- 

Darryl Ross, VK5FUNE
Director, AFOYI, "Information Technology Solutions"
p +61 8 7127 1831
f +61 8 8425 9607
e [EMAIL PROTECTED]



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Looking at objects by year, month

2008-05-02 Thread Darryl Ross

Ryan Vanasse wrote:

Now, my problem is that for every month, I want a different color of
image text...
 //blue/orange swap

so that on even months i'd have them come from the blue folder and odd
months they'd come from the orange folder (or something of that
nature). As far as I can tell, none of the default equality comparison
tags (if,ifequal, ifchanged?) would be able to select based on odd/
even. Count wouldn't work, I think, because it would change for each
individual event, instead of monthly.


My first thought was {%cycle%}, but as you said, that would alternate 
for every event, even if one month had multiple events.


What should work instead is to add a property to your Event model, which 
returns a boolean value based on if the month number is odd or even, and 
then you can use the standard if/else tag:


  class Event(models.Model):
# ...
@property
def month_is_even(self):
return self.start_DateTime.month % 2 and False or True




That code is of course making the assumption that start_DateTime can 
never be Null, or you're likely to end up with an exception: "NullType 
has no property month"


Cheers
Darryl

--

Darryl Ross, VK5FUNE
Director, AFOYI, "Information Technology Solutions"
p +61 8 7127 1831
f +61 8 8425 9607
e [EMAIL PROTECTED]



signature.asc
Description: OpenPGP digital signature


Re: Looking at objects by year, month

2008-05-02 Thread Ryan Vanasse

I got my data to populate mostly alright.
The key was changing the template example to "{% for month in
months.values %}"
it wasn't working before that.

Now, my problem is that for every month, I want a different color of
image text...
 //blue/orange swap

so that on even months i'd have them come from the blue folder and odd
months they'd come from the orange folder (or something of that
nature). As far as I can tell, none of the default equality comparison
tags (if,ifequal, ifchanged?) would be able to select based on odd/
even. Count wouldn't work, I think, because it would change for each
individual event, instead of monthly.

So I'd be stuck with writing my own template tags, which I may do
eventually, but I'll probably leave for the meantime.

if anyone has suggestions for how to accomplish the alternate months
thing, I'd be much obliged.

Thank you Darryl, for your help on this. I was thankful that someone
else was having the same problem.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Looking at objects by year, month

2008-05-01 Thread Ryan Vanasse

Is events in:
for event in Event.objects.order_by('start_DateTime'):
   events[event.start_DateTime.month]['events'].append(event)

supposed to be months? (looks like months[event.start_DateTime.month]
['events'].append(event)

I get a NameError if I leave it as is. when I switch to months it
doesn't pop an exception (though I'm still working on making it show
my data.)

Ryan
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Looking at objects by year, month

2008-04-28 Thread Darryl Ross

Ryan Vanasse wrote:

Trying to get the outer for loop working is something that I don't
really understand. I think that what I have now isn't going to work
because I'm using a dictionary reference on what was transmuted into
the Context, so that "eventsByMonth" doesn't exist...


I've been trying to work out if it would be possible to do this using 
the ORM to order the events by month, ignoring the day and year, and 
then the regroup tag in the template, but I can't get it to work in the 
shell. The issue is the ORM (even post-qsrf) doesn't seem to like 
.order_by('day__month'). It is possible to do at the SQL level, eg, 
using DATE_PART for PostgreSQL, but I don't know what support in the 
different databases is like.


Anyway, one way I came up with to do it, which works but isn't 
particularly "pretty", would be something like:


  def UpcomingEvents(request)
  months = { 1:  {'name': 'January',   'events': []},
 2:  {'name': 'February',  'events': []},
 3:  {'name': 'March', 'events': []},
 4:  {'name': 'April', 'events': []},
 5:  {'name': 'May',   'events': []},
 6:  {'name': 'June',  'events': []},
 7:  {'name': 'July',  'events': []},
 8:  {'name': 'August','events': []},
 9:  {'name': 'September', 'events': []},
 10: {'name': 'October',   'events': []},
 11: {'name': 'November',  'events': []},
 12: {'name': 'December',  'events': []}
   }
  for event in Event.objects.order_by('start_DateTime'):
  events[event.start_DateTime.month]['events'].append(event)
  return render_to_response('calendar.html', {'months': months})

Assuming you want the events under each month to be ordered 
chronologically, then the order_by('start_DateTime') is still important. 
Then in the template you should be able to do something like:


   {% for month in months %}
{{month.name}}

   {% for event in month.events %}
{{event.eventName}}
   {% endfor %}

   {% endfor %}

Hope that gives you a pointer.

Cheers
Darryl



signature.asc
Description: OpenPGP digital signature


Looking at objects by year, month

2008-04-28 Thread Ryan Vanasse

Hello.

Thank you for your helpfulness and friendliness on this group. I have
found it very helpful in getting me past some of the rough spots in
starting out with django.

I'm creating a calendar of events. I want to show an entire year's
worth of events, but group them on the page into months. For an
example (but only for three months, not an entire year), see "http://
rdvanasse.nwc.edu/theremnant/calendar/index.html".

I have two questions with this. The first regards my view. Naturally,
I would wish to take advantage of the archive_year generic view,
however, I cannot see how this would allow for grouping by month on
the page. Is this possible?


Currently, my view looks something like this:

def upcomingEvents(request):
janEvents = Event.objects.filter(start_DateTime__month = 1)
   ...repeat for each month...

   eventsByMonth = {'january':janEvents, [repeat for month] }

   return render_to_response('calendar.html', eventsByMonth)

Is this the only way to handle something like this?

Secondly, in my template, I want to reproduce my month grouping div
for each month, and within each month, I want to create a new table
row for the events in that month.
Right now, I have something like this:
{% for month in eventsByMonth.values %}




{% for Event in month %}





{{Event.eventName}} {{Event.eventDetails|truncatewords:"8"}}


{% endfor %}



{% endfor %}

Earlier I had hardcoded each month into my template and made it {% for
Event in january %} (for example). This worked fine.

Trying to get the outer for loop working is something that I don't
really understand. I think that what I have now isn't going to work
because I'm using a dictionary reference on what was transmuted into
the Context, so that "eventsByMonth" doesn't exist...

But then is there a way to iterate through all dictionary references
in the entire context you've passed the template? That's what I think
would satisfy my requirements.

a final thought on that...say I did get that going...would there be a
way to insert the key (i.e. 'january'...see the eventsByMonth in my
view above) in the image source where I presently have {{ month }}?

I'm sorry for thinking about things in such convoluted ways. I'm
trying to keep things simpler, but it is a learning process. Thanks
for your time.

Ryan Vanasse


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---