当前位置: 首页>>代码示例>>Python>>正文


Python models.Form类代码示例

本文整理汇总了Python中models.Form的典型用法代码示例。如果您正苦于以下问题:Python Form类的具体用法?Python Form怎么用?Python Form使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Form类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

    def post(self):
        try:
            jsondata = json.loads(self.request.body)
        except UnicodeDecodeError:
            jsondata = json.loads(self.request.body,encoding='latin-1')

        logging.info(jsondata.keys())

        form = Form()
        
        procfields = []
        for i,f in enumerate(jsondata['fields']):
            procfields.append({
                'name': 'field{}'.format(i),
                'Descr': f['Descr'],
                'Val': f['Val']
                })
        
        form.creator = jsondata['creator']
        form.until = datetime.datetime.now() + datetime.timedelta(hours=jsondata['duration'])
        form.hashtag = jsondata['hashtag']
        form.fields = procfields
        form.description = jsondata['description']
        form.authenticated = not bool(jsondata['authenticated']) 
        form.info = jsondata['info']

        form.put()
开发者ID:guillemborrell,项目名称:btdotnet,代码行数:27,代码来源:rest.py

示例2: post

	def post(self):
		form = Form()
		self._update_form_from_request(form)
		
		form.put()
		
		logging.info("Created form '%s'" % form.key.urlsafe())
		
		self.redirect(self.uri_for('forms-list'))
开发者ID:vanderkleij,项目名称:MailFacade,代码行数:9,代码来源:admin.py

示例3: form_toggle

def form_toggle(hashid):
    form = Form.get_with_hashid(hashid)

    # check that this request came from user dashboard to prevent XSS and CSRF
    referrer = referrer_to_baseurl(request.referrer)
    service = referrer_to_baseurl(settings.SERVICE_URL)
    if referrer != service:
        return render_template('error.html',
                               title='Improper Request',
                               text='The request you made is not valid.<br />Please visit your dashboard and try again.'), 400

    if form.owner_id != current_user.id:
        if form not in current_user.forms: #accounts for bug when form isn't assigned owner_id bc it was not created from dashboard
            return render_template('error.html',
                                  title='Wrong user',
                                  text='You aren\'t the owner of that form.<br />Please log in as the form owner and try again.'), 400
    if not form:
            return render_template('error.html',
                                   title='Not a valid form',
                                   text='That form does not exist.<br />Please check the link and try again.'), 400
    else:
        form.disabled = not form.disabled
        DB.session.add(form)
        DB.session.commit()
        if form.disabled:
            flash('Form successfully disabled', 'success')
        else:
            flash('Form successfully enabled', 'success')
        return redirect(url_for('dashboard'))
开发者ID:webscienceco,项目名称:formspree,代码行数:29,代码来源:views.py

示例4: submission_deletion

def submission_deletion(hashid, submissionid):
    submission = Submission.query.get(submissionid)
    form = Form.get_with_hashid(hashid)

    # check that this request came from user dashboard to prevent XSS and CSRF
    referrer = referrer_to_baseurl(request.referrer)
    service = referrer_to_baseurl(settings.SERVICE_URL)
    if referrer != service:
        return render_template('error.html',
                               title='Improper Request',
                               text='The request you made is not valid.<br />Please visit your dashboard and try again.'), 400

    if form.owner_id != current_user.id:
        if form not in current_user.forms: #accounts for bug when form isn't assigned owner_id bc it was not created from dashboard
            return render_template('error.html',
                                  title='Wrong user',
                                  text='You aren\'t the owner of that form.<br />Please log in as the form owner and try again.' + str(form.id)), 400
    if not submission:
        return render_template('error.html',
                              title='Not a valid submission',
                              text='That submission does not exist.<br />Please check the link and try again.'), 400
    elif submission.form_id != form.id:
        return render_template('error.html',
                              title='Not a valid submissions',
                              text='That submission does not match the form provided.<br />Please check the link and try again.'), 400
    else:
        DB.session.delete(submission)
        form.counter -= 1
        DB.session.add(form)
        DB.session.commit()
        flash('Submission successfully deleted', 'success')
        return redirect(url_for('form-submissions', hashid=hashid))
开发者ID:webscienceco,项目名称:formspree,代码行数:32,代码来源:views.py

示例5: form_submissions

