예제 #1
0
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
예제 #2
0
파일: views.py 프로젝트: cjdp25/waxyay
def registrar_add(request):
    baseform = BaseForm(request.POST)
    if baseform.is_valid():
        baseform.save()
    return render(request,
        'base/base-to-compatriota.html',
        {'base' : baseform.instance,})
예제 #3
0
파일: views.py 프로젝트: cjdp25/waxyay
def registrar(request):
    baseform = BaseForm()
    if request.method == 'POST':
        baseform = BaseForm(request.POST)
        if baseform.is_valid():
            baseform.save()
            return redirect('/base/registrar/')
    return render(request,
        'base/base.html',
        {'baseform' : baseform,'auth':request.user,})
예제 #4
0
 def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
              initial=None, error_class=ErrorList, label_suffix=':', instance=None):
     opts = self._meta
     if instance is None:
         # if we didn't get an instance, instantiate a new one
         self.instance = opts.model()
         object_data = {}
     else:
         self.instance = instance
         object_data = model_to_dict(instance, opts.fields, opts.exclude)
     # if initial was provided, it should override the values from instance
     if initial is not None:
         object_data.update(initial)
     BaseForm.__init__(self, data, files, auto_id, prefix, object_data, error_class, label_suffix)
예제 #5
0
 def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
              initial=None, error_class=ErrorList, label_suffix=':',
              instance=None):
     opts = self._meta
     if instance is None:
         # if we didn't get an instance, instantiate a new one
         self.instance = opts.model()
         object_data = {}
     else:
         self.instance = instance
         object_data = model_to_dict(instance, opts.fields, opts.exclude)
     # if initial was provided, it should override the values from instance
     if initial is not None:
         object_data.update(initial)
     BaseForm.__init__(self, data, files, auto_id, prefix, object_data, error_class, label_suffix)
예제 #6
0
 def _get_actual_form_class(self):
     from forms import BaseForm
     if not isinstance(self.form_class, str):
         return self.form_class
     if self.form_class == 'self':
         return current_form().__class__
     for subclass in BaseForm.__subclasses__():
         if subclass.__name__ == self.form_class:
             return subclass
     raise AttributeError('Form named %s is not defined' % self.form_class)
예제 #7
0
파일: views.py 프로젝트: aasoliz/Tree
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)
예제 #8
0
def current_form():
    if _is_set():
        return thread_local.current_form
    from forms import BaseForm
    return BaseForm({})