def home(request): params = getattr(request, request.method, '') if not params: import json params = json.loads(request.body) form = BaseForm(params) form.is_valid() cld = form.cleaned_data do_action = cld.get('action') # 功能函数名 # user_id = cld.get('user_id') # 用户名在数据库的id if not do_action: context = {'return_code': -1, 'message': u'系统异常。'} return JsonResponse(context) func = getattr(action, do_action, None) setattr(request, 'action', do_action) return_data = func(request) args = request.POST.keys() values = request.POST.values() log = '' for index, k in enumerate(args): log += k + '=' + values[index] + '&' # if isinstance(return_data, dict): # logger.info(log[0: -1] + ',' + str(return_data['return_code'])) return return_data
def base_add(): form = BaseForm() if form.validate_on_submit(): body_len = len(form.base.data) # Body is too long and needs to be shortened for list view if body_len > 140: base = Base_Post(title=form.title.data, body=form.base.data, description=form.base.data[0:140] + '...', timestamp=datetime.utcnow(), category=form.category.data, discriminator='base_post') else: base = Base_Post(title=form.title.data, body=form.base.data, description=form.base.data, timestamp=datetime.utcnow(), category=form.category.data, discriminator='base_post') db.session.add(base) db.session.commit() flash('You have added a story') # Once created go to story page return redirect(url_for('story', base_id=base.id)) return render_template("storyEdit.html", form=form)
def current_form(): if _is_set(): return thread_local.current_form from forms import BaseForm return BaseForm({})