Exemple #1
0
def addclass(req):
    """
    :param req: we use the same templates with the secfieldadd function.
    :return:
    """
    head = u"添加媒资分类"
    classinfo = Tseclass()
    print "addclass"
    if req.method == "POST":
        parentname = req.POST["csparent"].encode("utf-8")
        classname = req.POST["secclassname"].encode("utf-8")
        print parentname, classname
        af = ClassForm(req.POST)
        """if af.is_valid():
            parentname = req.POST['csparent'].encode('utf-8')
            classname = req.POST['secclassname'].encode('utf-8')
            print parentname,classname
            classinfo.parent_secl_id = int(parentname)
            classinfo.seclass_name = classname
            classinfo.gen_time = datetime.datetime.now()
            try:
                classinfo.save()
            except Exception as e:
                return HttpResponse(e)
            return HttpResponseRedirect('/class')"""
        classinfo.parent_secl_id = int(parentname)
        classinfo.seclass_name = classname
        classinfo.gen_time = datetime.datetime.now()
        try:
            classinfo.save()
        except Exception as e:
            return HttpResponse(e)
        return HttpResponseRedirect("/class")
    else:
        af = ClassForm()
    classesname = []
    classid = []
    AllClassids = []
    AllClassNames = []
    classesname.append("主分类")
    classid.append(0)
    classes = Tseclass.objects.filter(parent_secl_id=0)  # the names of null
    for clas in classes:  # [音乐 相声]
        clsid = Tseclass.objects.get(seclass_name=clas).seclass_id  # [1,7]
        classid.append(clsid)  # the secfield_ids which the parent_secfd_id is null
        classesname.append(clas)  # the secfield_names which the parent_secf_id is null
        secondname = Tseclass.objects.filter(parent_secl_id=clsid)  # [1:2 5]
        for second in secondname:
            secfidid = Tseclass.objects.get(seclass_name=second).seclass_id
            classid.append(secfidid)
            classesname.append(second)
    classinfo = zip(classid, classesname)
    vin = tuple(classinfo)
    # print "vin",vin
    return render_to_response("field_classadd2.html", {"af": af, "uu3": vin, "head": head})
Exemple #2
0
def addclass(req):
    '''
    :param req: we use the same templates with the secfieldadd function.
    :return:
    '''
    head = u'添加媒资分类'
    classinfo = Tseclass()
    if req.method == 'POST':
        af = ClassForm(req.POST)
        if af.is_valid():
            parentname = req.POST['csparent'].encode('utf-8')
            classname = req.POST['secclassname'].encode('utf-8')
            print parentname,classname
            classinfo.parent_secl_id = int(parentname)
            classinfo.seclass_name = classname
            classinfo.gen_time = datetime.datetime.now()
            try:
                classinfo.save()
            except Exception as e:
                return HttpResponse(e)
            return HttpResponseRedirect('/class')
    else:
        af = ClassForm()
    return render_to_response('field_classadd.html', {'af':af,'head':head})