def add(self): def pre_save(data): pass def post_created_form(fcls, model): pass def post_save(obj, data): pass def success_data(obj, data): d = obj.to_dict() return d def get_url(id): return url_for(self.__class__.list) template_data = {'layout':'blog_layout.html'} view = functions.AddView(self.model, ok_url=get_url, pre_save=pre_save, post_save=post_save, post_created_form=post_created_form, template_data=template_data, success_data=True, ) # response.template = 'GenericView/add.html' return view.run(json_result=True)
def add(self): def pre_save(data): pass def post_created_form(fcls, model): fcls.teacher.choices = [('', '')] def post_save(obj, data): pass def success_data(obj, data): d = obj.to_dict() d['teacher'] = unicode(obj.teacher) return d view = functions.AddView( self.model, # pre_save=pre_save, # post_save=post_save, post_created_form=post_created_form, # template_data={}, success_data=success_data, ) response.template = 'GenericView/ajax_add.html' return view.run(json_result=True)
def add(self): from sqlalchemy.sql import func def pre_save(data): issue, = self.model.filter( self.model.c.class_obj == self.class_id).values_one( func.max(self.model.c.issue)) data['issue'] = (issue or 0) + 1 data['class_obj'] = self.class_id def success_data(obj, data): from uliweb.utils.generic import get_field_display d = obj.to_dict() d['content'] = get_field_display(self.model, 'content', obj) return d view = functions.AddView( self.model, pre_save=pre_save, template_data={'title': '添加新的课程动态'}, success_data=success_data, ) response.template = 'GenericView/ajax_add.html' return view.run(json_result=True)
def add(self): from sqlalchemy.sql import func def pre_save(data): issue, = self.model.filter(self.model.c.class_obj==self.class_id).values_one(func.max(self.model.c.issue)) data['issue'] = (issue or 0)+1 data['class_obj'] = self.class_id def post_created_form(fcls, model): fcls.teachers.choices = [('', '')] fcls.map.validators.append(validators.IS_URL) def post_save(obj, data): obj.class_obj.issue_num += 1 obj.class_obj.save() def success_data(obj, data): from uliweb.utils.generic import get_field_display d = obj.to_dict() d['teachers'] = get_field_display(self.model, 'teachers', obj) d['position'] = self._position(d['position'], obj) d['type'] = get_field_display(self.model, 'type', obj) return d view = functions.AddView(self.model, pre_save=pre_save, post_save=post_save, post_created_form=post_created_form, template_data={'class_id':self.class_id}, success_data=success_data, ) return view.run(json_result=True)
def add(self): """ 添加新分类 """ def get_url(**kwargs): return url_for(TutorialcateView.read, **kwargs) view = functions.AddView(self.model, ok_url=get_url) return view.run()
def _add(self, model, json_result=False, **kwargs): self._process_fields_convert_map(kwargs) view = functions.AddView(model, **kwargs) return view.run(json_result=json_result)
def upload(): File = get_model('file') view = functions.AddView(File, ok_url='/list', upload_to='aaa', upload_to_sub='bbb', fileserving_config='UPLOAD_TEST') return view.run()