本文整理汇总了Python中forms.EventForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python EventForm.save方法的具体用法?Python EventForm.save怎么用?Python EventForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.EventForm
的用法示例。
在下文中一共展示了EventForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createevent
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def createevent(request):
#create form and enter into database
if (request.user!=""):
if request.method == 'POST':
#print 'in request'
#print request
createevent_form=EventForm(request.POST,request.FILES)
#print 'in request'
print createevent_form
if createevent_form.is_valid():
print 'in request'
createevent_form.save()
return redirect('dashboard')
#return render_to_response('wrongpage.html', {},{})
else :
s=User.objects.get(username=request.user)
s1=Seek_User.objects.get(username=request.user)
print s1.profilePhoto
createevent_form={'createevent_form':EventForm({'username':request.user,'email':s.email,'status':'active','userid':s.id,'profilePhoto':s1.profilePhoto,'pubdate':timezone.now()})}
# print createevent_form['createevent_form']
# createevent_form['createevent_form'].update({'profilePhoto' = s1.profilePhoto})
#createevent_form['createevent_form']['profilePhoto'] = s1.profilePhoto
print createevent_form['createevent_form']['profilePhoto'].value()
return render_to_response('CreateEvent.html',createevent_form,RequestContext(request))
#return render_to_response('wrongpage.html', {},{})
return HttpResponse('hello')
示例2: create_event
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def create_event(request):
# Returns false on empty
if request.POST:
form = EventForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('')
else:
form = EventForm
## Page Context Arguments
args = {}
args.update(csrf(request))
args['form'] = form
return render(request, 'img_upload/create_event.html', args)
示例3: edit
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def edit(request, pk):
template_name = 'events/edit.html'
event = get_object_or_404(Event, pk=pk,
user=request.user)
context = {}
context['event'] = event
if request.method == 'POST':
form = EventForm(data=request.POST, instance=event)
if form.is_valid():
form.save()
return redirect('events_my')
else:
form = EventForm(instance=event)
context['form'] = form
return render(request, template_name, context)
示例4: today
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def today(request):
form = EventForm()
today = get_begining(datetime.datetime.now())
events = Event.objects.filter(author=request.user).filter(
timestamp__gt=today)
context = {
'form': form,
'events': events,
}
if request.method == 'POST':
form = EventForm(request.POST)
if form.is_valid():
event = form.save(commit=False)
event.author = request.user
try:
event.save()
context['msgs'] = ['Event added successfully.',]
except:
context['msgs'] = ['Some error occured. Please enter \
valid data.',]
context['form'] = form
else:
context['msgs'] = ['Error: You must enter a title.',]
context['form'] = form
return render_to_response('diary/today.html',
RequestContext(request, context))
示例5: create
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def create(request):
if request.POST:
form = EventForm(request.POST, request.FILES)
if form.is_valid():
Event = form.save(commit=False)
Event.author = request.user
Event.pub_date = datetime.datetime.now()
Event = Event.save()
form.save_m2m()
return HttpResponseRedirect(reverse('event.views.home'))
else:
form = EventForm()
eighthour_advanced = datetime.datetime.now()+timedelta(hours=8)
d = eighthour_advanced.strftime("%Y-%m-%d %H:%M")
return render_to_response('create_event.html',
{'form': form,
'organizations': Organization.objects.order_by('title'),
'categories': Category.objects.order_by('title'),
'users': User.objects.order_by('username'),
'time2': d },
context_instance = RequestContext(request))
示例6: edit_event
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def edit_event(request, event_name):
try:
event = Event.objects.get(name=event_name)
except Event.DoesNotExist:
raise Http404('Event does not exist')
if request.method == 'POST':
form = EventForm(request.POST, instance=event)
if (form.is_valid()):
e = form.save(commit=False)
events = Event.objects.filter(name=e.name)
# To allow editing the same event and keeping its short name.
alreadyExists = False
for ev in events:
if ev != event:
alreadyExists = True
break
if not alreadyExists:
e.save()
return redirect('feedback:index', e.name)
messages.add_message(request, messages.WARNING, 'Event with that short name already exists.')
else:
form = EventForm(instance=event)
context = {
'form': form,
'event_name': event_name,
}
return render(request, 'feedback/edit_event.html', context)
示例7: edit_event
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def edit_event(request, slug):
event = get_object_or_404(Event, slug=slug)
if request.user.speaker not in event.speakers.all():
return redirect('access')
done = False
if request.method == 'POST':
form = EventForm(request.POST, instance=event)
if form.is_valid():
form.save()
done = True
else:
form = EventForm(instance=event)
return render(request, 'access/edit_event.html',
{'title': u"Editar: " + event.title, 'form': form, 'done': done} )
示例8: create
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def create(request):
if request.POST:
form = EventForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/events')
else:
form = EventForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('form.html',
args,
context_instance=RequestContext(request))
示例9: edit
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def edit(request, event_id):
nav_selected = "events"
event = get_object_or_404(Event, id=event_id)
form = EventForm(user=request.user, instance=event, data=(request.POST or None))
if form.is_valid():
event = form.save()
messages.success(request, "%s has been changed." % event)
return redirect(event)
return render_to_response("events/edit.html", locals(), context_instance=RequestContext(request))
示例10: edit_event
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def edit_event(request, id):
context = {}
context['user'] = request.user
context['event'] = get_object_or_404(Event, id=id)
# Only the host of the event can edit (prevents url hacking)
if context['user'].geolocuser != context['event'].host:
raise Http404
if request.method=="GET":
context['form'] = EventForm(instance=context['event'])
return render(request,'events/edit.html', context)
form = EventForm(request.POST, request.FILES, instance=context['event'])
if not form.is_valid():
context['form'] = form
return redirect(reverse('edit', args=[id]))
form.save()
return redirect(reverse('eventpage', args=[id]))
示例11: create
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def create(request):
nav_selected = "events"
form = EventForm(user=request.user, data=(request.POST or None))
if form.is_valid():
event = form.save()
Record.objects.create_record(request.user, "event_create", event)
messages.success(request, "%s has been created." % event)
return redirect(event)
return render_to_response("events/create.html", locals(), context_instance=RequestContext(request))
示例12: create
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def create(request):
if request.method == "POST":
form = EventForm(request.POST)
if form.is_valid():
event = form.save()
return HttpResponseRedirect('/agenda/%i/details/' % event.pk)
else:
form = EventForm()
return render(request, 'personal_calendar/event/create.html', {'form': form})
示例13: add_event
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def add_event(request):
if request.method == 'POST':
event_form = EventForm(request.POST)
if event_form.is_valid():
event_form.save()
return HttpResponseRedirect('/admin_forms/')
else:
degree_values = Degree.objects.values('name').distinct()
news_form = NewsForm()
directory_form = DirectoryForm()
news = NewsArticle.objects.all()
events = Event.objects.all()
return render(request, 'admin_forms.html',
{'degree_values': degree_values, 'news_form': news_form, 'event_form': event_form,
'directory_form': directory_form, 'event_class': "active", 'all_news': news,
'all_events': events})
else:
return HttpResponseBadRequest("THE REQUESTED URL IS INVALID")
示例14: create
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def create(request):
data = {}
data["user"] = request.user
form = EventForm(request.POST or None)
data["form"] = form
if form.is_valid():
obj = form.save(commit=False) # get an unbound object
obj.save()
return HttpResponseRedirect("/event/%s" % obj.id)
return render_to_response("event/create.html", data)
示例15: new_event
# 需要导入模块: from forms import EventForm [as 别名]
# 或者: from forms.EventForm import save [as 别名]
def new_event(request):
from forms import EventForm
if request.method == "POST":
form = EventForm(request.POST)
if form.is_valid():
event = form.save(commit=False)
event.save()
return redirect('events', event.event_url)
else:
form = EventForm()
return render(request, 'edit_event.html', {"form": form})