Example #1
0
def saveartical(request):
    errors = []
    artical_classes = Artical_class.objects.all()
    try:
        artical = Artical()
        artical.author = request.POST['author']
        if not artical.author:
            errors.append("no author")
        artical.title = request.POST['title']
        if not artical.title:
            errors.append("no title")
        content_html = markdown.markdown(request.POST['content'])
        artical.content = content_html
        if not artical.content:
            errors.append("no content")
        artical.artical_class_id = request.POST['category']
        if not artical.artical_class_id:
            errors.append("no artical_class")
        if errors:
            return errors
        artical.time = datetime.datetime.now()
        artical.save()
    except Exception:
        return render_to_response('backstage/upload/artical.html',
                                  {"artical_classes": artical_classes, "errors": errors},
                                  context_instance=RequestContext(request))
    return HttpResponseRedirect('/upload/artical')
Example #2
0
def saveartical(request):
    errors = []
    artical = Artical()
    artical.author = request.POST['author']
    if not artical.author:
        errors.append("no author")
    artical.title = request.POST['title']
    if not artical.title:
        errors.append("no title")
    content_html = markdown.markdown(request.POST['content'])
    artical.content = content_html
    if not artical.content:
        errors.append("no content")
    artical.artical_class_id = request.POST['category']
    if not artical.artical_class_id:
        errors.append("no artical_class")
    if errors:
        return errors
    artical.time = datetime.datetime.now()
    artical.save()