当前位置: 首页>>代码示例>>Python>>正文


Python EventForm.is_valid方法代码示例

本文整理汇总了Python中events.forms.EventForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python EventForm.is_valid方法的具体用法?Python EventForm.is_valid怎么用?Python EventForm.is_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在events.forms.EventForm的用法示例。


在下文中一共展示了EventForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: edit_event_view

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def edit_event_view(request, event_pk):
    ''' The view to edit an event. '''
    page_name = "Edit Event"
    profile = UserProfile.objects.get(user=request.user)
    event = get_object_or_404(Event, pk=event_pk)
    if event.owner != profile and not request.user.is_superuser:
        return HttpResponseRedirect(
            reverse('events:view', kwargs={"event_pk": event_pk}),
            )
    event_form = EventForm(
        request.POST or None,
        profile=profile,
        instance=event,
        )
    if event_form.is_valid():
        event = event_form.save()
        messages.add_message(
            request, messages.SUCCESS,
            MESSAGES['EVENT_UPDATED'].format(event=event.title),
            )
        return HttpResponseRedirect(
            reverse('events:view', kwargs={"event_pk": event_pk}),
            )
    return render_to_response('edit_event.html', {
        'page_name': page_name,
        'event_form': event_form,
        }, context_instance=RequestContext(request))
开发者ID:naderm,项目名称:farnsworth,代码行数:29,代码来源:views.py

示例2: post

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
    def post(self, request):
        # Temporary part of the method to create tickets for test purposes
        if 'test_baseticket' in request.POST:
            response = create_test_baseticket()
            return response

        event_form = EventForm(request.POST)
        base_ticket_price_form = BaseTicketPriceForm(request.POST)
        upload_form = UploadBaseTicketNew(request.POST, request.FILES)

        if not(event_form.is_valid() and base_ticket_price_form.is_valid() and upload_form.is_valid()):
            return render(request, self.template_name,
                              {'upload_form': upload_form, 'event_form': event_form,
                               'base_ticket_price_form': base_ticket_price_form, 'pdf_exists': 'false'})

        # if the forms were valid
        pdf_file = request.FILES['pdf_file']
        price = request.POST.get('price')

        pdf_object = ProcessBaseTicket(pdf_file)

        if not pdf_object.successful:
            messages.add_message(request, messages.ERROR, pdf_object.message)
            return render(request, self.template_name,
                              {'upload_form': upload_form, 'event_form': event_form,
                               'base_ticket_price_form': base_ticket_price_form, 'pdf_exists': 'false'})

        event = event_form.save()
        self.create_base_ticket(pdf_object, event, price)

        messages.add_message(request, messages.SUCCESS, message_text.event_creation_successful)
        return redirect('buy_ticket:available_tickets', event.id)
开发者ID:MGonen,项目名称:ticket-exchange,代码行数:34,代码来源:views.py

示例3: create

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def create(request):
    form = EventForm(request.POST or None)
    if form.is_valid():
        event = form.save(commit=False)
        event.creator = request.user
        g_d = None
        for  word in event.description.split():
            try:
                g_d = parse(word, fuzzy=True)
                break
            except :
                continue
        event.start_date = g_d
        event.save()

        #request.user.message_set.create(message="Event posted successfully.")

        if 'next' in request.POST:
            next = request.POST['next']
        else:
            next = reverse('ev_tonight')

        return HttpResponseRedirect(next)
    else:
        return render_to_response(
            'event/create.html',
            {'form':form},
            context_instance = RequestContext(request)
        )
开发者ID:jonycse,项目名称:django_project,代码行数:31,代码来源:views.py

示例4: add

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def add(request, app_label, model_name, id):
    ''' Tag an event to another model object '''

    try:
        ct = ContentType.objects.get(\
                app_label = app_label,
                model = model_name)
        obj = ct.get_object_for_this_type( id=id )

    except:
        return HttpResponseNotFound()

    if request.method == 'POST':
        #request.POST.update( { 'owner':request.user.id, 'object_id':id,
        #        'content_type':ct.id, 'content_obj': obj, } )
        form = EventForm(request.POST)

        if form.is_valid():
            ev = form.save(commit=False)
            ev.owner = request.user
            ev.object_id = obj.id
            ev.content_type = ct
            ev.save()


            return HttpResponseRedirect(ev.get_absolute_url())

    else:
        form = EventForm()

    context = { 'form':form, 'object':obj, 'content_type':ct, }
    context.update(locals())

    return render_to_response('events/events_add.html', context,\
            context_instance = RequestContext(request))
开发者ID:skyl,项目名称:django-eventpickrs,代码行数:37,代码来源:views.py

示例5: create

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def create(request):
	form = EventForm(request.POST or None)
	if form.is_valid():
		event = form.save(commit=False)
		event.creator = request.user
		guessed_date = None

		for word in event.description.split():
			try:
				guessed_date = parse(word)
				break
			except ValueError:
				continue
		event.start_date = guessed_date
		event.save()
		messages.success(request, "Your event was posted")
		if 'next' in request.POST:
			next = request.POST['next']
		else:
			next = reverse('ev_tonight')
		return HttpResponseRedirect(next)
	return render_to_response(
		'events/create.html',
		{'form':form},
		context_instance = RequestContext(request)
	)
开发者ID:KimHyoJin,项目名称:startthedart_2013312621,代码行数:28,代码来源:views.py

示例6: test_only_title_and_state_required

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def test_only_title_and_state_required():
    form_data = {
        'title': 'wtf',
        'status': 'i',
        'organizer': user,
    }
    form = EventForm(data=form_data)

    assert form.is_valid(), form.errors
开发者ID:tomsimonart,项目名称:incubator,代码行数:11,代码来源:test_forms.py

