I'm working on this very problem.

The best way I have found so far is to use the rrule stuff from the 
python-dateutil package.

Given a repeat interval such as DAILY, WEEKLY, MONTHLY etc. it can 
generate all the dates that your event occurs on between two dates.

It will even generate for just "weekdays" or every other Monday etc. 
etc. It also takes care of different sized months, leap years, etc.

All you then need to do is store the parameters to the rrule in a table 
and most of the work is done.

To retrieve from the database all you need to do is find all the ones 
that occur in your month of choice, feed all the rrules into an rruleset 
and generate everything in one line by list'ing the rruleset.

Hope this helps,
Gary.

Jay Parlar wrote:
> On 3/7/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
>> Sorry, I skipped the first step in the reasoning because I thought it
>> was obvious. My bad.
>>
>> Except for events that repeat only yearly, every single one of your
>> events is going to occur at least once in any given month. The only
>> exceptions will be things like events with monthly repetition on the
>> 30th of the month and where you're considering the month of February.
>> But that case occurs infrequently enough that you can ignore it.
>>
>> So, your initial list is *every event*. Then you have a method on the
>> Event model that converts that single event + a month and year (i.e. a
>> date) into a list of events on particular dates in that month. The
>> slight improvement here is to select every event except yearly ones and
>> then treat yearly recurrences as special. Which approach is best depends
>> on how common yearly events are.
>>
>> Iterate over your set of events, calling the special method and have
>> that method return a list of (date, title) tuples, for example. Then
>> merge those lists (iterate and merge in a single list comprehension),
>> sort the list and you're ready to put them on a calendar.
>>
>> Is that clearer?
>>
> 
> Ok, my bad, I left one option out of my original model, namely
> "NoRepeat", for one-off events.
> 
> But talking this through with you has filled in the blanks. So I think
> it stands as follows:
> 
> 1) Select all events that are NoRepeat, and find the ones that are in
> the desired month.
> 2) Then do everything you said on the set of events that are not
> NoRepeat, plus my results from step 1.
> 
> Sound good?
> 
> Of course, this is a simplified model. If I want to allow all the
> features of a regular calendar app, I'll need to support custom
> repeats, like "Every second Thursday", or "Every 5 months on the
> 17th". iCal on OS X has a very nice interface for selecting these
> custom repeats, I guess I'll try and copy that.
> 
> Jay P.
> 
> > 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to