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) 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) period_objects = dict([(period.__name__.lower(), period(event_list, date)) for period in periods]) if request.is_ajax(): template_parts = template_name.split('.') template_name = '{}_ajax.{}'.format(template_parts[0], template_parts[1]) 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 get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) calendar = self.object period_class = self.kwargs["period"] try: date = coerce_date_dict(self.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(self.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(self.request.get_full_path()), } ) return context
def test_coerce_date_dict_empty(self): # empty dictionary returns current datetime before = timezone.now() current = coerce_date_dict({}) after = timezone.now() self.assertTrue(before < current) self.assertTrue(current < after)
def calendar_by_cn(request, country,template_name="schedule/calendar_cn.html"): """ """ model = Event calendar = get_object_or_404(Calendar, slug='calendar') 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() calendar = get_object_or_404(Calendar, slug='calendar') country = get_object_or_404(CountryPage, name=country) event_list= calendar.event_set.filter(country__country_slug=country) user = request.user userprofile = get_object_or_404(IppcUserProfile, user_id=user.id) #return render_to_response(template_name, { # 'calendar': calendar, # 'weekday_names': weekday_names, # 'event_list': event_list, # 'here': quote(request.get_full_path()), # 'country' : country # #}, context_instance=RequestContext(request), ) return TemplateResponse(request, template_name, { 'userprofile':userprofile, 'calendar': calendar, 'weekday_names': weekday_names, 'event_list': event_list, 'here': quote(request.get_full_path()), 'country' : country},)
def get_context_data(self, **kwargs): context = super(CalendarByPeriodsView, self).get_context_data(**kwargs) calendar = self.object period_class = self.kwargs['period'] try: date = coerce_date_dict(self.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(self.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(self.request.get_full_path()), }) return context
def details(request, id, periods=None): try: sched = Calendar.objects.get(id=id) date = coerce_date_dict(request.GET) if date: try: date = datetime.datetime(**date) except ValueError: raise Http404 else: date = timezone.now() event_list = sched.event_set.all() period_objects = dict([(period.__name__.lower(), period(event_list, date)) for period in periods]) return render_to_response( 'schedule/detail.html', { 'date': date, 'periods': period_objects, 'calendar': sched, 'weekday_names': weekday_names, 'here': quote(request.get_full_path()), }, context_instance=RequestContext(request), ) except Calendar.DoesNotExist: raise Http404
def CalendarioP(request): calendU = request.user.calendarioUser if (calendU is None): return redirect('logout') else: if request.user.is_staff: calendar = Calendar.objects.get(name='root') else: calendar = Calendar.objects.get(id=calendU.id) period_class = Day 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) print(calendU) return render( request, 'calendarioP.html', { 'date': date, 'period': period, 'calendar': calendar, 'weekday_names': weekday_names, 'here': quote(request.get_full_path()), })
def calendar_by_cn(request, country,template_name="schedule/calendar_cn.html"): """ """ model = Event calendar = get_object_or_404(Calendar, slug='calendar') 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() calendar = get_object_or_404(Calendar, slug='calendar') country = get_object_or_404(CountryPage, name=country) event_list= calendar.event_set.filter(country__country_slug=country) return render_to_response(template_name, { 'calendar': calendar, 'weekday_names': weekday_names, 'event_list': event_list, 'here': quote(request.get_full_path()), 'country' : country }, context_instance=RequestContext(request), )
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), )
def room_by_periods(request, room_slug, periods=None, template_name="schedule/room_by_period.html", extra_context=None): """ This view is for getting a room, but also getting periods with that room. 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``. ``room`` This is the Room that is designated by the ``room_slug``. ``weekday_names`` This is for convenience. It returns the local names of weekedays for internationalization. """ extra_context = extra_context or {} room = get_object_or_404(Room, slug=room_slug) date = coerce_date_dict(request.GET) if date: try: date = datetime.datetime(**date) except ValueError: raise Http404 else: date = datetime.datetime.now() reservation_list = GET_EVENTS_FUNC(request, room) period_objects = dict([(period.__name__.lower(), period(reservation_list, date)) for period in periods]) context = { 'date': date, 'periods': period_objects, 'room': room, 'weekday_names': weekday_names, 'here':quote(request.get_full_path()), } context.update(extra_context) return render_to_response(template_name, context, context_instance=RequestContext(request),)
def create_or_edit_event(request, calendar_slug, event_id=None, next=None, template_name='event/edit.html', form_class = EventForm): 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) data = request.POST.copy() if data: data["title"] = data["oncall"]+","+data["fallback"] form = form_class(data=data or None, instance=instance, initial=initial_data) users = User.objects.all(); if form.is_valid(): event = form.save(commit=False) if instance is None: event.creator = request.user event.calendar = calendar event.save() return HttpResponseRedirect(reverse('calendar_details', kwargs={'calendar_slug': calendar.slug})) if instance is not None: officers = instance.title.split(",") data["oncall"] = officers[0] data["fallback"] = officers[1] data["start_ymd"] = instance.start.date().isoformat() data["start_hour"] = instance.start.time().strftime("%H:%M") data["end_ymd"] = instance.end.date().isoformat() data["end_hour"] = instance.end.time().strftime("%H:%M") if instance.end_recurring_period: data["recurr_ymd"] = instance.end_recurring_period.date().isoformat() data["description"] = instance.description data["rule"] = instance.rule and instance.rule.id or "" next = get_next_url(request, next) return render_to_response(template_name, { "data": data, "calendar": calendar, "next":next, "users":users, "form": form, }, context_instance=RequestContext(request))
def details(request, calendar_slug, periods=None): try: sched = get_object_or_404(Calendar, slug=calendar_slug) date = coerce_date_dict(request.GET) if date: try: date = datetime(**date) except ValueError: raise Http404 else: date = timezone.now() event_list = sched.event_set.all() currently_oncall_users = escalation_helper.get_current_events_users( sched) if len(currently_oncall_users) >= 2: oncall1 = "%s, Phone Number:%s" % ( currently_oncall_users[0].username, currently_oncall_users[0].profile.phone_number) oncall2 = "%s, Phone Number:%s" % ( currently_oncall_users[1].username, currently_oncall_users[1].profile.phone_number) else: oncall1 = "Nobody" oncall2 = "Nobody" if 'django_timezone' in 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) return render_to_response( 'schedule/detail.html', { 'date': date, 'periods': period_objects, 'calendar': sched, 'weekday_names': weekday_names, 'currently_oncall_1': oncall1, 'currently_oncall_2': oncall2, 'local_timezone': local_timezone, 'current_date': timezone.now(), 'here': quote(request.get_full_path()), }, context_instance=RequestContext(request), ) except Calendar.DoesNotExist: raise Http404
def get_initial(self): date = coerce_date_dict(self.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 return initial_data
def calendar_by_year(request, calendar_slug, year=None, template_name="schedule/calendar_by_year.html"): """ """ model = Event calendar = get_object_or_404(Calendar, slug=calendar_slug) try: date = coerce_date_dict(request.GET) except ValueError: raise Http404 print(date) if date: try: date = datetime.datetime(**date) print(date) except ValueError: raise Http404 else: date = timezone.now() user = request.user can_add= 0 if user.groups.filter(name='IPPC Secretariat'): can_add=1 calendar = get_object_or_404(Calendar, slug=calendar_slug) event_list= calendar.event_set.filter(start__year=date.year,country=-1).order_by('start') event_list2=[] months_list = [] for m in range(1,13): months_list.append((m, datetime.date(2014, m, 1).strftime('%B'))) monthevents=[] for e in event_list: if e.start.month == m: monthevents.append(e) event_list2.append((m,monthevents)) period_objects = dict([(period.__name__.lower(), period(event_list, date)) for period in year]) return render_to_response(template_name, { 'periods': period_objects, 'calendar': calendar, 'weekday_names': weekday_names, 'event_list': event_list, 'months_list': months_list, 'event_list2': event_list2, 'current_year': date.year, 'can_add': can_add, 'here': quote(request.get_full_path()), }, context_instance=RequestContext(request), )
def get_initial(self): date = coerce_date_dict(self.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 return initial_data
def get_initial(self): date = coerce_date_dict(self.request.GET) initial_data = None if date: try: start = datetime.datetime(**date) initial_data = { "start": start, "end": start + datetime.timedelta(hours=3) } except TypeError: raise Http404 except ValueError: raise Http404 return initial_data
def details(request, calendar_slug, periods=None): try: sched = get_object_or_404(Calendar, slug=calendar_slug) date = coerce_date_dict(request.GET) if date: try: date = datetime(**date) except ValueError: raise Http404 else: date = timezone.now() event_list = sched.event_set.all() currently_oncall_users = escalation_helper.get_current_events_users(sched) if len(currently_oncall_users) >= 2: oncall1 = "%s, Phone Number:%s" % (currently_oncall_users[0].username, currently_oncall_users[0].profile.phone_number) oncall2 = "%s, Phone Number:%s" % (currently_oncall_users[1].username, currently_oncall_users[1].profile.phone_number) else: oncall1 = "Nobody" oncall2 = "Nobody" if 'django_timezone' in 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) return render_to_response('schedule/detail.html', { 'date': date, 'periods': period_objects, 'calendar': sched, 'weekday_names': weekday_names, 'currently_oncall_1' : oncall1, 'currently_oncall_2' : oncall2, 'local_timezone': local_timezone, 'current_date': timezone.now(), 'here':quote(request.get_full_path()), },context_instance=RequestContext(request), ) except Calendar.DoesNotExist: raise Http404
def get_initial(self): date = coerce_date_dict(self.request.GET) initial_data = {} 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 if self.kwargs.get('post_slug'): post = get_object_or_404(Post, slug=self.kwargs['post_slug']) initial_data['title'] = post.title return initial_data
def get_context_data(self, **kwargs): ctx = super(CalendarsView, self).get_context_data(**kwargs) date = coerce_date_dict(self.request.GET) if date: try: date = datetime.datetime(**date) except ValueError: raise Http404 else: date = timezone.now() ctx.update({ 'now' : datetime.now(), 'date' : date, }) return ctx
def get_initial_data(self): show_data = {} date_data = { "start": coerce_date_dict(self.request.GET), } if self.request.user.profile.profile_type == "m": show_data['headliner'] = self.request.user.profile.artist_profile show_data[ 'headliner_text'] = self.request.user.profile.artist_profile else: show_data['venue'] = self.request.user show_data['venue_text'] = self.request.user.profile return { 'poster_form': {}, 'date_form': date_data, 'event_form': {}, 'show_info_form': show_data, }
def get(self, request, pk): calendar_slug = request.GET.get('calendar_slug', None) calendar = get_object_or_404(Calendar, slug=calendar_slug) date = coerce_date_dict(request.GET) start = None end = None if date: try: start = datetime.datetime(**date) end = start + datetime.timedelta(minutes=30) except TypeError: raise Http404 except ValueError: raise Http404 cr = CalendarRelation.objects.get(calendar=calendar) medico = Medico.objects.get(pk=cr.object_id) paciente = Paciente.objects.get(user=self.get_user()) consulta = None consulta = Consulta.objects.create( start=start, end=end, title=paciente.nome, description="Consulta para o paciente %s" % (paciente.nome), creator=self.get_user(), calendar=calendar, medico=medico, paciente=paciente, ) #PAGSEGURO# if consulta: pay = Payment.objects.create(user=self.get_user()) pay.add_item(medico.item, 1) redirect_url = self.request.META[ 'HTTP_REFERER'] + '&result=ok%id_consulta={0}&id_pagamento={1}'.format( consulta.pk, pay.pk) pay.submit('http://globo.com' ) #Substituir por redirect_url quando em producao pay.save() consulta.pagamento = pay consulta.save() return HttpResponse(pay.client_url) response = redirect('day_calendar', calendar_slug=calendar.slug) response['Location'] += querystring_for_date(start) return response
def get_context_data(self, **kwargs): context = super(SchedulesDetailView, self).get_context_data(**kwargs) schedule = self.get_object() date = timezone.now() date_from_request = coerce_date_dict(self.request.GET) or None if date_from_request: try: date = datetime(**date_from_request) except ValueError: raise Http404 event_list = schedule.event_set.all() on_call_1, on_call_2 = self.get_on_call_users() local_timezone = timezone.get_default_timezone() if 'django_timezone' in self.request.session: # pragma: no cover local_timezone = pytz.timezone( self.request.session['django_timezone']) period_objects = {} month = Month(event_list, date, None, None, local_timezone) shift = None if shift: # pragma: no cover if shift == -1: month = month.prev() if shift == 1: month = month.next() size = 'regular' day_names = weekday_abbrs if size == 'small' else weekday_names extra_context = { 'day_names': day_names, 'month': month, 'size': size, 'date': date, 'periods': period_objects, 'calendar': schedule, 'weekday_names': weekday_names, 'currently_oncall_1': on_call_1, 'currently_oncall_2': on_call_2, 'local_timezone': local_timezone, 'current_date': timezone.now(), 'here': f"{self.request.get_full_path()}", } context.update(extra_context) return context
def details(request, id, periods=None): try: sched = Calendar.objects.get(id=id) date = coerce_date_dict(request.GET) if date: try: date = datetime(**date) except ValueError: raise Http404 else: date = timezone.now() event_list = sched.event_set.all() currently_oncall_users = escalation_helper.get_current_events_users( sched) if len(currently_oncall_users) >= 2: oncall1 = "%s, Phone Number:%s" % ( currently_oncall_users[0].username, currently_oncall_users[0].profile.phone_number) oncall2 = "%s, Phone Number:%s" % ( currently_oncall_users[1].username, currently_oncall_users[1].profile.phone_number) else: oncall1 = "Nobody" oncall2 = "Nobody" period_objects = dict([(period.__name__.lower(), period(event_list, date)) for period in periods]) return render_to_response( 'schedule/detail.html', { 'date': date, 'periods': period_objects, 'calendar': sched, 'weekday_names': weekday_names, 'currently_oncall_1': oncall1, 'currently_oncall_2': oncall2, 'here': quote(request.get_full_path()), }, context_instance=RequestContext(request), ) except Calendar.DoesNotExist: raise Http404
def get_initial(self): initial = super(ScheduleExperimentFormView, self).get_initial() initial = initial.copy() exp_pk = resolve(self.request.path).kwargs['exp_pk'] initial.update(exp_pk=int(exp_pk)) date = coerce_date_dict(self.request.GET) if date: try: start = datetime(**date) endseconds = models.OneTimeSSSCommand.objects.filter( commandchoice='EndExperiment(0)', parent_experiment__exp_pk=exp_pk).first().delay initial.update(start=start, end=start + timedelta(seconds=int(endseconds))) except TypeError: raise Http404 except ValueError: raise Http404 calendar = Calendar.objects.get(slug=GLOBAL_CALENDAR_SLUG) return initial
def get(self, request, pk): calendar_slug = request.GET.get('calendar_slug', None) calendar = get_object_or_404(Calendar, slug=calendar_slug) date = coerce_date_dict(request.GET) start = None end = None if date: try: start = datetime.datetime(**date) end = start + datetime.timedelta(minutes=30) except TypeError: raise Http404 except ValueError: raise Http404 cr = CalendarRelation.objects.get(calendar=calendar) medico = Medico.objects.get(pk=cr.object_id) paciente = Paciente.objects.get(user=self.get_user()) consulta = None consulta = Consulta.objects.create( start=start, end=end, title=paciente.nome, description="Consulta para o paciente %s" %(paciente.nome), creator=self.get_user(), calendar=calendar, medico=medico, paciente=paciente, ) #PAGSEGURO# if consulta: pay = Payment.objects.create(user=self.get_user()) pay.add_item(medico.item, 1) redirect_url = self.request.META['HTTP_REFERER'] + '&result=ok%id_consulta={0}&id_pagamento={1}'.format(consulta.pk, pay.pk) pay.submit('http://globo.com')#Substituir por redirect_url quando em producao pay.save() consulta.pagamento = pay consulta.save() return HttpResponse(pay.client_url) response = redirect('day_calendar', calendar_slug=calendar.slug) response['Location'] += querystring_for_date(start) return response
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 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)
def get_context_data(self, *args, **kwargs): context = super(CalendarView, self).get_context_data(*args, **kwargs) context['calendar'] = self.request.user.calendar context['date'] = coerce_date_dict(self.request.GET) context['filter'] = filter = kwargs.get('filter') if filter == 'requests': event_list = Participant.objects.filter( user=self.request.user, thread__request__isnull=False) else: context['filter'] = filter = 'shows' event_list = self.request.user.calendar.events.filter( approved=True) tz = timezone.get_current_timezone() if tz: context['period'] = self.period(event_list, context['date'], tzinfo=tz) else: context['period'] = self.period(event_list, context['date']) context['period_name'] = self.period.__name__.lower() return context
def get_context_data(self, **kwargs): context = super(CalendarByPeriodView, self).get_context_data(**kwargs) context['site_name'] = settings.SITE_NAME depuser = self.request.user.departament if (depuser is None): print(depuser) return redirect('logout') else: if self.request.user.is_admin: # print(self.request.user.is_admin) calendar = Calendar.objects.get(name='root') else: # print(self.request.user.is_admin) calendar = Calendar.objects.get(id=depuser.calendario.id) period_class = self.kwargs['period'] try: date = coerce_date_dict(self.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(self.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(self.request.get_full_path()), }) return context
def calendar_ajax(context, calendar_slug): calendar = get_object_or_404(Calendar, slug=calendar_slug) date = coerce_date_dict(context['request'].GET) if date: try: date = datetime.datetime(**date) except ValueError: raise Http404 else: date = datetime.datetime.now() event_list = GET_EVENTS_FUNC(context['request'], calendar) periods = [Month] 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(context['request'].get_full_path()), 'MEDIA_URL': settings.MEDIA_URL, } return context
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
def get(self,request,*args,**kwargs): way = Way.objects.get(pk=kwargs['pk']) 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() if(kwargs['period'] == 'month'): period = way.get_month(date) args = { 'calendar':way.calendar, 'period':period, 'size':kwargs['size'] } prev_date = period.prev().start next_date = period.next().start val = {'rendered':render_to_string('schedule/calendar_month_compact.html',args), 'prev_date': { 'year':prev_date.year, 'month':prev_date.month, 'day':prev_date.day, 'hour':prev_date.hour, 'minute':prev_date.minute,'second':prev_date.second }, 'next_date': { 'year':next_date.year, 'month':next_date.month, 'day':next_date.day, 'hour':next_date.hour, 'minute':next_date.minute,'second':next_date.second } } elif(kwargs['period'] == 'day'): period = way.get_day(date) up_date = way.get_month(date).start occurrences = period.get_occurrences() for occ in occurrences: occ.meeting_url = Meeting.objects.get(event_ptr_id=occ.event.pk).get_absolute_url() args = { 'calendar':way.calendar, 'period':period, 'size':kwargs['size'], 'occurrences':occurrences } prev_date = period.prev().start next_date = period.next().start val = {'rendered':render_to_string('schedule/calendar_myday.html',args), 'prev_date': { 'year':prev_date.year, 'month':prev_date.month, 'day':prev_date.day, 'hour':prev_date.hour, 'minute':prev_date.minute,'second':prev_date.second }, 'next_date': { 'year':next_date.year, 'month':next_date.month, 'day':next_date.day, 'hour':next_date.hour, 'minute':next_date.minute,'second':next_date.second }, 'up_date': { 'year':up_date.year, 'month':up_date.month, 'day':up_date.day, 'hour':up_date.hour, 'minute':up_date.minute,'second':up_date.second } } return Response(val)
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
def HomeView(request): depuser = request.user.departament if (depuser is None): return redirect('logout') else: if request.user.is_admin: # print(self.request.user.is_admin) calendar = Calendar.objects.get(name='root') else: # print(self.request.user.is_admin) calendar = Calendar.objects.get(id=depuser.calendario.id) period_class = Day 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) return render( request, 'home.html', { 'site_name': settings.SITE_NAME, 'date': date, 'period': period, 'calendar': calendar, 'weekday_names': weekday_names, 'here': quote(request.get_full_path()), })
def get_context_data(self, request, **kwargs): context = super(AccountCalendar, 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
def details(request, id, periods=None): try: sched = Calendar.objects.get(id = id) date = coerce_date_dict(request.GET) if date: try: date = datetime.datetime(**date) except ValueError: raise Http404 else: date = timezone.now() event_list = sched.event_set.all() period_objects = dict([(period.__name__.lower(), period(event_list, date)) for period in periods]) return render_to_response('schedule/detail.html', { 'date': date, 'periods': period_objects, 'calendar': sched, 'weekday_names': weekday_names, 'here':quote(request.get_full_path()), },context_instance=RequestContext(request), ) except Calendar.DoesNotExist: raise Http404
def details(request, id, periods=None): try: sched = Calendar.objects.get(id = id) date = coerce_date_dict(request.GET) if date: try: date = datetime(**date) except ValueError: raise Http404 else: date = timezone.now() event_list = sched.event_set.all() currently_oncall_users = escalation_helper.get_current_events_users(sched) if len(currently_oncall_users) >= 2: oncall1 = "%s, Phone Number:%s" % (currently_oncall_users[0].username, currently_oncall_users[0].profile.phone_number) oncall2 = "%s, Phone Number:%s" % (currently_oncall_users[1].username, currently_oncall_users[1].profile.phone_number) else: oncall1 = "Nobody" oncall2 = "Nobody" period_objects = dict([(period.__name__.lower(), period(event_list, date)) for period in periods]) return render_to_response('schedule/detail.html', { 'date': date, 'periods': period_objects, 'calendar': sched, 'weekday_names': weekday_names, 'currently_oncall_1' : oncall1, 'currently_oncall_2' : oncall2, 'here':quote(request.get_full_path()), },context_instance=RequestContext(request), ) except Calendar.DoesNotExist: raise Http404
def calendar_by_year(request, calendar_slug, year=None, template_name="schedule/calendar_by_year.html"): """ """ model = Event calendar = get_object_or_404(Calendar, slug=calendar_slug) try: date = coerce_date_dict(request.GET) except ValueError: raise Http404 print(date) if date: try: date = datetime.datetime(**date) print(date) except ValueError: raise Http404 else: date = timezone.now() user = request.user can_add= 0 if user.groups.filter(name='IPPC Secretariat'): can_add=1 calendar = get_object_or_404(Calendar, slug=calendar_slug) event_list= calendar.event_set.filter(start__year=date.year,country=-1).order_by('start') event_list2=[] months_list = [] for m in range(1,13): months_list.append((m, datetime.date(2014, m, 1).strftime('%B'))) monthevents=[] for e in event_list: if e.start.month == m: monthevents.append(e) event_list2.append((m,monthevents)) period_objects = dict([(period.__name__.lower(), period(event_list, date)) for period in year]) # return render_to_response(template_name, { # 'periods': period_objects, # 'calendar': calendar, # 'weekday_names': weekday_names, # 'event_list': event_list, # 'months_list': months_list, # 'event_list2': event_list2, # 'current_year': date.year, # 'can_add': can_add, # 'here': quote(request.get_full_path()), # }, context_instance=RequestContext(request), ) return TemplateResponse(request,template_name, { 'periods': period_objects, 'calendar': calendar, 'weekday_names': weekday_names, 'event_list': event_list, 'months_list': months_list, 'event_list2': event_list2, 'current_year': date.year, 'can_add': can_add, 'here': quote(request.get_full_path()),})
def create_or_edit_event(request, country, calendar_slug, event_id=None, next=None, template_name='schedule/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: schedule/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 """ user = request.user if country=='event': print() else: country = get_object_or_404(CountryPage, name=country) 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 issues = None is_contryeevent=0 is_secretariat=0 is_contryeditor=0 is_contryeditor_1=0 can_add_edit=0 if user.groups.filter(name='IPPC Secretariat'): is_secretariat=1 if user.groups.filter(name='Country editor'): is_contryeditor=1 if user.groups.filter(name='Country Contact Points'): is_contryeditor=1 issueform =IssueKeywordsRelateForm(request.POST) calendar = get_object_or_404(Calendar, slug=calendar_slug) userprofile = get_object_or_404(IppcUserProfile, user_id=user.id) if event_id is not None: instance = get_object_or_404(Event, id=event_id) if user.groups.filter(name='Country editor') and (instance.country==userprofile.country): is_contryeditor_1=1 can_add_edit=1 if instance.country.id!=-1 : is_contryeevent=1 if (is_secretariat==1 and is_contryeevent==0): can_add_edit=1 if instance.issuename.count()>0: issues = get_object_or_404(IssueKeywordsRelate, pk=instance.issuename.all()[0].id) issueform =IssueKeywordsRelateForm(request.POST,instance=issues) else: issueform =IssueKeywordsRelateForm(request.POST) else: instance = Event() if is_contryeditor==1: can_add_edit=1 if (is_secretariat==1): can_add_edit=1 form = form_class(data=request.POST or None, instance=instance, initial=initial_data) if request.method == "POST": f_form = EventFileFormSet(request.POST, request.FILES,instance=instance) u_form = EventUrlFormSet(request.POST, instance=instance) p_form = EventParticipantsFormSet(request.POST, instance=instance) #issueform =IssueKeywordsRelateForm(request.POST,instance=issues) else: # issueform =IssueKeywordsRelateForm(instance=issues) f_form = EventFileFormSet(instance=instance) u_form = EventUrlFormSet(instance=instance) p_form = EventParticipantsFormSet(instance=instance) if form.is_valid() and f_form.is_valid() and u_form.is_valid() and p_form.is_valid(): event = form.save(commit=False) event.start=event.start + datetime.timedelta(hours=12) if user.groups.filter(name='Country editor'): event.country=user.get_profile().country event.creator = request.user event.calendar = calendar event.save() form.save_m2m() issue_instance = issueform.save(commit=False) issue_instance.content_object = event issue_instance.save() issueform.save_m2m() f_form.instance = event f_form.save() u_form.instance = event u_form.save() p_form.instance = event p_form.save() if event_id is not None: print('edit') else: print('new')#sendemail send_notificationevent_message(event.id) 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, # "issueform": issueform, # "f_form": f_form, # "u_form": u_form, # "p_form": p_form, # "calendar": calendar, # "is_contryeditor":is_contryeditor, # "is_contryeditor_1":is_contryeditor_1, # "is_secretariat":is_secretariat, # "can_add_edit":can_add_edit, # "event_id":event_id, # "next": next #}, context_instance=RequestContext(request)) return TemplateResponse(request, template_name, { "userprofile":userprofile, "form": form, "issueform": issueform, "f_form": f_form, "u_form": u_form, "p_form": p_form, "calendar": calendar, "is_contryeditor":is_contryeditor, "is_contryeditor_1":is_contryeditor_1, "is_secretariat":is_secretariat, "can_add_edit":can_add_edit, "event_id":event_id, "next": next},)
def create_or_edit_reservation(request, room_slug, reservation_id=None, next=None, template_name='schedule/create_reservation.html', form_class = ReservationForm, extra_context=None): """ 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: schedule/create_reservation.html Context Variables: form: an instance of ReservationForm room: a Room with id=room_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 reservation_id it will edit the reservation with that id, if it recieves a room_id and it is creating a new reservation it will add that reservation to the room with the id room_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 reservation detail of the recently create reservation """ extra_context = extra_context or {} 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 reservation_id is not None: instance = get_object_or_404(Reservation, id=reservation_id) room = get_object_or_404(Room, slug=room_slug) form = form_class(data=request.POST or None, instance=instance, hour24=True, initial=initial_data) if form.is_valid(): reservation = form.save(commit=False) if instance is None: reservation.creator = request.user reservation.room = room reservation.save() next = next or reverse('reservation', args=[reservation.id]) next = get_next_url(request, next) return HttpResponseRedirect(next) next = get_next_url(request, next) context = { "form": form, "room": room, "next":next } context.update(extra_context) return render_to_response(template_name, context, context_instance=RequestContext(request))
def create_or_edit_reservation(request, room_slug, reservation_id=None, next=None, template_name='schedule/create_reservation.html', form_class = ReservationForm, extra_context=None): errors = [] extra_context = extra_context or {} 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 conflict = False if reservation_id is not None: instance = get_object_or_404(Reservation, id=reservation_id) room = get_object_or_404(Room, slug=room_slug) form = form_class(data=request.POST or None, instance=instance, hour24=True, initial=initial_data) if form.is_valid(): d = form.cleaned_data start_time = d['start'] end_time = d['end'] start_conflict = room.reservation_set.filter(start__gt=start_time, start__lt=end_time).exclude(id=reservation_id) end_conflict = room.reservation_set.filter(end__gt=start_time, end__lt=end_time).exclude(id=reservation_id) during_conflict = room.reservation_set.filter(start__lt=start_time, end__gt=end_time).exclude(id=reservation_id) start_end_conflict = room.reservation_set.filter(start=start_time, end=end_time).exclude(id=reservation_id) if(start_conflict or end_conflict or during_conflict or start_end_conflict): conflict = True now = datetime.datetime.now() if(start_time < now): errors.append('Reservations can only be made for future dates.') next = get_next_url(request, next) context = { "form": form, "room": room, "next":next, "errors":errors, } return render_to_response(template_name, context, context_instance=RequestContext(request)) if(conflict): errors.append('Reservation cannot be granted. There is a conflict in schedule. Please try again') next = get_next_url(request, next) context = { "form": form, "room": room, "next":next, "errors":errors, } return render_to_response(template_name, context, context_instance=RequestContext(request)) else: reservation = form.save(commit=False) if instance is None: reservation.creator = request.user reservation.room = room reservation.save() next = next or reverse('reservation', args=[reservation.id]) next = get_next_url(request, next) return HttpResponseRedirect(next) next = get_next_url(request, next) context = { "form": form, "room": room, "next":next } context.update(extra_context) return render_to_response(template_name, context, context_instance=RequestContext(request))
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) 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', 'UTC') 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(request, template_name, { 'date': date, 'periods': period_objects, 'calendar': calendar, 'weekday_names': weekday_names, 'here': quote(request.get_full_path()), }, )
def create_or_edit_event(request, country, calendar_slug, event_id=None, next=None, template_name='schedule/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: schedule/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 """ user = request.user if country=='event': print() else: country = get_object_or_404(CountryPage, name=country) 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 issues = None is_contryeevent=0 is_secretariat=0 is_contryeditor=0 is_contryeditor_1=0 can_add_edit=0 if user.groups.filter(name='IPPC Secretariat'): is_secretariat=1 if user.groups.filter(name='Country editor'): is_contryeditor=1 issueform =IssueKeywordsRelateForm(request.POST) calendar = get_object_or_404(Calendar, slug=calendar_slug) if event_id is not None: instance = get_object_or_404(Event, id=event_id) if user.groups.filter(name='Country editor') and (instance.country==user.get_profile().country): is_contryeditor_1=1 can_add_edit=1 if instance.country.id!=-1 : is_contryeevent=1 if (is_secretariat==1 and is_contryeevent==0): can_add_edit=1 if instance.issuename.count()>0: issues = get_object_or_404(IssueKeywordsRelate, pk=instance.issuename.all()[0].id) issueform =IssueKeywordsRelateForm(request.POST,instance=issues) else: issueform =IssueKeywordsRelateForm(request.POST) else: instance = Event() if is_contryeditor==1: can_add_edit=1 if (is_secretariat==1): can_add_edit=1 form = form_class(data=request.POST or None, instance=instance, initial=initial_data) if request.method == "POST": f_form = EventFileFormSet(request.POST, request.FILES,instance=instance) u_form = EventUrlFormSet(request.POST, instance=instance) p_form = EventParticipantsFormSet(request.POST, instance=instance) #issueform =IssueKeywordsRelateForm(request.POST,instance=issues) else: # issueform =IssueKeywordsRelateForm(instance=issues) f_form = EventFileFormSet(instance=instance) u_form = EventUrlFormSet(instance=instance) p_form = EventParticipantsFormSet(instance=instance) if form.is_valid() and f_form.is_valid() and u_form.is_valid() and p_form.is_valid(): event = form.save(commit=False) event.start=event.start + datetime.timedelta(hours=12) if user.groups.filter(name='Country editor'): event.country=user.get_profile().country event.creator = request.user event.calendar = calendar event.save() form.save_m2m() issue_instance = issueform.save(commit=False) issue_instance.content_object = event issue_instance.save() issueform.save_m2m() f_form.instance = event f_form.save() u_form.instance = event u_form.save() p_form.instance = event p_form.save() if event_id is not None: print('edit') else: print('new')#sendemail send_notificationevent_message(event.id) 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, "issueform": issueform, "f_form": f_form, "u_form": u_form, "p_form": p_form, "calendar": calendar, "is_contryeditor":is_contryeditor, "is_contryeditor_1":is_contryeditor_1, "is_secretariat":is_secretariat, "can_add_edit":can_add_edit, "event_id":event_id, "next": next }, context_instance=RequestContext(request))
def all_calendars_by_period(request, 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. """ calendars = Calendar.objects.all() calendar_one = calendars.get(slug = 'room-541') calendar_two = calendars.get(slug = 'room-542') calendar_three = calendars.get(slug = 'room-543') calendar_four = calendars.get(slug = 'room-544') 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_one = GET_EVENTS_FUNC(request, calendar_one) event_list_two = GET_EVENTS_FUNC(request, calendar_two) event_list_three = GET_EVENTS_FUNC(request, calendar_three) event_list_four = GET_EVENTS_FUNC(request, calendar_four) if 'django_timezone' in request.session: local_timezone = pytz.timezone(request.session['django_timezone']) else: local_timezone = timezone.get_default_timezone() period_objects_one = {} period_objects_two = {} period_objects_three = {} period_objects_four = {} for period in periods: if period.__name__.lower() == 'year': period_objects_one[period.__name__.lower()] = period(event_list_one, date, None, local_timezone) period_objects_two[period.__name__.lower()] = period(event_list_two, date, None, local_timezone) period_objects_three[period.__name__.lower()] = period(event_list_three, date, None, local_timezone) period_objects_four[period.__name__.lower()] = period(event_list_four, date, None, local_timezone) else: period_objects_one[period.__name__.lower()] = period(event_list_one, date, None, None, local_timezone) period_objects_two[period.__name__.lower()] = period(event_list_two, date, None, None, local_timezone) period_objects_three[period.__name__.lower()] = period(event_list_three, date, None, None, local_timezone) period_objects_four[period.__name__.lower()] = period(event_list_four, date, None, None, local_timezone) return render_to_response(template_name, { 'date': date, 'periods_one': period_objects_one, 'periods_two': period_objects_two, 'periods_three': period_objects_three, 'periods_four': period_objects_four, 'calendar_one': calendar_one, 'calendar_two': calendar_two, 'calendar_three': calendar_three, 'calendar_four': calendar_four, 'weekday_names': weekday_names, 'here': quote(request.get_full_path()), }, context_instance=RequestContext(request), )
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))
def create_or_edit_event(request, calendar_slug, event_id=None, next=None, template_name='schedule/create_event.html', form_class=EventForm): date = coerce_date_dict(request.GET) initial_data = None if date: try: start = datetime.datetime(**date) lesson_time = datetime.datetime(**date) lesson_time_start = lesson_time.strftime("%m/%d/%Y %I:%M %p") initial_data = { "start": start, "end": start + datetime.timedelta(minutes=60) } 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, initial=initial_data) if form.is_valid(): event = form.save(commit=False) if instance is None: event.calendar = calendar try: to_email = event.creator.email number_of_lessons = event.creator.lessoncount.lesson_current_amount send_mail( 'New Lesson!', 'You have scheduled a workout for {} on {}.'.format( request.user.get_full_name(), lesson_time_start), '*****@*****.**', ['*****@*****.**']) send_mail( 'New Lesson!', 'You have been scheduled for a new workout on {}. ' 'A lesson will be deducted from your account.'.format( lesson_time_start), '*****@*****.**', [to_email]) membership_instance, created = LessonCount.objects \ .get_or_create(user=event.creator) membership_lesson_completed.send( membership_instance, new_lesson_count=number_of_lessons - 1) except: pass event.save() next = next or reverse('event', args=[event.id]) next = get_next_url(request, next) messages.success( request, "Thank you for scheduling a new lesson for {}!".format( lesson_time_start)) return HttpResponseRedirect(next) next = get_next_url(request, next) return render_to_response(template_name, { "form": form, "calendar": calendar, "next": next }, context_instance=RequestContext(request))
def create_or_edit_event(request, calendar_slug, event_id=None, next=None, template_name='schedule/create_event.html', form_class = EventForm, extra_context=None): extra_context = extra_context or {} 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 conflict = False 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) if form.is_valid(): d = form.cleaned_data start_time = d['start'] end_time = d['end'] start_conflict = calendar.event_set.filter(start__gt=start_time, start__lt=end_time).exclude(id=event_id) end_conflict = calendar.event_set.filter(end__gt=start_time, end__lt=end_time).exclude(id=event_id) during_conflict = calendar.event_set.filter(start__lt=start_time, end__gt=end_time).exclude(id=event_id) start_end_conflict = calendar.event_set.filter(start=start_time, end=end_time) if(start_conflict or end_conflict or during_conflict or start_end_conflict): conflict = True now = datetime.datetime.now() if(start_time < now): return render_to_response('restrict_reserve.html', context_instance=RequestContext(request)) if(conflict): return render_to_response('schedule_conflict.html', context_instance=RequestContext(request)) else: event = form.save(commit=False) if instance is None: event.creator = request.user event.calendar = calendar event.save() next = next or reverse('event', args=[event.id]) next = get_next_url(request, next) return HttpResponseRedirect(next) next = get_next_url(request, next) context = { "form": form, "calendar": calendar, "next":next } context.update(extra_context) return render_to_response(template_name, context, context_instance=RequestContext(request))
def get(self, request, *args, **kwargs): way = Way.objects.get(pk=kwargs['pk']) 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() if (kwargs['period'] == 'month'): period = way.get_month(date) args = { 'calendar': way.calendar, 'period': period, 'size': kwargs['size'] } prev_date = period.prev().start next_date = period.next().start val = { 'rendered': render_to_string('schedule/calendar_month_compact.html', args), 'prev_date': { 'year': prev_date.year, 'month': prev_date.month, 'day': prev_date.day, 'hour': prev_date.hour, 'minute': prev_date.minute, 'second': prev_date.second }, 'next_date': { 'year': next_date.year, 'month': next_date.month, 'day': next_date.day, 'hour': next_date.hour, 'minute': next_date.minute, 'second': next_date.second } } elif (kwargs['period'] == 'day'): period = way.get_day(date) up_date = way.get_month(date).start occurrences = period.get_occurrences() for occ in occurrences: occ.meeting_url = Meeting.objects.get( event_ptr_id=occ.event.pk).get_absolute_url() args = { 'calendar': way.calendar, 'period': period, 'size': kwargs['size'], 'occurrences': occurrences } prev_date = period.prev().start next_date = period.next().start val = { 'rendered': render_to_string('schedule/calendar_myday.html', args), 'prev_date': { 'year': prev_date.year, 'month': prev_date.month, 'day': prev_date.day, 'hour': prev_date.hour, 'minute': prev_date.minute, 'second': prev_date.second }, 'next_date': { 'year': next_date.year, 'month': next_date.month, 'day': next_date.day, 'hour': next_date.hour, 'minute': next_date.minute, 'second': next_date.second }, 'up_date': { 'year': up_date.year, 'month': up_date.month, 'day': up_date.day, 'hour': up_date.hour, 'minute': up_date.minute, 'second': up_date.second } } return Response(val)
def create_or_edit_event(request, calendar_slug, event_id=None, next=None, template_name='schedule/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: schedule/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 """ 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, initial=initial_data) if form.is_valid(): event = form.save(commit=False) if instance is None: event.creator = request.user event.calendar = calendar event.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, "next": next }, context_instance=RequestContext(request))
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), )