Exemplo n.º 1
0
def new_blog(request, form=None):
    """
        Handles the creation of a blog post
        - if user not logged in, give alert
        
        Populates : Features
        
        Removes : Showcase, Sponsors
    """
    dajax = Dajax()

    html_content = ""
    dajax.add_css_class("#showcase", "hide")
    dajax.add_css_class("#sponsors", "hide")

    if request.method == "POST":
        form = ThreadForm(deserialize_form(form))
        print form
        if form.is_valid():  # check validity
            form.save()
            show_alert(dajax, "success", "Your post has been saved !")
        else:  # form was not valid, show errors
            dajax.remove_css_class("#form_new_blog_post input", "error")
            for error in form.errors:  # tell which parts had errors
                dajax.add_css_class("#id_%s" % error, "error")
            print [error for error in form.errors]
            show_alert(dajax, "error", "There were some errors : please rectify them")  # show alert
Exemplo n.º 2
0
def newblog(request):
    '''View for creating a new blog'''
    if request.method == 'POST':
        data = ThreadForm(request.POST, request.FILES)
        if data.is_valid():
            data.save()
            return HttpResponse('<script>alert("Your blog has been submitted succesfully")</script><center>alert(Your blog has been submitted succesfully)</center>')
        else:
            return HttpResponse('<center>Enter valid data</center>')
    else:
        form = ThreadForm()
    return render(request, 'newblog.html', {'form': form})