def index(self): query = self.get_query() ordering = request.params.get('ordering') or '' query = self.apply_ordering(query, ordering) # process the filters from the request filter_form, query, cleaned, field_tree = self.process_filters(query) # create a paginated query out of our filtered results pq = PaginatedQuery(query, self.paginate_by) if request.method == 'POST': id_list = ','.join(request.forms.getall('id')) if request.forms['action'] == 'delete': return redirect(url_for(self.get_url_name('delete'), id=id_list)) else: return redirect(url_for(self.get_url_name('export'), id=id_list)) return render_template(self.templates['index'], model_admin=self, query=pq, ordering=ordering, filter_form=filter_form, field_tree=field_tree, active_filters=cleaned, **self.get_extra_context() )
def inner(*args, **kwargs): if self.auth.autogc: with self.auth.db: if self.auth.check: user = self.auth.get_logged_in_user() if not user: login_url = url_for('auth.login', next=get_next()) return redirect(login_url) if not self.check_user_permission(user, perm_key): return abort(403) return func(*args, **kwargs) else: return func(*args, **kwargs) else: if self.auth.check: user = self.auth.get_logged_in_user() if not user: login_url = url_for('auth.login', next=get_next()) return redirect(login_url) if not self.check_user_permission(user, perm_key): return abort(403) return func(*args, **kwargs) else: return func(*args, **kwargs)
def dispatch_save_redirect(self, instance): if 'save' in request.forms: return redirect(url_for(self.get_url_name('index'))) elif 'save_add' in request.forms: return redirect(url_for(self.get_url_name('add'))) else: return redirect( url_for(self.get_url_name('edit'), pk=instance.get_id()) )
def inner(*args, **kwargs): user = self.get_logged_in_user() if not user or not test_fn(user): login_url = url_for('%s.login' % self.blueprint.name, next=get_next()) return redirect(login_url) return fn(*args, **kwargs)
def delete(self): if request.method == 'GET': id_list = request.params.get('id') id_list = id_list.split(',') id_list = [int(e) for e in id_list if e] else: id_list = request.forms.getall('id') query = self.model.select().where(self.pk << id_list) if request.method == 'GET': collected = {} if self.delete_collect_objects: for obj in query: collected[obj.get_id()] = self.collect_objects(obj) elif request.method == 'POST': count = query.count() for obj in query: obj.delete_instance(recursive=self.delete_recursive) flash('Successfully deleted %s %ss' % (count, self.get_display_name()), 'success') return redirect(url_for(self.get_url_name('index'))) return render_template(self.templates['delete'], **dict( model_admin=self, query=query, collected=collected, **self.get_extra_context() ))
def handle_foreign_key(self, model, field, **kwargs): if field.name in (self.model_admin.foreign_key_lookups or ()): data_source = url_for(self.model_admin.get_url_name('ajax_list')) widget = ChosenAjaxSelectWidget(data_source, field.name) form_field = LimitedModelSelectField(model=field.rel_model, widget=widget, **kwargs) else: form_field = ModelSelectField(model=field.rel_model, **kwargs) return field.name, form_field
def inner(*args, **kwargs): user = self.auth.get_logged_in_user() if not user: login_url = url_for('auth.login', next=get_next()) return redirect(login_url) if not self.check_user_permission(user): abort(403) return func(*args, **kwargs)
def get_admin_url(self, obj): model_admin = self.admin.get_admin_for(type(obj)) if model_admin: return url_for(model_admin.get_url_name('edit'), pk=obj.get_id())
def dashboard_url(self): return url_for('%s.index' % (self.admin.blueprint.name))
def redirect(self): u''' 默认的跳转 ''' return redirect(url_for(self.model_admin.get_url_name('index')))