Exemplo n.º 1
0
    def get_context_data(self, request, **kwargs):
        context = super(CalendarByPeriodsView, self).get_context_data(**kwargs)
        calendar = self.object
        period_class = kwargs['period']
        try:
            date = coerce_date_dict(request.GET)
        except ValueError:
            raise Http404
        if date:
            try:
                date = datetime.datetime(**date)
            except ValueError:
                raise Http404
        else:
            date = timezone.now()
        event_list = GET_EVENTS_FUNC(request, calendar)

        local_timezone = timezone.get_current_timezone()
        period = period_class(event_list, date, tzinfo=local_timezone)

        context.update({
            'date': date,
            'period': period,
            'calendar': calendar,
            'weekday_names': weekday_names,
            'here': quote(request.get_full_path()),
        })
        return context
Exemplo n.º 2
0
def calendar_by_periods(request,
                        calendar_slug,
                        periods=None,
                        template_name="schedule/calendar_by_period.html"):
    """
    This view is for getting a calendar, but also getting periods with that
    calendar.  Which periods you get, is designated with the list periods. You
    can designate which date you the periods to be initialized to by passing
    a date in request.GET. See the template tag ``query_string_for_date``

    Context Variables

    ``date``
        This was the date that was generated from the query string.

    ``periods``
        this is a dictionary that returns the periods from the list you passed
        in.  If you passed in Month and Day, then your dictionary would look
        like this

        {
            'month': <schedule.periods.Month object>
            'day':   <schedule.periods.Day object>
        }

        So in the template to access the Day period in the context you simply
        use ``periods.day``.

    ``calendar``
        This is the Calendar that is designated by the ``calendar_slug``.

    ``weekday_names``
        This is for convenience. It returns the local names of weekedays for
        internationalization.

    """
    calendar = get_object_or_404(Calendar, slug=calendar_slug)
    date = coerce_date_dict(request.GET)
    if date:
        try:
            date = datetime.datetime(**date)
        except ValueError:
            raise Http404
    else:
        date = timezone.now()
    event_list = GET_EVENTS_FUNC(request, calendar)
    period_objects = dict([(period.__name__.lower(), period(event_list, date))
                           for period in periods])
    return render_to_response(
        template_name,
        {
            'date': date,
            'periods': period_objects,
            'calendar': calendar,
            'weekday_names': weekday_names,
            'here': quote(request.get_full_path()),
        },
        context_instance=RequestContext(request),
    )
Exemplo n.º 3
0
def calendar_by_periods_json(request, calendar_slug, periods):
    # XXX is this function name good?
    # it conforms with the standard API structure but in this case it is rather cryptic
    user = request.user
    calendar = get_object_or_404(Calendar, slug=calendar_slug)
    date = coerce_date_dict(request.GET)
    if date:
        try:
            date = datetime.datetime(**date)
        except ValueError:
            raise Http404
    else:
        date = datetime.datetime.now()
    event_list = GET_EVENTS_FUNC(request, calendar)
    period_object = periods[0](event_list, date)
    occurrences = []
    for o in period_object.occurrences:
        if period_object.classify_occurrence(o):
            occurrences.append(o)
    resp = serialize_occurrences_func(request, occurrences, user)
    return HttpResponse(resp)
Exemplo n.º 4
0
    def get_context_data(self, request, **kwargs):
        context = super(CalendarByPeriodsView, self).get_context_data(**kwargs)
        calendar = self.object
        periods = kwargs.get('periods', None)
        try:
            date = coerce_date_dict(request.GET)
        except ValueError:
            raise Http404
        if date:
            try:
                date = datetime.datetime(**date)
            except ValueError:
                raise Http404
        else:
            date = timezone.now()
        event_list = GET_EVENTS_FUNC(request, calendar)

        if 'django_timezone' in self.request.session:
            local_timezone = pytz.timezone(request.session['django_timezone'])
        else:
            local_timezone = timezone.get_default_timezone()
        period_objects = {}
        for period in periods:
            if period.__name__.lower() == 'year':
                period_objects[period.__name__.lower()] = period(
                    event_list, date, None, local_timezone)
            else:
                period_objects[period.__name__.lower()] = period(
                    event_list, date, None, None, local_timezone)

        context.update({
            'date': date,
            'periods': period_objects,
            'calendar': calendar,
            'weekday_names': weekday_names,
            'here': quote(request.get_full_path()),
        })
        return context
