本文整理汇总了Python中events.models.Event.date_time_end方法的典型用法代码示例。如果您正苦于以下问题:Python Event.date_time_end方法的具体用法?Python Event.date_time_end怎么用?Python Event.date_time_end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类events.models.Event
的用法示例。
在下文中一共展示了Event.date_time_end方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_event
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import date_time_end [as 别名]
def save_event(request):
if request.is_ajax() or True:
print 'Is AJAX'
# TODO: Add handler for these below. They are required and must be submitted or else the form will not validate. Or perhaps the clean_fields() exception is enough...?
import pprint
print 'Hér kemur hrátt data:'
pprint.pprint(request.POST['data'])
print 'Hér kemur JSON útgáfan:'
data = json.loads(request.POST['data'])
pprint.pprint(data)
t = data['title']
d = data['description']
dtb = timezone.make_aware(parser.parse(data['date_time_begin']),timezone.get_default_timezone())
dte = timezone.make_aware(parser.parse(data['date_time_end']),timezone.get_default_timezone())
et_id = data['event_type']
try:
event_id = data['event_id']
if event_id == '':
# If no event id has been supplied, we'll create a new event.
event = Event(title=t, description=d, date_time_begin=dtb, date_time_end=dte, event_type_id=et_id)
else:
# else we update the existing one.
event = Event.objects.get(pk=event_id)
event.title = t
event.description = d
event.date_time_begin = dtb
event.date_time_end = dte
event.event_type_id = et_id
#return HttpResponse('Event fields updated.')
# Now save the event
try:
event.clean_fields()
event.save()
print 'The event is: ------'
print (vars(event))
print '--------------------'
except:
return HttpResponse ("Hello, world. Could not save event.")
# Now that the event has been taken care of, let's sort out the event roles etc.
# Flow:
# For each role:
for role in Role.objects.all():
print 'Role ID %s' % role.id
print 'Role is %s' % role
try: #if we want the role:
currentparticipants = [] # This will be populated below if the event exists (and currently has any participants).
currentgroups = [] # This will be populated below if the event exists (and currently has any participants).
currentmembers= [] # This will be populated below if the event exists (and currently has any participants).
wantedparticipantIDs = data['role'][role.id]['participants']
print 'Wanted participantsID: {}'.format(wantedparticipantIDs)
wantedgroups = [Group.objects.get(pk=int(groupid[1:])) for groupid in wantedparticipantIDs if groupid[0]=='g']
print 'We want event role {} with groups {}'.format(role, wantedgroups)
wantedmembers= [Member.objects.get(pk=int(memberid[1:])) for memberid in wantedparticipantIDs if memberid[0]=='m']
print 'We want event role {} with members {}'.format(role, wantedmembers)
try: #check whether the EventRole already exists
# In the event that an EventRole already exists, we have to:
# 1. Get the EventRole, stored in eventrole.
# 2. Remove unwanted participants
# Adding wanted participants is shared with EventRoles that
# need to be created so we're doing that later on.
# 3. Update the minimum and maximum number of participants
# 1.
eventrole = EventRole.objects.get(event_id=event.id,role_id=role.id)
print 'EventRole "{}" already exists.'.format(eventrole)
# 2.
#currentgroups= GroupInvitation.objects.filter(event_role=eventrole)
currentgroups = eventrole.invited_groups.all()
currentmembers= eventrole.invited_members.all()
print 'currentgroups: {}'.format(currentgroups)
print 'currentmembers: {}'.format(currentmembers)
print 'EventRole already has these invitations:'
for group in currentgroups:
print '>>{} ({})'.format(group, group.id)
#print 'Comare {} with {}'.format(group.id,wantedgroups)
if group not in wantedgroups:
print '-- ID is {}: We don\'t want {}.'.format(group.id,group)
#gi = GroupInvitation(event_role=eventrole,group=group)
#print 'Removing group {} from eventrole {}'.format(group,eventrole)
#print 'DEBUG'
try:
print 'DEBUG: {}'.format(eventrole.invited_groups)
gi = GroupInvitation.objects.get(event_role=eventrole,group=group)
#print gi
gi.delete()
print 'BINGO'
except:
print 'Could not remove group {} from {}'.format(group,currentgroups)
else:
print '++ ID is {}: We keep {}.'.format(group.id,group)
for member in currentmembers:
print '>>{} ({})'.format(member, member.id)
if member not in wantedmembers:
print '-- ID is {}: We don\'t want {}.'.format(member.id,member)
try:
print 'DEBUG: {}'.format(eventrole.invited_members)
mi = MemberInvitation.objects.get(event_role=eventrole,member=member)
#.........这里部分代码省略.........
示例2: save_event
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import date_time_end [as 别名]
def save_event(request):
print 'Saving event'
if not request.is_ajax():
return HttpResponse(json.dumps({ 'type': 'error', 'message': 'Hello, world. Not an AJAX request.'}))
else:
print 'Is AJAX'
import pprint
print 'Hér kemur hrátt data:'
pprint.pprint(request.POST['data'])
print 'Hér kemur JSON útgáfan:'
data = json.loads(request.POST['data'])
pprint.pprint(data)
# Sanitise some of the data and return messages if it fails.
### TITLE ###
# The title must be non-zero and no longer than 64 characters (defined in events/models.py).
print 'Submitted data:'
t = data['title']
if t == "":
return HttpResponse(json.dumps({ 'type': 'error', 'message': 'Title missing.', }))
elif len(t) > 64:
return HttpResponse(json.dumps({ 'type': 'error', 'message': 'The title is currently '+str(len(t))+' characters long but the maximum is 64.', }))
import sys
print sys.stdout.encoding
print type(t)
print '--title: {}'.format(t.encode('UTF-8'))
### DESCRIPTION ###
# There are no restrictions on the description field other than being cleaned. It may be blank and arbitrarily long.
d = data['description']
# The dates must be supplied and the beginning must precede the end.
print '--description: {}'.format(d.encode('UTF-8'))
### DATES ###
if data['date_time_begin'] == "":
return HttpResponse(json.dumps({ 'type': 'error', 'message': 'Beginning date missing.', }))
try:
dtb = timezone.make_aware(parser.parse(data['date_time_begin']),timezone.get_default_timezone())
except:
return HttpResponse(json.dumps({ 'type': 'error', 'message': 'Beginning date-time is not a valid datetime.', }))
print '--begins: {}'.format(dtb)
if data['date_time_end'] == "":
return HttpResponse(json.dumps({ 'type': 'error', 'message': 'End date missing.', }))
try:
dte = timezone.make_aware(parser.parse(data['date_time_end']),timezone.get_default_timezone())
except:
return HttpResponse(json.dumps({ 'type': 'error', 'message': 'End date-time is not a valid datetime', }))
if dte <= dtb:
return HttpResponse(json.dumps({ 'type': 'error', 'message': 'The event start time must precede the end.', }))
print '--ends: {}'.format(dte)
### TYPE ###
# The event-type must be supplied.
et_id = data['event_type']
print '--type ID: {}'.format(et_id)
if et_id== "":
return HttpResponse(json.dumps({ 'type': 'error', 'message': 'No event type supplied.', }))
### EVENT ID ###
print 'All the data has been submitted. Checking whether event_id has been supplied.'
try:
event_id = data['event_id']
print 'event_id: {}'.format(event_id)
except:
return HttpResponse(json.dumps({ 'type': 'error', 'message': 'No event_id submitted.', }))
if event_id == '':
# If no event id has been supplied, we'll create a new event.
print 'Creating event...'
event = Event(title=t, description=d, date_time_begin=dtb, date_time_end=dte, event_type_id=et_id)
else:
# else we update the existing one.
print 'Updating event...'
event = Event.objects.get(pk=event_id)
event.title = t
event.description = d
event.date_time_begin = dtb
event.date_time_end = dte
event.event_type_id = et_id
# Now save the event
try:
event.clean_fields()
event.save()
print 'The event is: ------'
pprint.pprint(vars(event))
print '--------------------'
except:
return HttpResponse (json.dumps({ 'type': 'error', 'message': 'Could not save event.'}))
# Now that the event has been taken care of, let's sort out the event roles etc.
# Flow:
# For each role:
for role in Role.objects.all():
print 'Role ID %s' % role.id
print 'Role is %s' % role
try:
participants_exist = data['role'][role.id]['participants']
except:
participants_exist = False
#.........这里部分代码省略.........