def form_submissions(random_like_string):
    if not current_user.upgraded:
        return jsonerror(402, {'error': "Please upgrade your account."})

    form = Form.get_form_by_random_like_string(random_like_string)
    submissions = form.submissions

    if request_wants_json():
        if current_user.id != form.owner_id:
            return jsonerror(403, {'error': "You're not the owner of this form."})

        return jsonify({
            'submissions': [s.data for s in submissions]
        })
    else:
        if current_user.id != form.owner_id:
            return redirect(url_for('dashboard'))

        fields = set()
        for s in submissions:
            fields.update(s.data.keys())
        fields -= set(EXCLUDE_KEYS)

        return render_template('forms/submissions.html',
            form=form,
            fields=sorted(fields),
            submissions=submissions
        )
开发者ID:jean,项目名称:formspree,代码行数:28,代码来源:views.py

示例6: form_submissions

def form_submissions(hashid):
    if not current_user.upgraded:
        return jsonerror(402, {'error': "Please upgrade your account."})

    form = Form.get_with_hashid(hashid)

    if not form.controlled_by(current_user):
        if request_wants_json():
            return jsonerror(403, {'error': "You do not control this form."})
        else:
            return redirect(url_for('dashboard'))

    submissions = form.submissions

    if request_wants_json():
        return jsonify({
            'submissions': [s.data for s in submissions]
        })
    else:
        fields = set()
        for s in submissions:
            fields.update(s.data.keys())
        fields -= set(EXCLUDE_KEYS)

        return render_template('forms/submissions.html',
            form=form,
            fields=sorted(fields),
            submissions=submissions
        )
开发者ID:davidhegarty,项目名称:formspree,代码行数:29,代码来源:views.py

示例7: get

	def get(self):
		forms = Form.query().fetch(keys_only=True)		
		
		template_values = {
			'form_keys': map(lambda form: form.urlsafe(), forms)
		}
		
		html_template_path = os.path.join(templates_directory, 'admin_forms_list.html')
		html = template.render(html_template_path, template_values)
		
		self.response.write(html)
开发者ID:vanderkleij,项目名称:MailFacade,代码行数:11,代码来源:admin.py

示例8: form

def form(request, success_url='sent', template_name='contact_form.html'):

    notify = True
    contact_form = ContactForm()
    if request.method == 'POST':
        contact_form = ContactForm(request.POST, request.FILES)
        if contact_form.is_valid():
            new_form = {
                    'firstname': contact_form.cleaned_data['firstname'],
                    'lastname': contact_form.cleaned_data['lastname'],
                    'email': contact_form.cleaned_data['email'],
                    'pc': contact_form.cleaned_data['pc'],
                    'tipo': contact_form.cleaned_data['tipo'],
                    'caso': contact_form.cleaned_data['caso'],
                    }
            new_form = Form(**new_form)
            new_form.save(notify=notify)
            return HttpResponseRedirect(success_url)

    return render_to_response(template_name, RequestContext(request, {'form': contact_form}))
开发者ID:exezaid,项目名称:Hacklab,代码行数:20,代码来源:views.py

示例9: create

def create():
    form = ContactForm()
    if form.validate() is False:
        for error_type in form.errors:
            if form.errors[error_type][0] in dictionary():
                form.errors[error_type][0] = dictionary()[form.errors[error_type][0]]
        return render_template('contact/index.html', form=form, action=url_for('contact.create'))
    else:
        contact = Form()
        contact.name = form.name.data
        contact.email = form.email.data
        contact.subject = form.subject.data
        contact.message = form.message.data
        contact.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

        message_tpl = render_template('contact/message_template.html', contact=contact)

        db.session.add(contact)
        db.session.commit()
        send_mail("Contato - DataViva", [admin_email], message_tpl)

        message = gettext("Your message has been sent successfully. We will soon get back to you.")
        flash(message, 'success')

        return redirect(url_for('contact.create'))
开发者ID:DataViva,项目名称:dataviva-site,代码行数:25,代码来源:views.py

示例10: forms

