For those interested:

### INIT ###

import datetime, time
from django.http import Http404

def trans_month(month):
   """Vertaald de locale maandweergave naar globale"""
   if month == "maa": month = "mar"
   elif month == "mei": month = "may"
   elif month == "okt": month = "oct"

   return month


def get_week_range(year=None, week=None):
   """Geeft de begin en einddatum voor een optioneel meegegeven
week"""
   if year is None:
      year= str(datetime.datetime.now().year)
   if week is None:
      week= datetime.datetime.now().strftime("%W")

   try:
      start_date = datetime.date(*time.strptime(year + '-1-' + week,
'%Y-%w-%W')[:3])
   except ValueError:
      raise Http404
   end_date = start_date + datetime.timedelta(days=7)

   return [ start_date, end_date ]


def get_month_range(year=None, month=None):
   """Geeft de begin en einddatum voor een optioneel meegegeven
week"""
   if year is None:
      year= str(datetime.datetime.now().year)
   if month is None:
      month= datetime.datetime.now().strftime("%b")
   else:
      month = trans_month(month)

   try:
      date = datetime.date(*time.strptime(year+month, '%Y%b')[:3])
   except ValueError:
      raise Http404

   first_day = date.replace(day=1)
   if first_day.month == 12:
      last_day = first_day.replace(year=first_day.year + 1, month=1)
   else:
      last_day = first_day.replace(month=first_day.month + 1)
   return [ first_day, last_day ]

### VIEW ###
def sectie_intro(request, sectie_slug):
   now = datetime.datetime.now()
   sectie = get_sectie_by_slug_or_404(sectie_slug)
   sectie_sjabloon = sectie.get_template()
   sectie_periode = sectie.get_periode()

   berichten_relevant = Bericht.objects.filter(sectie__id__exact =
sectie.id).exclude(publiceren=False).order_by('publicatiedatum')
   if(sectie_periode == 'day'):
      subtitel = "vandaag"
      lookup_kwargs = {
         'publicatiedatum__range' : (datetime.datetime.combine(now,
datetime.time.min), datetime.datetime.combine(now,
datetime.time.max)),
      }
   elif(sectie_periode == 'week'):
      subtitel = "deze week"
      range = get_week_range()
      start_date = range[0]
      end_date = range[1]
      lookup_kwargs = {'publicatiedatum__range': (start_date,
end_date)}
      if end_date >= now.date():
         lookup_kwargs['publicatiedatum__lte'] = now
   elif(sectie_periode == 'month'):
      subtitel = "deze maand"
      lookup_kwargs = {'publicatiedatum__month': now.month,
'publicatiedatum__year' : now.year}
   else:
      subtitel = "dit jaar"
      lookup_kwargs['publicatiedatum__year'] = now.year

   sectie_periodiek = sectie.periodiek_set.filter(**lookup_kwargs)
   berichten_nieuw = berichten_relevant.filter(**lookup_kwargs)
   return render_to_response(sectie_sjabloon, {
      'sectie' : sectie,
      'subtitel' : subtitel, ## voor in sjabloon achter de titel
      'sectie_periodiek' : sectie_periodiek,
      'berichten_nieuw' : berichten_nieuw,
      'kruimelprefix' : '',
      }, context_instance=RequestContext(request))


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

Reply via email to