Example #1
0
def html(request, year=None):
    result = []
    year = int(year)
    holidays = Holiday.objects.all()
    for holiday in holidays:
        date = holiday.getDateByYear(year)
        datestring = '%s %s' % (formatmonth(date.month),
                                formatday(date.day))      
        countries = [c.name for c in holiday.country.all().order_by('name')]
        result.append(dict(name=holiday.name, rawdate=date, date=datestring, 
                           countries=', '.join(countries)))
    result = sorted(result, key=operator.itemgetter('rawdate'))
    return render_to_response('holidays.html', 
                              dict(holidays=result,
                                   thisyear=year,
                                   years=range(year-3, year+3)))
Example #2
0
        
        
class State(Model):
    name = CharField(max_length=50)
    country = ForeignKey(Country)
    
    def __unicode__(self):
        return u'<State "%s" in "%s">' % (self.name, self.country.name)

    @property
    def holidays(self):
        return Holiday.objects.all().filter(state=self)


MONTHS_CHOICES = [(0, 'Not fixed')] + [(i, formatmonth(i)) for i in range(1, 13)]
DAY_CHOICES = [(0, 'Not fixed')] + [(i, formatday(i)) for i in range(1, 32)]

class Holiday(Model):
    name = CharField(max_length=50)
    definition = CharField(max_length=100, blank=True)
    month = IntegerField(default=0, choices=MONTHS_CHOICES)
    day = IntegerField(default=0, choices=DAY_CHOICES)
    country = ManyToManyField(Country, blank=True, null=True)
    state = ManyToManyField(State, blank=True, null=True)
    
    def __unicode__(self):
        return u'<Holiday "%s">' % (self.name,)
        
    def getByCountryAndYear(self, countryName, year):    
        country = Country.objects.get(name=countryName)
        return Holiday.objects.all().filter(country=country)