本文整理汇总了Python中events.models.Event.save方法的典型用法代码示例。如果您正苦于以下问题:Python Event.save方法的具体用法?Python Event.save怎么用?Python Event.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类events.models.Event
的用法示例。
在下文中一共展示了Event.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_event
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def save_event(request):
""" Create a new event """
print "In Save Event"
if request.method != "POST":
print "Save brew received a non post"
return HttpResponseRedirect(reverse("events_userhome"))
name = request.POST.get('event_name')
description = request.POST.get("event_description")
# On empty POST request, return to user home.
if(name.strip() == "" and description.strip() == ""):
print "Empty form received"
return HttpResponseRedirect(reverse("events_userhome"))
# Create a new event and save it.
new_event = Event()
new_event.name = name
new_event.description = description
new_event.save()
print "New Event Created ", new_event.ident
print type(new_event.ident), str(new_event.ident)
# Save the user as the host of the new event
user = request.user.get_profile()
admin = Host()
admin.uid = user
admin.eid = new_event
admin.save()
return HttpResponseRedirect(reverse("events.views.event",
args=(new_event.ident,)))
示例2: new_event_submit
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def new_event_submit(request):
checked_checklist_items = request.POST.getlist('checklist_items')
name = request.POST['name']
description = request.POST['description']
price = request.POST['price']
try:
event = Event(
name=name,
description=description,
price=price
)
event.save()
for item in checked_checklist_items:
event.checklist_items.add(item)
messages.success(request, "Your event was saved successfully.")
except:
e = sys.exc_info()[0]
messages.error(request, "There was an error saving your event.")
print(e)
return redirect('events:index')
示例3: TestOccurrencePool
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
class TestOccurrencePool(TestCase):
def setUp(self):
rule = Rule(frequency="WEEKLY")
rule.save()
cal = Calendar(name="MyCal")
cal.save()
data = {
'title': 'Recent Event',
'start': datetime.datetime(2008, 1, 5, 8, 0),
'end': datetime.datetime(2008, 1, 5, 9, 0),
'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0),
'rule': rule,
'calendar': cal
}
self.recurring_event = Event(**data)
self.recurring_event.save()
def testPeriodFromPool(self):
"""
Test that period initiated with occurrence_pool returns the same occurrences as "straigh" period
in a corner case whereby a period's start date is equal to the occurrence's end date
"""
start = datetime.datetime(2008, 1, 5, 9, 0)
end = datetime.datetime(2008, 1, 5, 10, 0)
parent_period = Period(Event.objects.all(), start, end)
period = Period(parent_period.events, start, end, parent_period.get_persisted_occurrences(), parent_period.occurrences)
self.assertEquals(parent_period.occurrences, period.occurrences)
示例4: save
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def save(self):
if not self.instance:
event = Event(
owner=self.profile,
title=self.cleaned_data['title'],
description=self.cleaned_data['description'],
location=self.cleaned_data['location'],
start_time=self.cleaned_data['start_time'].replace(tzinfo=utc),
end_time=self.cleaned_data['end_time'].replace(tzinfo=utc),
)
else:
self.instance.title = self.cleaned_data['title']
self.instance.description = self.cleaned_data['description']
self.instance.location = self.cleaned_data['location']
self.instance.start_time = self.cleaned_data['start_time'].replace(tzinfo=utc)
self.instance.end_time = self.cleaned_data['end_time'].replace(tzinfo=utc)
self.instance.cancelled = self.cleaned_data['cancelled']
event = self.instance
event.save()
if self.cleaned_data['rsvp'] and \
self.profile.user.username != ANONYMOUS_USERNAME:
event.rsvps.add(self.profile)
as_manager = self.cleaned_data['as_manager']
if as_manager:
event.as_manager = as_manager
event.save()
return event
示例5: save
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def save(self):
if not self.instance:
event = Event(
owner=self.profile,
title=self.cleaned_data['title'],
description=self.cleaned_data['description'],
location=self.cleaned_data['location'],
start_time=self.cleaned_data['start_time'],
end_time=self.cleaned_data['end_time'],
)
else:
self.instance.title = self.cleaned_data['title']
self.instance.description = self.cleaned_data['description']
self.instance.location = self.cleaned_data['location']
self.instance.start_time = self.cleaned_data['start_time']
self.instance.end_time = self.cleaned_data['end_time']
self.instance.cancelled = self.cleaned_data['cancelled']
event = self.instance
event.save()
if self.cleaned_data['rsvp'] and \
self.profile.user.username != ANONYMOUS_USERNAME:
event.rsvps.add(self.profile)
as_manager = self.cleaned_data['as_manager']
if as_manager:
event.as_manager = as_manager
else:
event.as_manager = None
event.save()
for profile in event.rsvps.all():
if profile.user == self.profile.user:
continue
notify.send(self.profile.user, verb="updated", action=event,
recipient=profile.user)
return event
示例6: event
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def event(request):
model = Event
event = Event.objects.all()
# Handle file upload
if request.method == 'POST':
form = EventForm(request.POST , request.FILES)
if form.is_valid():
event = Event(user=request.user, snap=request.FILES['snap'], eventtype = request.POST['eventtype'],duration = request.POST['duration'],dresscode = request.POST['duration'],date_event = request.POST['date_event'], description = request.POST['description'], place = request.POST['place'],)
event.save()
# Redirect to the document list after POST
return redirect('/events/')
else:
form = EventForm() # A empty, unbound form
event = Event.objects.all()
# Load documents for the list page
# Render list page with the documents and the form
return render_to_response(
'events/event.html',
{ 'event': event,'form': form,},
context_instance=RequestContext(request)
)
示例7: ical_import
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def ical_import(request, group_slug=None,
template_name="calendars/ical_import.html"):
"""docstring for invitation"""
calendar = get_object_or_404(Calendar, slug=group_slug)
is_member = calendar.user_is_member(request.user)
if request.method == "POST":
if request.user.is_authenticated():
if is_member:
ical_url = request.POST.get('ical_url', None)
ical_file = request.FILES.get('ical_file', None)
if ical_url or ical_file:
if ical_url:
feed = urllib2.urlopen(ical_url)
if ical_file:
feed = ical_file
ical = vobject.readOne(feed.read(), ignoreUnreadable=True)
for ical_event in ical.components():
if getattr(ical_event, 'summary', None) and getattr(ical_event, 'dtstart', None):
event = Event(
title = ical_event.summary.value,
start_time = ical_event.dtstart.value.replace(tzinfo=None),
end_time = getattr(ical_event, 'dtend', None) and ical_event.dtend.value.replace(tzinfo=None),
body = getattr(ical_event, 'description', None) and ical_event.description.value,
location = getattr(ical_event, 'location', None) and ical_event.location.value,
)
calendar.associate(event, commit=False)
event.creator = request.user
event.save()
if getattr(ical_event, 'rruleset'):
today_tz = datetime.datetime.now(tzutc())
endday_tz = today_tz + datetime.timedelta(30)
dates = ical_event.rruleset.between(today_tz, endday_tz)
for date in dates:
if date != ical_event.dtstart.value:
delta = date - ical_event.dtstart.value
if getattr(ical_event, 'dtend', None):
end_date = ical_event.dtend.value + delta
else:
end_date = None
event = Event(
title = ical_event.summary.value,
start_time = date.replace(tzinfo=None),
end_time = end_date.replace(tzinfo=None) if end_date else None,
body = getattr(ical_event, 'description', None) and ical_event.description.value,
location = getattr(ical_event, 'location', None) and ical_event.location.value,
)
calendar.associate(event, commit=False)
event.creator = request.user
event.save()
messages.add_message(request, messages.SUCCESS,
ugettext("Successfully imported events from ical")
)
else:
return HttpResponseForbidden()
return render_to_response(template_name, {
"calendar": calendar,
"group": calendar, # @@@ this should be the only context var for the calendar
}, context_instance=RequestContext(request))
示例8: save
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def save(self):
if not self.instance:
event = Event(
owner=self.profile,
title=self.cleaned_data["title"],
description=self.cleaned_data["description"],
location=self.cleaned_data["location"],
start_time=self.cleaned_data["start_time"],
end_time=self.cleaned_data["end_time"],
)
else:
self.instance.title = self.cleaned_data["title"]
self.instance.description = self.cleaned_data["description"]
self.instance.location = self.cleaned_data["location"]
self.instance.start_time = self.cleaned_data["start_time"]
self.instance.end_time = self.cleaned_data["end_time"]
self.instance.cancelled = self.cleaned_data["cancelled"]
event = self.instance
event.save()
if self.cleaned_data["rsvp"] and self.profile.user.username != ANONYMOUS_USERNAME:
event.rsvps.add(self.profile)
as_manager = self.cleaned_data["as_manager"]
if as_manager:
event.as_manager = as_manager
else:
event.as_manager = None
event.save()
return event
示例9: test_root_url_shows_all_events
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def test_root_url_shows_all_events(self):
# set up some events
user = User.objects.create(username="john")
event1 = Event(
title='PyCon 2013',
slug='pycon-2013',
description='The most advanced conference about Python',
where='Santa Clara, California',
posted_by=user,
datetime = timezone.now())
event1.save()
event2 = Event(
title='PyData 2013',
slug='pydata-2013',
description='The most advanced conference about Python and Data Analysis',
where='Santa Clara, California',
posted_by=user,
datetime = timezone.now())
event2.save()
response = self.client.get('/events/')
self.assertTemplateUsed(response, 'event_list.html')
self.assertIn(event1.title, response.content)
self.assertIn(event1.slug, response.content)
self.assertIn(event1.description, response.content)
self.assertIn(event2.title, response.content)
示例10: addEvents
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def addEvents():
print 'Adding Events ...'
c = Court.objects.count()
u = User.objects.count()
s = Sport.objects.count()
for i in range(5000):
e = Event()
year = 2016 + randint(0, 50)
month = randint(1, 12)
day = randint(1,30) if ( month != 2 ) else randint(1, 28)
hour = randint(1, 23) - 2
hour = 0 if (hour < 0) else hour
minute = randint(0, 59)
e.dateTime = timezone.datetime(year=year, month=month, day=day,
hour=hour, minute=minute)
e.endTime = timezone.datetime(year=year, month=month, day=day,
hour=hour+2, minute=minute)
e.court = Court.objects.all()[randint(0,c-1)]
e.sport = Sport.objects.all()[randint(0,s-1)]
e.creator = User.objects.all()[randint(0,u-1)]
e.duration = 2
e.save()
try:
for i in range(randint(1,50)):
e.participants.add(User.objects.get(id=randint(2,u)))
except(User.DoesNotExist):
pass
e.save()
示例11: events_list
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def events_list(request):
func_return = _init_facebook_app(request)
if(func_return != False):
return func_return
try:
graph, user, sys_user = _get_facebook_app(request)
if sys_user is None:
return HttpResponseRedirect("/facebook/setup/")
except facebook.GraphAPIError:
del request.session["access_token"]
return HttpResponseRedirect("http://apps.facebook.com/"+ settings.FACEBOOK_APP_ID +"/")
if request.method == 'POST':
events_ids = request.POST.getlist("object_events")
for event_id in events_ids:
event = graph.get_object(event_id)
image_url = "https://graph.facebook.com/" + event["id"] + "/picture?type=large"
img_temp = NamedTemporaryFile(delete=True)
img_temp.write(urllib2.urlopen(image_url).read())
img_temp.flush()
user_event = Event(
title = event["name"],
from_date = dateutil.parser.parse(event["start_time"]),
to_date = dateutil.parser.parse(event["end_time"]),
address = event["location"],
user = sys_user.username,
add_user = sys_user,
category = EventCategory.objects.get(id=1),
status = 2,
)
if "description" in event:
user_event.description = event["description"]
user_event.image.save(event["id"] + ".jpg", File(img_temp));
user_event.slug = SlugifyUniquely( event["name"], user_event.__class__)
user_event.save()
if len(events_ids) > 0:
_add_flash_message(request, "Your events has been added")
return HttpResponseRedirect( reverse('facebook_events_list') )
events = graph.get_connections(user["id"], "events")
for event in events["data"]:
event["start_time"] = dateutil.parser.parse(event["start_time"])
event["end_time"] = dateutil.parser.parse(event["end_time"])
event["picture_url"] = "https://graph.facebook.com/" + event["id"] + "/picture?type=normal"
return dict(
user = user,
events = events,
message = _get_flash_message(request),
)
示例12: create_tool
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def create_tool(sender, instance, created, **kwargs):
"""
If we are creating a tool, make a creation event.
"""
if created:
event = Event(tool=instance, event_type='Oprettelse')
event.save()
示例13: test_event_get_occurrences_after
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def test_event_get_occurrences_after(self):
recurring_event = Event(**self.recurring_data)
recurring_event.save()
occurrences = recurring_event.get_occurrences(start=datetime.datetime(2008, 1, 5),
end=datetime.datetime(2008, 1, 6))
occurrence = occurrences[0]
occurrence2 = recurring_event.occurrences_after(datetime.datetime(2008, 1, 5)).next()
self.assertEqual(occurrence, occurrence2)
示例14: test_get_occurrence
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def test_get_occurrence(self):
event = Event(**self.recurring_data)
event.save()
occurrence = event.get_occurrence(datetime.datetime(2008, 1, 5, 8, 0))
self.assertEqual(occurrence.start, datetime.datetime(2008, 1, 5, 8))
occurrence.save()
occurrence = event.get_occurrence(datetime.datetime(2008, 1, 5, 8, 0))
self.assertTrue(occurrence.pk is not None)
示例15: _save_recurring_superevents
# 需要导入模块: from events.models import Event [as 别名]
# 或者: from events.models.Event import save [as 别名]
def _save_recurring_superevents(self, recurring_groups):
groups = map(frozenset, recurring_groups.values())
aggregates = set()
for group in groups:
kulke_ids = set(map(make_kulke_id, group))
superevent_aggregates = EventAggregate.objects.filter(members__event__id__in=kulke_ids).distinct()
cnt = superevent_aggregates.count()
if cnt > 1:
print("Error: the superevent has an ambiguous aggregate group.")
print("Aggregate ids: {}, group: {}".format(superevent_aggregates.values_list("id", flat=True), group))
continue
events = Event.objects.filter(id__in=kulke_ids)
if events.count() < 2:
continue
aggregate = None
if cnt == 0:
if len(group) == 1:
# Do not create aggregates of only one.
continue
aggregate = EventAggregate()
aggregate.save()
super_event = Event(
publisher=self.organization,
super_event_type=Event.SuperEventType.RECURRING,
data_source=DataSource.objects.get(pk="kulke"), # TODO
id="linkedevents:agg-{}".format(aggregate.id),
)
super_event.save()
aggregate.super_event = super_event
aggregate.save()
for event in events:
member = EventAggregateMember.objects.create(event=event, event_aggregate=aggregate)
elif cnt == 1:
aggregate = superevent_aggregates.first()
if len(group) == 1:
events = Event.objects.get(pk=make_kulke_id(group.pop()))
# The imported event is not part of an aggregate
# but one was found it in the db. Remove the event
# from the aggregate. This is the only case when
# an event is removed from a recurring aggregate.
aggregate.members.remove(events)
else:
for event in events:
try:
member = EventAggregateMember.objects.create(event=event, event_aggregate=aggregate)
except IntegrityError:
# Ignore unique violations. They
# ensure that no duplicate members are added.
pass
for event in events:
event.super_event = aggregate.super_event
event.save()
aggregates.add(aggregate)
return aggregates