Exemplo n.º 1
0
def create_forms_article(request):

    if request.method == 'POST':
        formulario = FormArticle(request.POST)

        if formulario.is_valid():
            data_form = formulario.cleaned_data

            title = data_form.get('title')
            content = data_form['content']
            public = data_form['public']

            articulo = Article(title=title, content=content, public=public)

            articulo.save()

            #Crear mensaje flash solo se muestra una vez
            messages.success(
                request, f"Has creado correctamente el articulo {articulo.id}")

            return redirect('articulos')

    else:
        formulario = FormArticle()

    return render(request, 'create_forms_article.html', {'form': formulario})
Exemplo n.º 2
0
def create_full_article(request):

    #Si deslde el formularios nos envia datos
    if request.method == 'POST':
        formulario = FormArticle(
            request.POST)  #Limpieza y validación de datos Django

        if formulario.is_valid():  #Validacion del formulario
            data_form = formulario.cleaned_data  #Datos limpios que llegan

            title = data_form.get('title')
            content = data_form['content']
            public = data_form['public']

            articulo = Article(title=title, content=content, public=public)

            articulo.save()
            # CREACION DE MENSAJE MEDIANTE SESION FLASH
            #Creacion de sesion
            messages.success(
                request, f'Has creado correctamente el articulo {articulo.id}')
            return redirect('articulos')
            #return HttpResponse(f"{articulo.title} | {articulo.content} | {str(articulo.public)}")
    else:
        formulario = FormArticle()

    return render(request, 'create_full_article.html', {'form': formulario})
Exemplo n.º 3
0
def create_full_article(request):

    if request.method == 'POST':

        formulario = FormArticle(request.POST)

        if formulario.is_valid():
            data_form = formulario.cleaned_data

            title = data_form.get('title')
            content = data_form['content']
            public = data_form['public']

            articulo = Article(
                title = title,
                content = content,
                public = public
            )
            articulo.save()

            #Crear mensaje FLash (sesion que solo se muestra 1 vez)
            messages.success(request, f'Has creado el articulo correctamente el articulo {articulo.id}')

            return redirect('articulos')
            #return HttpResponse(articulo.title + ' ' + articulo.content + ' ' + str(articulo.public))

    else:
        formulario = FormArticle()

    return render(request, 'create_full_article.html',{
        'form': formulario
    })
Exemplo n.º 4
0
def create_full_article(request):

    if request.method == 'POST':

        formulario = FormArticle(request.POST)

        if formulario.is_valid():
            data_form = formulario.cleaned_data

            title = data_form.get('title')
            content = data_form.get('content')
            public = data_form.get('public')

            articulo = Article(
            title = title,
            content = content,
            public = public
            )    
            articulo.save()

            return redirect('articulos')

            #return HttpResponse(articulo.title + '' + articulo.content + '' + str(articulo.public))


    else:
        formulario = FormArticle()

    return render(request, 'create_full_article.html', {
        'form' : formulario
    })
Exemplo n.º 5
0
def full_create_article(request):
    title = "Formularios | create article con formularios personalizados de DJango"

    if request.method == "POST":
        formulario = FormArticle(request.POST)

        if formulario.is_valid():
            datos_form = formulario.cleaned_data

            title = datos_form.get('title')
            content = datos_form['content']
            public = datos_form['public']

            articulo = Article(title=title, content=content, public=public)

            articulo.save()

            # Mensajes FLASH - solo duran una sesion/refresco de pagina
            messages.success(
                request, f'Has creado correctamente el articulo {articulo.id}')

            return redirect('listar_articulos')
            #return HttpResponse(articulo.title + " " + articulo.content + " " + str(articulo.public))

    else:
        formulario = FormArticle()

    return render(request, 'miapp/full_create_article.html', {
        'form': formulario,
        'title': title,
    })
Exemplo n.º 6
0
def create_full_article(request):

    formulario = FormArticle()

    return render(request, 'create_full_article.html', {
        'form': formulario
    })
Exemplo n.º 7
0
def create_full_article(request):

    try:

        if request.method == 'POST':
            full_form = FormArticle(request.POST)
        
            if full_form.is_valid() :
                data_form = full_form.cleaned_data

                title = data_form.get('title')
                content = data_form['content']
                public = data_form.get('public')
                


                articulo = Article(
                    title=title,
                    content=content,
                    public=public
                    
                )

                articulo.save()

                #  crear mensaje flash que solo se muestra una vez.
                messages.success(request, f'Articulo {articulo.id} - {articulo.title } creado exitosamente')

                return redirect('listar_articulos')
                # return HttpResponse(title + ' - ' + content + ' - ' + str(public))

        else:
            full_form = FormArticle()


        return render(request, 'create_full_article.html', {
            'formulario' : full_form 
        }) 
        

    except:
        response = 'Error  '
    return HttpResponse(response)
Exemplo n.º 8
0
def create_full_article(request):

    if request.method == "POST":
        formulario = FormArticle(request.POST)

        if formulario.is_valid():
            data_form = formulario.cleaned_data
            title = data_form.get('title')
            content = data_form['content']
            public = data_form['public']
            grabarArticulo(request, title, content, public)

            return redirect('articulos')
            #return HttpResponse("{} - {} - {} ".format(title,content,str(public)) )
    else:
        formulario = FormArticle()

    return render(request, 'create_full_article.html',
                  {'formulario': formulario})
Exemplo n.º 9
0
def create_article_full(request):

    if request.method == 'POST':
        formulario = FormArticle(request.POST)

        if formulario.is_valid():
            data_form = formulario.cleaned_data
            title = data_form.get('title')
            content = data_form['content']
            public = data_form['public']

            articulo = Article(title=title, content=content, public=public)

            articulo.save()
            return HttpResponse("HOLA SOY RUBEN " + title + ' ' + content +
                                '  ' + str(public))
    else:
        formulario = FormArticle()

    return render(request, 'create_full_article.html', {'form': formulario})
Exemplo n.º 10
0
def create_full_article(request):
    """
    formularios como le gustan a django
    1.- importar el formulario
    2.- extender de la clase ejemplo FormArticle()
    """
    # comprobar datos por post
    # si llega generameos una peticion
    # pero si no llega se manda un form vacio
    if request.method == 'POST':
        # se mandaran los datos al form
        # automaticamnte se mandan los datos limpiando
        formulario = FormArticle(request.POST)
        # validar formulario
        if formulario.is_valid():
            # recoger datos del formulario limpios
            data_form = formulario.cleaned_data
            # se puede acceder con el .get o solo
            title = data_form.get('title')
            content = data_form.get('content')
            public = data_form.get('public')
            # guardar informacion
            articulo = Article(
                title=title,
                content=content,
                public=public
            )

            articulo.save()
            # return HttpResponse(articulo.title)
            #crear mensaje flash (sesión que solo se muestra una vez)
            #el primer parametro es la reques para crear la session
            #el seguno es el mensaje
            messages.success(request, f'Has creado correctamente el articulo {articulo.title}')

            return redirect('articulos')
    else:
        formulario = FormArticle()
    return render(request, 'create_full.html', {
        'form': formulario
    })