def calendar_by_periods(request, calendar_slug, periods=None, template_name="events/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': <events.periods.Month object> 'day': <events.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 = tz.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),)
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(occurrences, user) return HttpResponse(resp)
def create_or_edit_event(request, calendar_slug, event_id=None, next=None, template_name='events/create_event.html', form_class=EventForm): """ This function, if it receives a GET request or if given an invalid form in a POST request it will generate the following response Template: events/create_event.html Context Variables: form: an instance of EventForm calendar: a Calendar with id=calendar_id if this function gets a GET request with ``year``, ``month``, ``day``, ``hour``, ``minute``, and ``second`` it will auto fill the form, with the date specifed in the GET being the start and 30 minutes from that being the end. If this form receives an event_id it will edit the event with that id, if it recieves a calendar_id and it is creating a new event it will add that event to the calendar with the id calendar_id If it is given a valid form in a POST request it will redirect with one of three options, in this order # Try to find a 'next' GET variable # If the key word argument redirect is set # Lastly redirect to the event detail of the recently create event """ from .forms import EventRelationFormSet date = coerce_date_dict(request.GET) initial_data = None if date: try: start = datetime.datetime(**date) initial_data = { "start": start, "end": start + datetime.timedelta(minutes=30) } except TypeError: raise Http404 except ValueError: raise Http404 instance = None if event_id is not None: instance = get_object_or_404(Event, id=event_id) calendar = get_object_or_404(Calendar, slug=calendar_slug) form = form_class(data=request.POST or None, instance=instance, hour24=True, initial=initial_data) eventrelation_formset = None if form.is_valid(): event = form.save(commit=False) if instance is None: event.creator = request.user event.calendar = calendar eventrelation_formset = EventRelationFormSet(request.POST, instance=event) if eventrelation_formset.is_valid(): event.save() eventrelation_formset.save() next = next or reverse('event', args=[event.id]) next = get_next_url(request, next) return HttpResponseRedirect(next) next = get_next_url(request, next) return render_to_response(template_name, { "form": form, "calendar": calendar, "relation_formset": eventrelation_formset or EventRelationFormSet(instance=instance), "next": next }, context_instance=RequestContext(request))
def calendar_by_periods(request, calendar_slug, periods=None, template_name="events/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': <events.periods.Month object> 'day': <events.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 = tz.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), )