Exemplo n.º 1
0
def delete_term(request, class_name, id):
    Class = models.get_model('tm', class_name)
    obj = Class.objects.get(id=id)
    obj.delete()
    return http.HttpResponseRedirect(
            h.reverse(manage, args=[class_name])
    )
Exemplo n.º 2
0
def new_term(request, class_name):
    Class = models.get_model('tm', class_name)
    if request.method == 'GET':
        new_term_form = forms.form_for_model(Class)()
    else:
        new_term_form = forms.form_for_model(Class)(request.POST)
        if new_term_form.is_valid():
            try:
                new_term_form.save()
                return http.HttpResponseRedirect(
                        h.reverse(manage, args=[class_name])
                )
            except Exception, e:
                logging.debug(unicode(e))
                request.add_message(unicode(e))
Exemplo n.º 3
0
def edit_term(request, class_name, id):
    Class = models.get_model('tm', class_name)
    obj = Class.objects.get(id=id)
    if request.method == 'GET':
        edit_term_form = forms.form_for_instance(obj)()
    else:
        edit_term_form = forms.form_for_instance(obj)(request.POST)
        if edit_term_form.is_valid():
            try:
                edit_term_form.save()
                return http.HttpResponseRedirect(
                        h.reverse(manage, args=[class_name])
                )
            except Exception, e:
                logging.debug(unicode(e))
                request.add_message(unicode(e))
Exemplo n.º 4
0
def imp(request):
    f = request.FILES.get('file')
    reader = csv.reader(StringIO(f['content']))
    schema = reader.next()
    fields = [f.name for f in dw.MRFP._meta.fields]
    keys = [key for key in schema if key not in fields]
    if keys:
        logging.debug("不存在的表头字段", keys)
    for row in reader:
        d = dict(zip(schema, row))
        null_value_keys = [key for key in d if not d[key]]
        if null_value_keys:
            logging.debug("空值的字段", null_value_keys)
        for k in keys: del d[k]
        for k in null_value_keys: del d[k]
        for key in d:
            d[key] = dw.MRFP._meta.get_field(key).to_python(d[key])
        dw.MRFP.objects.create(**d)
    return http.HttpResponseRedirect(
            h.reverse(index)
    )