1

I need to use a calendar. I'm developing a website for house's rental, my first own web project, so, the idea is that the user selects an initial date and finish date, in the same month or any months (from January until April for example), and in the view (template) of the housing availability.

I want to show all months (12) and where is busy the house I'll show the days with some different color.

I'm searching and testing for Django calendar, but if somebody knows about it, please give me a hand :)

Thanks :)

3 Answers 3

3

Did you take a look at Django Schedule and Django SwingTime ?

0
3

Take a look at some of the calendar related exapmles here to see if they work for you:

Also, you might consider using Python's HTMLCalendar as discussed here:

2

Here it is an example of overiding HTMLCalendar to display a queryset:

class QuerysetCalendar(HTMLCalendar):

    def __init__(self, queryset, field):
        self.field = field
        super(QuerysetCalendar, self).__init__()
        self.queryset_by_date = self.group_by_day(queryset)

    def formatday(self, day, weekday):
        if day != 0:
            cssclass = self.cssclasses[weekday]
            if date.today() == date(self.year, self.month, day):
                cssclass += ' today'
            if day in self.queryset_by_date:
                cssclass += ' filled'
                body = ['<ul>']

                for item in self.queryset_by_date[day]:
                    body.append('<li>')
                    body.append('<a href="%s">' % item.get_absolute_url())
                    body.append(esc(item))
                    body.append('</a></li>')
                body.append('</ul>')
                return self.day_cell(cssclass, '%d %s' % (day, ''.join(body)))
            return self.day_cell(cssclass, day)
        return self.day_cell('noday', ' ')


    def formatmonth(self, year, month):
        self.year, self.month = year, month
        return super(QuerysetCalendar, self).formatmonth(year, month)

    def group_by_day(self, queryset):
        field = lambda item: getattr(item, self.field).day
        return dict(
            [(day, list(items)) for day, items in groupby(queryset, field)]
        )

    def day_cell(self, cssclass, body):
        return '<td class="%s">%s</td>' % (cssclass, body)
1
  • 3
    So where is this called from? Not the template because it cannot do python code. The view? Could be, but all this formatting seems a bad idea for the view. A custom templatetag you have? In any event, you should be clear how you think this should be used.
    – hughdbrown
    Aug 17, 2009 at 16:13

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.