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 export(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) related = self.collect_related_fields(self.model, {}, []) # check for raw id id_list = request.params.getall('id') id_list = [int(e) for e in id_list if e] if id_list: query = query.where(self.pk << id_list) if request.method == 'POST': raw_fields = request.forms.getall('fields') export = Export(query, related, raw_fields) return export.json_response('export-%s.json' % self.get_admin_name()) return render_template(self.templates['export'], model_admin=self, model=query.model_class, query=query, filter_form=filter_form, field_tree=field_tree, active_filters=cleaned, related_fields=related, sql=query.sql(), **self.get_extra_context() )
def hander(self): if request.method == 'GET': id_list = request.params.get('id') id_list = id_list.split(',') id_list = [e for e in id_list if e] else: id_list = request.forms.getall('id') m_pk = self.pk and self.pk or 'pk' m_model = self.model_admin.model if self.pk: m_key = getattr(m_model,self.pk) else: m_key = self.model_admin.pk self.instances = self.only_id and id_list or m_model.select().where( m_key<< id_list) #if not self.instances:abort(404) if request.method == 'POST': form = self.OpForm(request.forms) if form.validate(): res = self.action(form, request) if res: return res else: form = self.OpForm() res = self.init(form, request) if res: return res return render_template(self._get_template(), cur_op = self, model_admin=self.model_admin, form=form, instances=self.instances, **self.model_admin.get_extra_context() )
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 table_desc(self): u''' 数据库表结构视图 ''' return render_template('admin/table_desc.html', model_admins=self.get_model_admins(), **self.template_helper.get_helper_context() )
def index(self): u''' 总控制面板视图 ''' return render_template('admin/index.html', model_admins=self.get_model_admins(), panels=self.get_panels(), **self.template_helper.get_helper_context() )
def hander(self): if request.method == 'POST': form = self.OpForm(request.forms) if form.validate(): res = self.action(form, request) if res: return res else: form = self.OpForm() res = self.init(form, request) if res: return res return render_template(self.template, form=form, cur = self)
def add(self): Form = self.get_add_form() instance = self.model() if request.method == 'POST': form = Form(request.forms) if form.validate(): instance = self.save_model(instance, form, True) flash('New %s saved successfully' % self.get_display_name(), 'success') return self.dispatch_save_redirect(instance) else: form = Form() return render_template(self.templates['add'], model_admin=self, form=form, instance=instance, **self.get_extra_context() )
def hander(self): self.instance = self.model_admin.model() if request.method == 'POST': form = self.OpForm(request.forms) if form.validate(): res = self.action(form, request) if res: return res else: form = self.OpForm() res = self.init(form, request) if res: return res return render_template(self._get_template(), cur_op = self, model_admin=self.model_admin, form=form, instance=self.instance, **self.model_admin.get_extra_context() )
def hander(self): if request.method == 'POST': form = self.OpForm(request.forms) if form.validate(): res = self.action(form, request) if res: return res else: form = self.OpForm() res = self.init(form, request) if res: return res return render_template(self._get_template(), form=form, cur = self, model_grup = self.app_menu, model_name = self.__class__.__name__, model_menu_key = self.admin.get_page_permkey(self), model_admins=self.app_menu and self.admin.get_grup_admins(self.app_menu) or self.admin.get_model_admins(), **self.admin.template_helper.get_model_admins() )
def login(self): error = None Form = self.get_login_form() if request.method == 'POST': form = Form(request.forms) if form.validate(): authenticated_user = self.authenticate( form.username.data, form.password.data, ) if authenticated_user: self.login_user(authenticated_user) return redirect( request.params.get('next') or \ self.default_next_url ) else: flash('Incorrect username or password') else: form = Form() return render_template('auth/login.html', error=error, form=form)
def edit(self, pk): try: instance = self.get_object(pk) except self.model.DoesNotExist: abort(404) Form = self.get_edit_form(instance) if request.method == 'POST': form = Form(request.forms, obj=instance) if form.validate(): self.save_model(instance, form, False) flash('Changes to %s saved successfully' % self.get_display_name(), 'success') return self.dispatch_save_redirect(instance) else: form = Form(obj=instance) return render_template(self.templates['edit'], model_admin=self, instance=instance, form=form, **self.get_extra_context() )
def object_list(template_name, qr, var_name='object_list', **kwargs): pq = PaginatedQuery(qr, kwargs.pop('paginate_by', 20)) kwargs[var_name] = pq.get_list() return render_template(template_name, pagination=pq, page=pq.get_page(), **kwargs)
def index(self): return render_template('admin/index.html', model_admins=self.get_model_admins(), panels=self.get_panels(), **self.template_helper.get_model_admins() )
def render(self): return render_template(self.get_template_name(), panel=self, **self.get_context())