本文整理汇总了Python中schedule.utils.coerce_date_dict函数的典型用法代码示例。如果您正苦于以下问题:Python coerce_date_dict函数的具体用法?Python coerce_date_dict怎么用?Python coerce_date_dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了coerce_date_dict函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_context_data
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
示例2: calendar_by_cn
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), )
示例3: calendar_by_periods
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), )
示例4: create_or_edit_event
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))
示例5: room_by_periods
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),)
示例6: get_initial
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
示例7: calendar_by_year
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), )
示例8: details
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
示例9: get_initial
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
示例10: get_context_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
示例11: get
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
示例12: calendar_by_periods_json
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)
示例13: calendar_ajax
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
示例14: get
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)
示例15: get_context_data
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