Exemplo n.º 5
0
def calendar_by_periods(request, calendar_slug, periods=None,
    template_name="schedule/calendar_by_period.html", extra_context=None):
    """
    This view is for getting a calendar, but also getting periods with that
    calendar.  Which periods you get, is designated with the list periods. You
    can designate which date you the periods to be initialized to by passing
    a date in request.GET. See the template tag ``query_string_for_date``

    Context Variables

    ``date``
        This was the date that was generated from the query string.

    ``periods``
        this is a dictionary that returns the periods from the list you passed
        in.  If you passed in Month and Day, then your dictionary would look
        like this

        {
            'month': <schedule.periods.Month object>
            'day':   <schedule.periods.Day object>
        }

        So in the template to access the Day period in the context you simply
        use ``periods.day``.

    ``calendar``
        This is the Calendar that is designated by the ``calendar_slug``.

    ``weekday_names``
        This is for convenience. It returns the local names of weekedays for
        internationalization.

    """
    extra_context = extra_context or {}
    calendar = get_object_or_404(Calendar, slug=calendar_slug)
    date = coerce_date_dict(request.GET)
    if date:
        try:
            date = datetime.datetime(**date)
        except ValueError:
            raise Http404
    else:
        date = datetime.datetime.now()
    event_list = GET_EVENTS_FUNC(request, calendar)

    # Apply filter if requested (filter cannot be applied to Public events
    # - i.e. events that do not have any group. They will always show up.)
    groups = request.GET.getlist('group')
    if groups:
        event_list = event_list.filter(Q(group__isnull=True) | Q(group__pk__in=groups))

    # Discard 'group' GET param and only keep period params - easier to keep
    # state this way for filtering to work in the front-end
    period_params = []
    for param in request.GET.urlencode().split('&'):
        if not param.startswith('group='):
            period_params.append(param)

    period_objects = dict([(period.__name__.lower(), period(event_list, date)) for period in periods])
    context = {
            'date': date,
            'periods': period_objects,
            'calendar': calendar,
            'weekday_names': weekday_names,
            'here':quote(request.get_full_path()),
            'title': 'Events',
            'cal_groups': CalendarGroup.objects.all(),
            'selected_groups': [int(pk) for pk in groups],
            'period_params': '&'.join(period_params),
        }
    context.update(extra_context)
    return render_to_response(template_name, context, context_instance=RequestContext(request))
Exemplo n.º 6
0
def calendar_by_periods(request,
                        calendar_slug,
                        periods=None,
                        template_name="schedule/calendar_by_period.html"):
    """
    JMY: 	this is called by all  of the clanedar views.. so i need to call it if i want to put a calendar on start a shipment...
    			it is called on the schedule/urls.py pagefor a PARTICULAR calendar (e.g., a particlar calendar_slug..) , e.g., 
    			
    			url(r'^calendar/bi_month/(?P<calendar_slug>[-\w]+)/$',                               
        			'schedule.views.calendar_by_periods',                                             
        			name="bi_month_calendar",                                                        
        			kwargs={'periods': [Month], 'template_name': 'schedule/calendar_bi_month.html'}),	
    			
    			url(r'^calendar/month/(?P<calendar_slug>[-\w]+)/$',
        	    schedule.views.calendar_by_periods',
        	    name="month_calendar",
        	    kwargs={'periods': [Month], 'template_name': 'schedule/calendar_month.html'}),
        
    INTERPRETING THE KWARGS CALL, E.G., KWARGS={'periods': [Month],zy
    BUT periods is also defined in the, e.g., calendar_bi_month.html with the ... % month_table calendar periods.month "small" % ...
       
    NOTES FROM DJANGO APP:
    This view is for getting a calendar, but also getting periods with that
    calendar.  Which periods you get, is designated with the list periods. You
    can designate which date you the periods to be initialized to by passing
    a date in request.GET. See the template tag ``query_string_for_date``

    Context Variables

    ``date``
        This was the date that was generated from the query string.

    ``periods``
        this is a dictionary that returns the periods from the list you passed
        in.  If you passed in Month and Day, then your dictionary would look
        like this

        {
            'month': <schedule.periods.Month object>
            'day':   <schedule.periods.Day object>
        }

        So in the template to access the Day period in the context you simply
        use ``periods.day``.

    ``calendar``
        This is the Calendar that is designated by the ``calendar_slug``.

    ``weekday_names``
        This is for convenience. It returns the local names of weekedays for
        internationalization.

    """
    calendar = get_object_or_404(Calendar, slug=calendar_slug)
    try:
        date = coerce_date_dict(request.GET)
    except ValueError:
        raise Http404

    if date:
        try:
            date = datetime.datetime(**date)
        except ValueError:
            raise Http404
    else:
        date = timezone.now()
    event_list = GET_EVENTS_FUNC(request, calendar)
    local_timezone = request.session.setdefault('django_timezone', 'PST')
    #HALP FIX THE TIMEZON AHHHH
    #local_timezone = request.session.setdefault('django_timezone', 'PST')
    local_timezone = pytz.timezone(local_timezone)
    period_objects = {}
    for period in periods:
        if period.__name__.lower() == 'year':
            period_objects[period.__name__.lower()] = period(
                event_list, date, None, local_timezone)
        else:
            period_objects[period.__name__.lower()] = period(
                event_list, date, None, None, local_timezone)
    return render_to_response(
        template_name,
        {
            'date': date,
            'periods': period_objects,
            'calendar': calendar,
            'weekday_names': weekday_names,
            'here': quote(request.get_full_path()),
            'local_timezone': local_timezone,
        },
        context_instance=RequestContext(request),
    )