Esempio n. 1
0
def edit(request, pk):
    occurrence = get_object_or_404(
        klass=Occurrence, 
        pk=pk
    )
    osm_formset = OSMFormSet(
        data=request.POST or None, 
        instance=occurrence
    )
    occurrence_form = OccurrenceForm(
        data=request.POST or None,
        instance=occurrence
    )
    if occurrence_form.is_valid():
        
        occurrence_form.save(auth.get_user(request))
        messages.success(request, u"Material editado com sucesso.")
        return redirect('occurrence_list')

    template_context = {
        'occurrence': occurrence,
        'occurrence_form': occurrence_form,
        'osm_formset': osm_formset,
    }
    return render(
        request=request,
        template_name='occurrence/edit.html',
        dictionary=template_context
    )
Esempio n. 2
0
def add(request):
    osm_formset = OSMFormSet(data=request.POST or None, instance=Occurrence())
    occurrence_form = OccurrenceForm(data=request.POST or None)
    if occurrence_form.is_valid() and osm_formset.is_valid():
        occurrence = occurrence_form.save(auth.get_user(request))
        osm_formset.instance = occurrence
        osm_formset.save(auth.get_user(request))
        messages.success(request, u"Material salvo com sucesso.")
        return redirect('occurrence_list')

    template_context = {
        'occurrence_form': occurrence_form,
        'osm_formset': osm_formset,
    }
    return render(request=request,
                  template_name='occurrence/add.html',
                  dictionary=template_context)
Esempio n. 3
0
def edit(request, pk):
    occurrence = get_object_or_404(klass=Occurrence, pk=pk)
    osm_formset = OSMFormSet(data=request.POST or None, instance=occurrence)
    occurrence_form = OccurrenceForm(data=request.POST or None,
                                     instance=occurrence)
    if occurrence_form.is_valid():

        occurrence_form.save(auth.get_user(request))
        messages.success(request, u"Material editado com sucesso.")
        return redirect('occurrence_list')

    template_context = {
        'occurrence': occurrence,
        'occurrence_form': occurrence_form,
        'osm_formset': osm_formset,
    }
    return render(request=request,
                  template_name='occurrence/edit.html',
                  dictionary=template_context)
Esempio n. 4
0
def add(request):
    osm_formset = OSMFormSet(
        data=request.POST or None, 
        instance=Occurrence()
    )
    occurrence_form = OccurrenceForm(
        data=request.POST or None
    )
    if occurrence_form.is_valid() and osm_formset.is_valid():
        occurrence = occurrence_form.save(auth.get_user(request))
        osm_formset.instance = occurrence
        osm_formset.save(auth.get_user(request))
        messages.success(request, u"Material salvo com sucesso.")
        return redirect('occurrence_list')
    
    template_context = {
        'occurrence_form': occurrence_form,
        'osm_formset': osm_formset,
    }
    return render(
        request=request,
        template_name='occurrence/add.html',
        dictionary=template_context
    )