def DataDetail(request, ModelName, DataKey): dataModel = GetModel(ModelName) if not hasPerm(request.user, dataModel, "change"): return NoPermissionResponse() if not dataModel: return NoFound404Response(request) if dataModel == User: # 管理员 管理 from mysite.iclock.admin_detail_view import doPostAdmin, doCreateAdmin if request.method == "POST": return doPostAdmin(request, dataModel, DataKey) else: return doCreateAdmin(request, dataModel, DataKey) backupDevice = "" emp = dataModel.objects.in_bulk([DataKey]) if emp == {}: return NoFound404Response(request) #render_to_response("info.html", { # "title": _("Edit %(object_name)s")%{"object_name":dataModel._meta.verbose_name}, # "content": _("Keyword \"%(object_name)s\" data do not exist!")%{'object_name':DataKey}}); emp = emp[emp.keys()[0]] try: dataForm = form_for_instance(emp) except: dataForm = form_for_model(dataModel) if request.method == "POST": return DataChangePost(request, dataModel, dataForm, emp) return DataChangeGet(request, dataModel, dataForm, emp)
def DataDetail(request, ModelName, DataKey): dataModel = GetModel(ModelName) if not hasPerm(request.user, dataModel, "change"): return NoPermissionResponse() if not dataModel: return NoFound404Response(request) if dataModel==User: # 管理员 管理 from mysite.iclock.admin_detail_view import doPostAdmin,doCreateAdmin if request.method=="POST": return doPostAdmin(request, dataModel, DataKey) else: return doCreateAdmin(request, dataModel, DataKey) backupDevice="" emp=dataModel.objects.in_bulk([DataKey]) if emp=={}: return NoFound404Response(request) #render_to_response("info.html", { # "title": _("Edit %(object_name)s")%{"object_name":dataModel._meta.verbose_name}, # "content": _("Keyword \"%(object_name)s\" data do not exist!")%{'object_name':DataKey}}); emp=emp[emp.keys()[0]] try: dataForm=form_for_instance(emp) except: dataForm=form_for_model(dataModel) if request.method=="POST": return DataChangePost(request, dataModel, dataForm, emp) return DataChangeGet(request, dataModel, dataForm, emp)
def DataNewPost(request, dataModel): if dataModel == User: return doPostAdmin(request, dataModel, '_new_') dataForm = form_for_model(dataModel) f = dataForm(request.POST) if f.is_valid(): isAdd = True #检查通过 DelTag 标记“删除”(隐藏)的数据 key = (dataModel._meta.pk.name in f.cleaned_data ) and f.cleaned_data[dataModel._meta.pk.name] or None if key: try: o = dataModel.objects.get(pk=key) deleted = True if fieldVerboseName(dataModel, "DelTag") and o.DelTag: o.save() return HttpResponseRedirect("../") f.errors[dataModel._meta.pk.name] = [_("Duplicated")] return DataDetailResponse(request, dataModel, f) except ObjectDoesNotExist: pass try: obj = f.save() key = obj.pk except Exception, e: #通常是不满足数据库的唯一性约束导致保存失败 f.errors[ NON_FIELD_ERRORS] = u'<ul class="errorlist"><li>%s</li></ul>' % unicode( e.message) return DataDetailResponse(request, dataModel, f) DataPostCheck(request, None, obj) log = adminLog(User=request.user, model=dataModel.__name__, object=u"%s" % obj) log.action = "Create" log.save() popup = request.GET.get("_popup", "") if popup: the_add_object = unicode(obj) return HttpResponse( u'<script type="text/javascript">\nopener.dismissAddAnotherPopup(window, "%s", "%s");\n</script>' % (key, the_add_object)) return HttpResponseRedirect("../")
def DataNewPost(request, dataModel): if dataModel == User: return doPostAdmin(request, dataModel, '_new_') dataForm = form_for_model(dataModel) f = dataForm(request.POST) if f.is_valid(): isAdd = True key = dataModel._meta.pk.name in f.cleaned_data and f.cleaned_data[ dataModel._meta.pk.name] or None if key: try: o = dataModel.objects.get(pk=key) deleted = True if fieldVerboseName(dataModel, 'DelTag') and o.DelTag: o.save() return HttpResponseRedirect('../') f.errors[dataModel._meta.pk.name] = [_('Duplicated')] return DataDetailResponse(request, dataModel, f) except ObjectDoesNotExist: pass try: obj = f.save() key = obj.pk except Exception, e: e = _('Record Duplicated') f.errors[ NON_FIELD_ERRORS] = u'<ul class="errorlist"><li>%s</li></ul>' % e return DataDetailResponse(request, dataModel, f) DataPostCheck(request, None, obj) log = adminLog(User=request.user, model=dataModel.__name__, object=u'%s' % obj) log.action = 'Create' log.save() popup = request.GET.get('_popup', '') if popup: the_add_object = unicode(obj) return HttpResponse( u'<script type="text/javascript">\nopener.dismissAddAnotherPopup(window, "%s", "%s");\n</script>' % (key, the_add_object)) return HttpResponseRedirect('../')
def DataNewPost(request, dataModel): if dataModel==User: return doPostAdmin(request, dataModel, '_new_') dataForm=form_for_model(dataModel) f=dataForm(request.POST) if f.is_valid(): isAdd=True #检查通过 DelTag 标记“删除”(隐藏)的数据 key=(dataModel._meta.pk.name in f.cleaned_data) and f.cleaned_data[dataModel._meta.pk.name] or None if key: try: o=dataModel.objects.get(pk=key) deleted=True if fieldVerboseName(dataModel, "DelTag") and o.DelTag: o.save() return HttpResponseRedirect("../") f.errors[dataModel._meta.pk.name]=[_("Duplicated")] return DataDetailResponse(request, dataModel, f) except ObjectDoesNotExist: pass try: obj=f.save() key=obj.pk except Exception, e: #通常是不满足数据库的唯一性约束导致保存失败 f.errors[NON_FIELD_ERRORS]=u'<ul class="errorlist"><li>%s</li></ul>'%unicode(e.message) return DataDetailResponse(request, dataModel, f) DataPostCheck(request, None, obj) log=adminLog(User=request.user, model=dataModel.__name__, object=u"%s"%obj) log.action="Create" log.save() popup = request.GET.get("_popup", "") if popup: the_add_object = unicode(obj) return HttpResponse(u'<script type="text/javascript">\nopener.dismissAddAnotherPopup(window, "%s", "%s");\n</script>' % (key, the_add_object)) return HttpResponseRedirect("../")
def DataDetail(request, ModelName, DataKey): dataModel = GetModel(ModelName) if not hasPerm(request.user, dataModel, 'change'): return NoPermissionResponse() if not dataModel: return NoFound404Response(request) if dataModel == User: from mysite.iclock.admin_detail_view import doPostAdmin, doCreateAdmin if request.method == 'POST': return doPostAdmin(request, dataModel, DataKey) return doCreateAdmin(request, dataModel, DataKey) backupDevice = '' emp = dataModel.objects.in_bulk([DataKey]) if emp == {}: return NoFound404Response(request) emp = emp[emp.keys()[0]] try: dataForm = form_for_instance(emp) except: dataForm = form_for_model(dataModel) if request.method == 'POST': return DataChangePost(request, dataModel, dataForm, emp) return DataChangeGet(request, dataModel, dataForm, emp)