def get_posts(): """ 所有文章信息 :return: json """ return jsonify(ImportData.get_data().get('post_data'))
def form_valid(self, form): f = form.files.get('file') model = Province if self.data_type == 'sheng' else City import_data = ImportData(f, data_type='sheng').data for i in import_data: model.objects.create(**i) return HttpResponse('0k')
def get_category(cate): """ 指定分类信息 """ for c in ImportData.get_data().get('category_data'): if c.get('category') == cate: return jsonify(c) return jsonify({'msg': '没有数据'})
def get_tag(tag): """ 指定标签信息 """ for t in ImportData.get_data().get('tag_data'): if t.get('tag') == tag: return jsonify(t) return jsonify({'msg': '没有数据'})
def get_page(url): """ 指定页面信息 """ for p in ImportData.get_data().get('page_data'): if p.get('url') == url: return jsonify(p) return jsonify({'msg': '没有数据'})
def get_post(id): """ 指定 id 文章信息 """ for p in ImportData.get_data().get('post_data'): if p.get('id') == id: return jsonify(p) return jsonify({'msg': '没有数据'})
def upload_post(): """ 支持用户上传 md 文件并生成 html :return: """ source_folder = app.config['POST_PATH'] if request.method == 'POST': file = request.files['file'] filename = file.filename path = os.path.join(source_folder, filename) file.save(path) # 生成 html gen() # 重置 shelve 数据 ImportData.reload_data() return redirect(url_for('index')) return render_template('upload_post.html', title="上传文章")
def post(self, request): cart = Cart(self.request) file_form = AddExcelForm(self.request.POST, self.request.FILES) clean = self.request.POST.get('clean') if clean: del cart.cart['import_block'] cart.save() return redirect('purchase:import_data') else: if file_form.is_valid(): f = file_form.files.get('file') importer = ImportData(f, data_type='block_list') cart.cart['import_block'] = importer.data cart.save() return redirect('purchase:import_data')
def get_categories(): """ 所有分类信息 """ return jsonify(ImportData.get_data().get('category_data'))
def get_tags(): """ 所有标签信息 """ return jsonify(ImportData.get_data().get('tag_data'))
def get_pages(): """ 所有页面 """ return jsonify(ImportData.get_data().get('page_data'))
def save_import_slab_list(self, f): importer = ImportData(f) self.cart['import_slabs'].extend(importer.data) self.save()