Esempio n. 1
0
def get_month_data(year, month, plan_view):
    year, month = normalize_month(year, month)
    month_data = get_month(year, month)
    # prev/next month
    previous = get_previous_month(year, month)
    next = get_next_month(year, month)
    # get day list
    dates = calendar.Calendar().itermonthdates(year, month)
    day_dict, count_dict = models.get_days_for_month(month_data['url'])
    days = []
    today = datetime.date.today()
    for date in dates:
        if date.month == month and date.weekday() < 5:
            day = {'weekday': day_name[date.weekday()],
                    'day': date.day,
                    'child': None}
            if day_dict.has_key(date.day):
                day['child'] = day_dict[date.day].child
                day['menu'] = day_dict[date.day].menu or ''
                day['menulink'] = '+' if day['menu'] else '?'
            day['rowclass'] = 'odd' if date.isocalendar()[1] % 2 else 'even'
            day['cellclass'] =  'today' if date == today else ''
            days.append(day)
    # get childlist
    childlist = models.get_current_children()
    children = [{'key': child.key(),
                 'id': child.key().id(),
                 'name': child.name,
                 'count': count_dict.get(child.key().id(), 0),
             } for idx, child in enumerate(childlist)]
    form = forms.ChildSelector(days, children) if plan_view else forms.MenuForm()
    return dict(days=days, month=month_data, previous=previous, next=next,
                form=form, children=children)
Esempio n. 2
0
def store_month(request, year, month):
    year, month = normalize_month(year, month)
    month_key = format_month(year, month)
    day_dict, count_dict = models.get_days_for_month(month_key)
    days = calendar.Calendar().itermonthdays(year, month)
    for day in days:
        if day > 0 and request.has_key(str(day)):
            child_key = request[str(day)]
            child = models.Child.get(child_key) if child_key else None
            # logging.info("Creating day: %d %s %s", day, month_key, child)
            if day_dict.has_key(day):
                item = day_dict[day]
                item.child = child
            else:
                item = models.Day(month=month_key, day=day, child=child)
            item.put()