本文整理汇总了Python中models.Event.save方法的典型用法代码示例。如果您正苦于以下问题:Python Event.save方法的具体用法?Python Event.save怎么用?Python Event.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Event
的用法示例。
在下文中一共展示了Event.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_event
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def save_event(request):
if request.method == 'GET':
q = request.GET.get("js_kind_value")
if q:
pkind = transform_text(q)
kind = verify_kind_exists('kind_value',pkind)
if kind is None:
if (verify_get_param(request,'js_gender_value') and verify_get_param(request,'js_age_value')):
new_kind = Kind(kind_value= pkind,gender_target=request.GET.get('js_gender_value'), age_target=request.GET.get('js_age_value'))
new_kind.save()
kind = Kind.objects.get(kind_value=pkind)
elif request.GET.get('kind_choice'):
kind = verify_kind_exists('id',request.GET.get('kind_choice'))
print kind
else:
pass
event_name_value = request.GET.get("js_event_name")
description_event_value = request.GET.get("js_event_description")
if event_name_value is not '' and description_event_value is not '':
event_name_value = transform_text(event_name_value)
existent_name = verify_event_properties_exists('name', event_name_value)
description_event_value = transform_text(description_event_value)
existent_description = verify_event_properties_exists('description', description_event_value)
# An event with the passed name or description could not be already stored..
if existent_description is None and existent_name is None:
new_event = Event(name=event_name_value, description=description_event_value, creation_date = datetime.now, kind_event = kind)
new_event.save()
return determine_interested_people(request, new_event)
return render_to_response('event_creation/home.html', {'email_address' : request.session['email_address_user'],'error_message' : 'Event name/description already exist','kind_form' : KindEventForm(request.GET)}, RequestContext(request))
return render_to_response('event_creation/home.html', {'email_address' : request.session['email_address_user'],'error_message' : 'An error has occurred','kind_form' : KindEventForm(request.GET)}, RequestContext(request))
return render_to_response('event_creation/home.html', {'email_address' : request.session['email_address_user'],'error_message': 'An error has occurred','kind_form' : KindEventForm(request.GET)}, RequestContext(request))
示例2: index
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def index(request, year, month):
month = int(month)
year = int(year)
calendar = newcalendar.LinkyCalendar()
calendar1 = CalendarVarOne()
calendar2 = CalendarVarTwo()
if request.method == "POST":
form = eventform(request.POST)
if form.is_valid():
date = form.cleaned_data['date']
description = form.cleaned_data['description']
ev = Event(date=date, description=description)
ev.save()
data = {}
for event in Event.objects.all():
if event.date.year == year and \
event.date.month == month:
data[event.date.day] = fix_date(event.date.day)
form = eventform()
firstmonth = calendar.formatmonth(year, month, data=data)
secondmonth = calendar1.formatmonth(year, month, data=data)
thirdmonth = calendar2.formatmonth(year, month, data=data)
return render_to_response('index.html', {"calendar1":unicode(firstmonth),
"calendar2":unicode(secondmonth),
"calendar3":unicode(thirdmonth),
"form":form,
},
context_instance=RequestContext(request),
)
示例3: test_model_event
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def test_model_event(self):
"""Test Event model"""
event = Event(name="Test", end=datetime.now())
event.save()
self.assertNotEquals(event.id, None)
event.delete()
示例4: event_add_view
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def event_add_view(request, calendar_id, year, month, day):
calendar = Calendar.objects.get(id=calendar_id)
if request.method == 'POST':
form = EventForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
event = Event()
event.begin_date = cd['begin_date']
event.name = cd['name']
event.owned_by = request.user
event.calendar=calendar
event.description = cd['description']
event.end_date = cd['end_date']
event.save()
guests = []
for subscriber in calendar.subscribers.all():
guest = EventGuest(event=event, user=subscriber, notify_date=timezone.now())
guest.save()
guests.append(guest)
event.guests = guests
event.save()
return HttpResponseRedirect('/event/'+str(event.id))
else:
form = EventForm()
begin_date = datetime(year=int(year), month=int(month), day=int(day), hour=12)
end_date = datetime(year=int(year), month=int(month), day=int(day), hour=15)
# form.begin_date = begin_date
t = get_template('event_edit.html')
html = t.render( RequestContext(request, {'form': form, 'calendar': calendar, 'begin_date':begin_date, 'end_date': end_date, 'date': begin_date}))
return HttpResponse(html)
示例5: indexsignup
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def indexsignup(request):
form = AccountsSignupForm(request.POST)
print form.is_valid()
if form.is_valid():
email = form.cleaned_data['email']
password = form.cleaned_data['password']
realname = form.cleaned_data['realname']
gender = form.cleaned_data['gender']
student = Student.create_user(username=email, email=email, password=password)
url_number = len(Student.objects)
student.url_number = url_number
public_profile = Public_Profile(realname=realname, gender=gender, face=STATIC_URL + 'img/face.png')
student.public_profile = public_profile
student.save()
sscard = S_S_Card(user=student)
sscard.save()
event = Event(user=student)
event.save()
user = authenticate(username=email, password=password)
request.session.set_expiry(0)
if user is not None and user.is_active:
login(request, user)
return HttpResponseRedirect('/')
else:
return render_to_response('404.html', {'STATIC_URL':STATIC_URL})
示例6: _save_event
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def _save_event(self, event):
"""Save the given event"""
uid = event['id']
try:
local_event = Event.objects.get(uid=uid)
except:
local_event = Event(uid=uid)
local_event.calendar = self.gcal
local_event.author = event['creator']
local_event.title = event['summary']
local_event.description = event.get('description', None)
local_event.location = event.get('location', None)
try:
local_event.start = parse(event['start']['dateTime'])
except:
local_event.start = parse(event['start']['date'])
try:
local_event.end = parse(event['end']['dateTime'])
except:
local_event.end = parse(event['end']['date'])
status = 'active'
if event['status'] == 'cancelled':
status = 'cancelled'
local_event.status = status
local_event.save()
return local_event
示例7: update
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def update(request):
xml = getXML()
updateHour = datetime.datetime.now()
entry = Update.objects.get(id=1)
entry.hour = updateHour
entry.save()
content = xml.findAll("contenido")
events = Event.objects.all()
for line in content:
(title, dateTime, hourEnd, price, eventType, duration, description, url) = getEvent(line)
found = False
for event in events:
if (event.title == title):
if (str(event.date) == str(dateTime)):
found = True
if (found == False):
entry = Event(title=title, date=dateTime, dateEnd=hourEnd, price=price, eventType=eventType, duration=duration, url=url, description=description, likes=0)
entry.save()
return HttpResponseRedirect("/todas")
示例8: save
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def save(self, request):
event = Event()
start_date = self.cleaned_data['start_date']
start_time = self.cleaned_data['start_time']
end_time = self.cleaned_data['end_time']
event.start_time = datetime.combine(start_date, start_time)
event.end_time = datetime.combine(start_date, end_time)
event.event_name = self.cleaned_data['event_name']
event.event_location = self.cleaned_data['event_location']
event.event_organizer = self.cleaned_data['event_organizer']
event.event_description = self.cleaned_data['event_description']
event.event_website = self.cleaned_data['event_website']
event.save()
acl = ACLUserEvent()
acl.user = request.user
acl.event = event
acl.save()
discussiondefs = (
('PR', _(u'Discussion of the upcoming %s'), _(u'Discuss the upcoming event %s before it actually happens.')),
('LI', _(u'Live discussion of %s'), _(u'Discuss the ongoing event %s live.')),
('PO', _(u'Post-hoc discussion of %s'), _(u'Discuss %s after the facts.'))
)
for s in discussiondefs:
thread = Thread()
thread.time = datetime.now()
thread.user = request.user
thread.event = event
thread.thread_type = s[0];
thread.title = s[1] % (event.event_name)
thread.description = s[2] % (event.event_name)
thread.save()
示例9: sheet_event
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def sheet_event (self, id):
""" Create an event """
sheet = Sheet.objects.get_or_404(id = id)
if request.method == 'GET' :
""" Get all events """
#if 'from' not in request.args or 'to' not in request.args:
# abort(400, error = 'missing arguments from and to ')
_sheetEvents = Event.objects(sheet=sheet, alive=True)
_events = [e.to_json() for e in _sheetEvents ]
return jsonify(ok=True, objects=_events),200
if request.method == 'POST':
new_event = Event(
dates = request.json.get('dates',[]),
name = request.json['name'],
event_date = request.json['event_date'],
description = request.json['description'],
location = request.json['location'],
public = request.json.get('public',True),
links = request.json.get('links',[]),
color = request.json.get('color','#fff'),
tags = request.json['tags'],
alive = True,
created_by = str(sheet.created_by),
sheet= sheet
)
new_event.save()
return jsonify(ok=True,objects=[new_event.to_json()]), 201
示例10: crawl_listing
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def crawl_listing(self, url, ctx='', **kwargs):
prefix_url = url.rsplit('/', 1)[0] + '/'
r = req.get(url)
event_id, data = re.compile(r'parse_sale_(\w+)\((.*)\);$').search(r.text).groups()
data = json.loads(data)
event = Event.objects(event_id=event_id).first()
if not event: event = Event(event_id=event_id)
for product_data in data['asins']: # ensure we download the complete data once
if 'cAsin' not in product_data:
r = req.get(url)
event_id, data = re.compile(r'parse_sale_(\w+)\((.*)\);$').search(r.text).groups()
data = json.loads(data)
product_ids = []
for product_data in data['asins']:
ret = self._parse_product(event_id, event.asin_detail_page, event.casin_soldout_info, prefix_url, product_data, ctx)
product_ids.append(ret)
if event.urgent == True:
event.urgent = False
ready = True
else: ready = False
event.product_ids = product_ids
event.update_time = datetime.utcnow()
event.save()
common_saved.send(sender=ctx, obj_type='Event', key=event_id, is_new=False, is_updated=False, ready=ready)
示例11: save
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def save(self, user):
utc = pytz.timezone('UTC')
ltz = pytz.timezone(self.cleaned_data['market'].timezone)
local_time = ltz.localize(self.cleaned_data['time'])
time = local_time.astimezone(utc)
thread = Thread(
creator = user,
subject = self.cleaned_data['title'],
site = Site.objects.get_current(),
)
thread.save()
post = Post(
thread = thread,
creator = user,
body = self.cleaned_data['post']
)
post.save()
thread.last_post = post
thread.save()
event = Event(
thread = thread,
creator = user,
description = self.cleaned_data['description'],
location = self.cleaned_data['location'],
time = time,
market = self.cleaned_data['market']
)
event.save()
return event
示例12: event
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def event(request):
if request.method == "POST":
try:
user = None
if not request.user.is_anonymous():
user = request.user
session_key = None
if request.session is not None:
session_key = request.session.session_key
e = json.loads(request.body)
details = json.dumps(e["details"])
event = Event(
dstamp=datetime.now(),
app=e["app"],
user=user,
session=session_key,
event_type=e["eventType"],
details=details,
)
event.save()
return HttpResponse("Success", content_type="text/plain", status=status.HTTP_200_OK)
except ValueError, e:
logger.error("Failed to parse event: " + str(request.body[0:1000]))
return HttpResponse("Failed to parse event", content_type="text/plain", status=status.HTTP_400_BAD_REQUEST)
except KeyError, e:
logger.error("Missing event attributes: " + str(request.body[0:1000]))
return HttpResponse(
"Missing event attributes", content_type="text/plain", status=status.HTTP_400_BAD_REQUEST
)
示例13: create
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def create(request):
if request.method == 'POST':
# save new evento
title = request.POST['title']
description = request.POST['description']
date_start = request.POST['date_start']
date_end = request.POST['date_end']
lat = request.POST['lat']
lng = request.POST['lng']
#image = request.FILES['image']
event = Event(title=title)
event.last_update = datetime.datetime.now()
event.description = description
event.date_start = datetime.datetime.strptime(date_start, '%d/%m/%Y %H:%M')
if not date_end:
event.date_end = None
else:
event.date_end = datetime.datetime.strptime(date_end, '%d/%m/%Y %H:%M')
event.location = [float(lat),float(lng)]
user_id = request.session.get('userid')
user = Account.objects(id=user_id)[0]
event.user = user
event.user_going = [user]
#im = Image.open(image)
#event.image.put(open(im))
event.save()
Account.objects(id=user_id).update_one(push__event_going=event)
return HttpResponseRedirect(reverse('event-list'))
return render_to_response('event/event_create.html',{
'request':request},
context_instance=RequestContext(request))
示例14: saveEventToDB
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def saveEventToDB(event_form,request):
event = Event()
event.category = models.CategoryOptions().get_category_by_id(int(event_form.cleaned_data['category']))
event.budget = event_form.cleaned_data['budget']
event.date = event_form.cleaned_data['date']
event.description = event_form.cleaned_data['description']
event.is_kosher = event_form.cleaned_data['is_kosher']
event.is_vegan = event_form.cleaned_data['is_vegan']
event.is_vegeterian = event_form.cleaned_data['is_vegeterian']
event.picture = event_form.cleaned_data['picture']
event.location = event_form.cleaned_data['location']
event.city = event_form.cleaned_data['city']
event.max_people = event_form.cleaned_data['max_people']
event.name = event_form.cleaned_data['name']
event.organizer_id = request.user.id
user = models.KitchenUser.objects.get(id=request.user.id)
event.save()
participant = models.EventParticipant(event = event, user = user, \
rsvp = models.RsvpOptions().get_rsvp_by_id(int(event_form.cleaned_data['rsvp'])))
participant.save()
return event.id
示例15: send_event
# 需要导入模块: from models import Event [as 别名]
# 或者: from models.Event import save [as 别名]
def send_event(actor, type, path, **context):
"""
Log an event performed by actor, of the type, on the path, and any other context arguments needed
to render notification templates.
"""
# Todo, make sure notifications aren't sent too quickly one after another.
if isinstance(path, models.Model):
object = path
path = model_sig(path)
else:
object = get_instance_from_sig(path)
# Build a context to render templates
context = context.copy()
context['actor'] = actor
context['path'] = path
context['type'] = type
context['object'] = object
context['settings'] = settings
context['DOMAIN'] = settings.DOMAIN
# Find users to be notified
subscriptions = Subscription.objects.filter(path=path, toggle=True)
users = set([s.user for s in subscriptions])
users.discard( actor )
logger.info("Event: %s %s %s", actor, type, path)
# Create the event, yo
e = Event(
actor = actor,
type = type,
path = path
)
streams = set([actor])
# Trigger event signal
# Receivers are expected to alter notify or context.
for reciever, response in event.send(sender=e, notify=users, streams=streams, **context):
if isinstance(response, dict):
context.update(response)
e.save()
for stream in streams:
e.add_to_stream(stream)
# Notify all the ya'lls
messages = []
for user in users:
notice = Notice.objects.create(user=user)
notice.events = [e]
try:
msg = render_mail(user.email, type, context)
messages.append(msg)
except Exception, x:
print "Error sending email:", x