示例7: test_ready_must_have_date

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def test_ready_must_have_date():
    form_data = {
        'title': 'wtf',
        'status': 'r',
    }
    form = EventForm(data=form_data)

    assert not form.is_valid(), form.errors
    assert 'Un événement prêt doit avoir une date de début' in form.errors['__all__']
开发者ID:tomsimonart,项目名称:incubator,代码行数:11,代码来源:test_forms.py

示例8: add

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def add(request):
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save()
            return HttpResponseRedirect(reverse('event-edit', args=[event.id])+'?after_add=1')
    else:
        form = EventForm()

    return render_to_response('event_add.html', locals())
开发者ID:emperorcezar,项目名称:OpenConnect,代码行数:12,代码来源:views.py

示例9: test_stop_must_be_after_start

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def test_stop_must_be_after_start():
    form_data = {
        'title': 'wtf',
        'status': 'i',
        'start': datetime(2100, 1, 1),
        'stop': datetime(2000, 1, 1)
    }
    form = EventForm(data=form_data)

    assert not form.is_valid()
    assert 'La date de fin ne peut être avant la date de début' in form.errors['__all__']
开发者ID:tomsimonart,项目名称:incubator,代码行数:13,代码来源:test_forms.py

示例10: create_event

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def create_event(request):
    """
        Creates an event.
    """
    form = EventForm()
    if request.method == "POST":
        form = EventForm(request.POST,request.FILES)
        if form.is_valid():
            event = form.save()
            return HttpResponseRedirect(reverse("event",args=(event.pk,)))
    return render_to_response("events/event_form.html",{"form":form},context_instance=RequestContext(request))
开发者ID:sanchitbareja,项目名称:cetweb,代码行数:13,代码来源:views.py

示例11: new_event

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def new_event(request):
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save(commit=False)
            event.user = request.user
            event.save()
            return HttpResponseRedirect('/events')
    else:
        event = Event()
        form = EventForm(instance=event)
    return render_to_response('events/new_event.html', {'form': form}, context_instance=RequestContext(request))
开发者ID:sigurdga,项目名称:nidarholm,代码行数:14,代码来源:views.py

示例12: edit_event

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def edit_event(request, id):
    if request.method == 'POST':
        event = get_object_or_404(Event, id=id)
        form = EventForm(request.POST, instance=event)
        if form.is_valid():
            form.save(commit=False)
            event.save()
            return HttpResponseRedirect(event.get_absolute_url())
    else:
        event = get_object_or_404(Event, id=id)
        form = EventForm(instance=event)
    return render_to_response('events/new_event.html', {'form': form, 'object': event}, context_instance=RequestContext(request))
开发者ID:sigurdga,项目名称:nidarholm,代码行数:14,代码来源:views.py

示例13: test_no_stop_but_start

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def test_no_stop_but_start():
    form_data = {
        'title': 'wtf',
        'status': 'i',
        'start': datetime(2000, 1, 1),
        'organizer': user,
    }
    form = EventForm(data=form_data)

    assert form.is_valid(), form.errors
    assert form.cleaned_data['start'] == form.cleaned_data['stop']
    assert form.cleaned_data['start'].year == 2000
开发者ID:tomsimonart,项目名称:incubator,代码行数:14,代码来源:test_forms.py

示例14: event_create

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def event_create(request):
    if request.method == 'POST':
        eventform = EventForm(request.POST)
        if eventform.is_valid():
            eventform.save()
    else:
        eventform = EventForm()

    print eventform
    return render_to_response('events/event-create.html',
                              {'eventform': eventform},
                              context_instance=RequestContext(request)
                             )
开发者ID:bmease,项目名称:thanksPearl,代码行数:15,代码来源:views.py

示例15: list_all_events_view

# 需要导入模块: from events.forms import EventForm [as 别名]
# 或者: from events.forms.EventForm import is_valid [as 别名]
def list_all_events_view(request):
    ''' A list view of all events.  Part of archives. '''
    page_name = "Archives - All Events"
    profile = UserProfile.objects.get(user=request.user)

    event_form = EventForm(
        request.POST if "post_event" in request.POST else None,
        profile=profile,
        )

    if event_form.is_valid():
        event_form.save()
        return HttpResponseRedirect(reverse('events:all'))

    # a pseudo-dictionary, actually a list with items of form (event, ongoing,
    # rsvpd, rsvp_form, already_past), where ongoing is a boolean of whether the
    # event is currently ongoing, rsvpd is a boolean of whether the user has
    # rsvp'd to the event
    events_dict = list()
    for event in Event.objects.all():
        rsvp_form = None
        if event.end_time > now():
            rsvp_form = RsvpForm(
                request.POST if "rsvp-{0}".format(event.pk) in request.POST else None,
                instance=event,
                profile=profile,
                )
            if rsvp_form.is_valid():
                rsvpd = rsvp_form.save()
                if rsvpd:
                    message = MESSAGES['RSVP_ADD'].format(event=event.title)
                else:
                    message = MESSAGES['RSVP_REMOVE'].format(event=event.title)
                messages.add_message(request, messages.SUCCESS, message)
                return HttpResponseRedirect(reverse('events:all'))

        ongoing = event.start_time <= now() and event.end_time >= now()
        rsvpd = profile in event.rsvps.all()
        events_dict.append(
            (event, ongoing, rsvpd, rsvp_form)
            )

    if request.method == "POST":
        messages.add_message(request, messages.ERROR, MESSAGES["EVENT_ERROR"])

    return render_to_response('list_events.html', {
        'page_name': page_name,
        'events_dict': events_dict,
        'now': now(),
        'event_form': event_form,
        }, context_instance=RequestContext(request))
开发者ID:naderm,项目名称:farnsworth,代码行数:53,代码来源:views.py


注:本文中的events.forms.EventForm.is_valid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。