def forms():
    if request.method == 'GET':
        if request_wants_json():
            return jsonerror(501, {'error': "This endpoint may return the list of forms for the logged user."})
        else:
            return redirect(url_for('dashboard'))

    # Create a new form
    if not current_user.upgraded:
        return jsonerror(402, {'error': "Please upgrade your account."})

    if request.get_json():
        email = request.get_json().get('email')
    else:
        email = request.form.get('email')

    if not IS_VALID_EMAIL(email):
        if request_wants_json():
            return jsonerror(400, {'error': "The email you sent is not a valid email."})
        else:
            flash('The email you sent is not a valid email.', 'error')
            return redirect(url_for('dashboard'))

    form = Form(email, owner=current_user)
    DB.session.add(form)
    DB.session.commit()

    # A unique identifier for the form that maps to its id,
    # but doesn't seem like a sequential integer
    random_like_string = form.get_random_like_string()

    if request_wants_json():
        return jsonify({
            'ok': True,
            'random_like_string': random_like_string,
            'submission_url': settings.API_ROOT + '/' + random_like_string
        })
    else:
        return redirect(url_for('dashboard'))
开发者ID:jean,项目名称:formspree,代码行数:39,代码来源:views.py

示例11: handle

    def handle(self, sms):
        """Método chamado pelo RapidSMS para processar uma mensagem"""
        sub_type = Submission.TYPE_SMS  # estamos organizando as outras branchs do projeto
        answer = Config.get("message_unknown_format")

        if Submission.has_confirmation_pending(sms.connection.identity):
            submission = Submission.get_unconfirmed(sms.connection.identity)
            answer = submission.confirm(sms.text)
            return self.send_answer(sms, answer)

        if Form.main_form_exists():
            form = Form.get_main_form()

        else:
            keyword, separator, remaining_message = Form.extract_keyword(sms.text)
            sms.text = remaining_message
            form = Form.get_by_keyword_and_separator(keyword, separator)

        if form:
            answer = form.process_submission(sms, sub_type) or answer

        return self.send_answer(sms, answer)
开发者ID:institutotim,项目名称:resposta-rapida,代码行数:22,代码来源:app.py

示例12: get

 def get(self):
     formlist = []
     forms = Form.last()
     
     if forms:
         for form in forms:
             formlist.append(form.to_dict_key())
             
         self.response.headers['Content-Type'] = 'application/json'
         self.response.out.write(json.dumps(formlist))
         
     else:
         self.abort(404)
开发者ID:guillemborrell,项目名称:btdotnet,代码行数:13,代码来源:rest.py

示例13: confirm_email

def confirm_email(nonce):
    '''
    Confirmation emails point to this endpoint
    It either rejects the confirmation or
    flags associated email+host to be confirmed
    '''

    # get the form for this request
    form = Form.confirm(nonce)

    if not form:
        return render_template('error.html',
                               title='Not a valid link',
                               text='Confirmation token not found.<br />Please check the link and try again.'), 400

    else:
        return render_template('forms/email_confirmed.html', email=form.email, host=form.host)
开发者ID:mgraupner,项目名称:formspree,代码行数:17,代码来源:views.py

示例14: form_recaptcha_toggle

def form_recaptcha_toggle(hashid):
    form = Form.get_with_hashid(hashid)

    if not valid_domain_request(request):
        return jsonify(error='The request you made is not valid.<br />Please visit your dashboard and try again.'), 400

    if form.owner_id != current_user.id and form not in current_user.forms:
        return jsonify(error='You aren\'t the owner of that form.<br />Please log in as the form owner and try again.'), 400

    if not form:
        return jsonify(error='That form does not exist. Please check the link and try again.'), 400
    else:
        form.captcha_disabled = not form.captcha_disabled
        DB.session.add(form)
        DB.session.commit()

        if form.captcha_disabled:
            return jsonify(disabled=True, message='CAPTCHA successfully disabled')
        else:
            return jsonify(disabled=False, message='CAPTCHA successfully enabled')
开发者ID:davidcretu,项目名称:formspree,代码行数:20,代码来源:views.py

示例15: admin

def admin(request):
    user = users.get_current_user()
    if not (user and users.is_current_user_admin()):
        return HttpResponseRedirect(users.create_login_url('/admin'))

    if request.method == 'POST' and request.POST['id'] and request.POST['action']:
        id = request.POST['id']
        action = int(request.POST['action'])
        model = Form.get(id)

        model.status = action
        model.put()

    pending = []
    accepted = []
    rejected = []
    
    for x in db.GqlQuery("SELECT * FROM poznanopen_form"):
        { 1:pending, 2: accepted, 3: rejected }[x.status].append(x)

    return render_to_response('admin.html', {'page': 'admin', 'pending': pending, 'accepted': accepted, 'rejected': rejected})
开发者ID:MHordecki,项目名称:poznanopen,代码行数:21,代码来源:views.py


注:本文中的models.Form类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。