def single_time_event_type_list(request, event_type_id_string, year, month, day, start_hour_string, end_hour_string): event_type_list = utils.get_event_type_list(event_type_id_string, current_topic=get_current_topic(request)) date_day = utils.construct_day(year, month, day) start_time = utils.construct_time(date_day, utils.construct_hour(start_hour_string)) end_time = utils.construct_time(date_day, utils.construct_hour(end_hour_string)) return _get_events(request, event_type_list, start_time, end_time)
def _get_events(request, event_type_list, start_time, end_time): # TODO: investigate this: some buggs probably due to cache Site.objects.clear_cache() current_site = Site.objects.get_current() Site.objects.clear_cache() topic = get_current_topic(request) title = ' - '.join([event.label for event in event_type_list]) template = 'topic/sorted_events.html' sorted_occurrences = dict() for event_type in event_type_list: occurrences = Occurrence.objects.filter(event__event_type__topic=topic, event__site=current_site, event__event_type=event_type, start_time__gte=start_time, end_time__lte=end_time) sorted_occurrences[event_type] = occurrences context = dict({'sorted_occurrences': sorted_occurrences, 'days': utils.list_days(start_time, end_time), 'title': title }) return render(request, template, context)
def daily_events(request, year, month, day): event_type_list = EventType.objects.filter(topic=get_current_topic(request)) date_day = utils.construct_day(year, month, day) start_time = utils.construct_time(date_day, time.min) end_time = utils.construct_time(date_day, time.max) return _get_events(request, event_type_list, start_time, end_time)
def event_type_coming_days(request, event_type_id_string): event_type_list = utils.get_event_type_list( event_type_id_string, current_topic=get_current_topic(request)) start_time = datetime.now() end_time = utils.end_of_next_days(duration=3) return _get_events(request, event_type_list, start_time, end_time)
def _get_events(request, event_type_list, start_time, end_time): # TODO: investigate this: some buggs probably due to cache Site.objects.clear_cache() current_site = Site.objects.get_current() Site.objects.clear_cache() topic = get_current_topic(request) title = ' - '.join([event.label for event in event_type_list]) template = 'topic/sorted_events.html' sorted_occurrences = dict() for event_type in event_type_list: occurrences = Occurrence.objects.filter(event__event_type__topic=topic, event__site=current_site, event__event_type=event_type, start_time__gte=start_time, end_time__lte=end_time) sorted_occurrences[event_type] = occurrences context = dict({ 'sorted_occurrences': sorted_occurrences, 'days': utils.list_days(start_time, end_time), 'title': title }) return render(request, template, context)
def single_day_event_type_list(request, event_type_id_string, year, month, day): event_type_list = utils.get_event_type_list(event_type_id_string, current_topic=get_current_topic(request)) date_day = utils.construct_day(year, month, day) start_time = utils.construct_time(date_day, time.min) end_time = utils.construct_time(date_day, time.max) return _get_events(request, event_type_list, start_time, end_time)
def daily_events(request, year, month, day): event_type_list = EventType.objects.filter( topic=get_current_topic(request)) date_day = utils.construct_day(year, month, day) start_time = utils.construct_time(date_day, time.min) end_time = utils.construct_time(date_day, time.max) return _get_events(request, event_type_list, start_time, end_time)
def single_day_event_type_list(request, event_type_id_string, year, month, day): event_type_list = utils.get_event_type_list( event_type_id_string, current_topic=get_current_topic(request)) date_day = utils.construct_day(year, month, day) start_time = utils.construct_time(date_day, time.min) end_time = utils.construct_time(date_day, time.max) return _get_events(request, event_type_list, start_time, end_time)
def _add_event( request, recurrence_form_class, template='crud/add_event.html', event_form_class=EventForm, ): topic = get_current_topic(request) return _add_event_by_topic(request, topic, recurrence_form_class, template, event_form_class)
def single_time_event_type_list(request, event_type_id_string, year, month, day, start_hour_string, end_hour_string): event_type_list = utils.get_event_type_list( event_type_id_string, current_topic=get_current_topic(request)) date_day = utils.construct_day(year, month, day) start_time = utils.construct_time(date_day, utils.construct_hour(start_hour_string)) end_time = utils.construct_time(date_day, utils.construct_hour(end_hour_string)) return _get_events(request, event_type_list, start_time, end_time)
def index(request, template='topic/research.html'): """ :param request: :param template: :return: home template with index form """ context = dict() topic = get_current_topic(request) if request.method == 'POST': form = IndexForm(topic, request.POST) if form.is_valid(): # required query_date = form.cleaned_data['quand'] # blank allowed event_type_list = form.cleaned_data['quoi'] # hour by default else. start_hour = form.cleaned_data['start_hour'] end_hour = form.cleaned_data['end_hour'] if event_type_list: event_type_id_string = utils.create_id_string(event_type_list) else: event_type_id_string = utils.create_id_string( EventType.objects.filter(topic=topic)) return redirect( reverse('topic:single_time_event_type_list', kwargs={ 'year': query_date.year, 'month': query_date.month, 'day': query_date.day, 'event_type_id_string': event_type_id_string, 'start_hour_string': utils.construct_hour_string(start_hour), 'end_hour_string': utils.construct_hour_string(end_hour), }, current_app=topic.name), ) else: form = IndexForm(topic) context['form'] = form return render(request, template, context)
def add_multiple_dates( request, template='crud/add_event_as_dates.html', event_form_class=EventForm, ): dtstart = None topic = get_current_topic(request) OccurrenceFormSet = formset_factory(MultipleDateSingleOccurrenceForm, extra=10) if request.method == 'POST': # to add event_planner to event event = Event( event_planner=EnjoyTodayUser.objects.get(user=request.user), #site=get_current_site(request) ) event_form = event_form_class(topic, request.POST, request.FILES, instance=event) formset = OccurrenceFormSet(request.POST) if event_form.is_valid() and formset.is_valid(): event.save() for occurrence_form in formset: if occurrence_form.is_valid and occurrence_form.cleaned_data: occurrence_form.save(event) return redirect('core:event_planner_panel') else: if 'dtstart' in request.GET: try: dtstart = parser.parse(request.GET['dtstart']) except (TypeError, ValueError) as exc: # TODO: A badly formatted date is passed to add_event logging.warning(exc) dtstart = dtstart or datetime.now() event_form = event_form_class(topic) # initial parameter doesnt work here formset = OccurrenceFormSet() context = dict({ 'dtstart': dtstart, 'event_form': event_form, 'formset': formset, }) return render(request, template, context)
def add_multiple_dates( request, template='crud/add_event_as_dates.html', event_form_class=EventForm, ): dtstart = None topic = get_current_topic(request) OccurrenceFormSet = formset_factory(SingleOccurrenceForm, extra=10) if request.method == 'POST': # to add event_planner to event event = Event(event_planner=EnjoyTodayUser.objects.get(user=request.user), #site=get_current_site(request) ) event_form = event_form_class(topic, request.POST, request.FILES, instance=event) formset = OccurrenceFormSet(request.POST) if event_form.is_valid() and formset.is_valid(): event.save() for occurrence_form in formset: if occurrence_form.is_valid and occurrence_form.cleaned_data: occurrence_form.save(event) return redirect('core:event_planner_panel') else: if 'dtstart' in request.GET: try: dtstart = parser.parse(request.GET['dtstart']) except(TypeError, ValueError) as exc: # TODO: A badly formatted date is passed to add_event logging.warning(exc) dtstart = dtstart or datetime.now() event_form = event_form_class(topic) # initial parameter doesnt work here formset = OccurrenceFormSet() context = dict({'dtstart': dtstart, 'event_form': event_form, 'formset': formset, }) return render(request, template, context)
def index(request, template='topic/research.html'): """ :param request: :param template: :return: home template with index form """ context = dict() topic = get_current_topic(request) if request.method == 'POST': form = IndexForm(topic, request.POST) if form.is_valid(): # required query_date = form.cleaned_data['quand'] # blank allowed event_type_list = form.cleaned_data['quoi'] # hour by default else. start_hour = form.cleaned_data['start_hour'] end_hour = form.cleaned_data['end_hour'] if event_type_list: event_type_id_string = utils.create_id_string(event_type_list) else: event_type_id_string = utils.create_id_string(EventType.objects.filter(topic=topic)) return redirect(reverse('topic:single_time_event_type_list', kwargs={'year': query_date.year, 'month': query_date.month, 'day': query_date.day, 'event_type_id_string': event_type_id_string, 'start_hour_string': utils.construct_hour_string(start_hour), 'end_hour_string': utils.construct_hour_string(end_hour), }, current_app=topic.name), ) else: form = IndexForm(topic) context['form'] = form return render(request, template, context)
def get_form(self, form_class=form_class): return form_class(topic=get_current_topic(self.request), **self.get_form_kwargs())
def event_type_coming_days(request, event_type_id_string): event_type_list = utils.get_event_type_list(event_type_id_string, current_topic=get_current_topic(request)) start_time = datetime.now() end_time = utils.end_of_next_days(duration=3) return _get_events(request, event_type_list, start_time, end_time)
def _all_events(request, start_time, end_time): event_type_list = EventType.objects.filter(topic=get_current_topic(request)) return _get_events(request, event_type_list, start_time, end_time)
def _all_events(request, start_time, end_time): event_type_list = EventType.objects.filter( topic=get_current_topic(request)) return _get_events(request, event_type_list, start_time, end_time)