本文整理汇总了Python中schedule.utils.coerce_date_dict函数的典型用法代码示例。如果您正苦于以下问题:Python coerce_date_dict函数的具体用法?Python coerce_date_dict怎么用?Python coerce_date_dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了coerce_date_dict函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:Alcolo47,项目名称:django-scheduler,代码行数:28,代码来源:views.py
示例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), )
开发者ID:ippc,项目名称:ippcdj,代码行数:30,代码来源:views.py
示例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), )
开发者ID:damianmoore,项目名称:django-scheduler,代码行数:60,代码来源:views.py
示例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))
开发者ID:40a,项目名称:openduty,代码行数:55,代码来源:events.py
示例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),)
开发者ID:bjdag1234,项目名称:django-schedule-rooms,代码行数:55,代码来源:views.py
示例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
开发者ID:Tamriel,项目名称:wagtail_room_booking,代码行数:12,代码来源:views.py
示例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), )
开发者ID:ippc,项目名称:ippcdj,代码行数:52,代码来源:views.py
示例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
开发者ID:40a,项目名称:openduty,代码行数:48,代码来源:schedules.py
示例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
开发者ID:guanquan94,项目名称:orbis,代码行数:18,代码来源:views.py
示例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
开发者ID:sittizen,项目名称:django-fullcalendar,代码行数:18,代码来源:views.py
示例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
开发者ID:tulioncds,项目名称:med-alliance,代码行数:41,代码来源:views.py
示例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)
开发者ID:zorna,项目名称:django-schedule,代码行数:21,代码来源:views.py
示例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
开发者ID:damianmoore,项目名称:django-scheduler,代码行数:22,代码来源:scheduletags.py
示例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)
开发者ID:linux2400,项目名称:learningers,代码行数:38,代码来源:views.py
示例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
开发者ID:Tamriel,项目名称:wagtail_room_booking,代码行数:38,代码来源:views.py
示例16: details
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
开发者ID:larue3000,项目名称:openduty,代码行数:36,代码来源:schedules.py
示例17: get_context_data
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
开发者ID:Yury191,项目名称:brownstonetutors,代码行数:36,代码来源:views.py
示例18: details
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
开发者ID:ematthews,项目名称:openduty,代码行数:24,代码来源:schedules.py
示例19: all_calendars_by_period
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), )
开发者ID:lawhorkl,项目名称:uc-consult-panel,代码行数:86,代码来源:views.py
示例20: create_or_edit_reservation
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))
开发者ID:bjdag1234,项目名称:django-schedule-rooms,代码行数:75,代码来源:views.py
注:本文中的schedule.utils.coerce_date_dict函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论