コード例 #1
0
ファイル: events.py プロジェクト: hderaps/bccf
def edit(request, slug):
    event = Event.objects.get(slug=slug)
    form = EventForm(instance=event)
    form.fields['status'].widget = forms.Select(choices=CONTENT_STATUS_CHOICES)
    if request.method == 'POST':
        form = EventForm(data=request.POST, files=request.FILES, instance=event)
        if form.is_valid():
            form.save()
            messages.success(request, 'Event updated successfully.')
            return HttpResponseRedirect(form.instance.get_absolute_url())
    context = RequestContext(request, locals())
    return render_to_response('bccf/event_update.html', {}, context_instance=context)
コード例 #2
0
ファイル: events.py プロジェクト: hderaps/bccf
def create(request):
    form = EventForm(request.user, initial={
        'provider': request.user,
        'page_for': 'parent',
        'status': CONTENT_STATUS_DRAFT,
    })
    if request.method == 'POST':
        form = EventForm(request.user, data=request.POST, files=request.FILES)
        if form.is_valid():
            form.save()
            if not form.instance.parent:
                try:
                    form.instance.gparent = BCCFPage.objects.get(slug='bccf/trainings')
                    form.instance.save()
                except:
                    pass
            messages.success(request, 'Event created successfully.')
            return HttpResponseRedirect(form.instance.edit_url())
    context = RequestContext(request, locals())
    return render_to_response('bccf/event_create.html', {}, context_instance=context)